diff --git a/0.FirstExample/TodoBusinessTestFinal.java b/0.FirstExample/TodoBusinessTestFinal.java new file mode 100644 index 0000000..730cecd --- /dev/null +++ b/0.FirstExample/TodoBusinessTestFinal.java @@ -0,0 +1,76 @@ +package com.in28minutes.spring.example1; + +import static org.junit.Assert.assertEquals; + +import java.sql.Connection; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@Configuration +@ComponentScan(basePackages = { "com.in28minutes" }) +class SpringContext { +} + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = SpringContext.class) +public class TodoBusinessTestFinal { + + @Autowired + TodoBusinessServiceImpl todoBusinessServiceImpl; + + @Test + public void testGetTodosAboutSpring(){ + + List todosAboutSpring = todoBusinessServiceImpl.getTodosAboutSpring(); + assertEquals(1,todosAboutSpring.size()); + } +} + +@Component +class TodoBusinessServiceImpl { + + @Autowired + TodoDataService todoDataServiceImpl; + + List getTodosAboutSpring(){ + List todos = todoDataServiceImpl.getTodos(); + List todosAboutSpring = new ArrayList(); + for(String todo:todos){ + if(todo.contains("Spring")) + todosAboutSpring.add(todo); + } + return todosAboutSpring; + } +} + +interface TodoDataService { + List getTodos(); +} + +@Component +class TodoDataServiceStubImpl implements TodoDataService{ + Connection jdbcConnection; + public List getTodos() { + //make a call; + return new ArrayList(); + } +} + +@Component +class TodoDataServiceRealImpl implements TodoDataService { + Connection jdbcConnection; + public List getTodos() { + return Arrays.asList("Learn Spring","Learn Struts"); + } +} + diff --git a/0.FirstExample/pom.xml b/0.FirstExample/pom.xml index 0f6407c..36caa46 100755 --- a/0.FirstExample/pom.xml +++ b/0.FirstExample/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 jar - com.in28minutes.example.layering + com.in28minutes.example.first spring-basic-example 0.0.1-SNAPSHOT ${project.artifactId} @@ -11,117 +11,53 @@ 4.1.6.RELEASE - 4.1.6.RELEASE - - - - scm:svn:URL TO SVN REPOSITORY - - - scm:svn:URL TO SVN REPOSITORY - - URL TO SVN REPOSITORY - - - - - - - org.springframework - spring-beans - ${spring-core-version} - - - org.springframework - spring-context - ${spring-core-version} - - - org.springframework - spring-context-support - ${spring-core-version} - - - - org.springframework - spring-core - ${spring-core-version} - - - - org.springframework - spring-aop - ${spring-aop-version} - - - org.springframework - spring-aspects - ${spring-aop-version} - - - - org.springframework - spring-tx - ${spring-core-version} - - - - log4j - log4j - 1.2.16 - - - - - junit - junit - 4.10 - test - - - org.springframework - spring-test - ${spring-core-version} - test - - - org.mockito - mockito-core - 1.9.0-rc1 - test - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.2 - - true - 1.8 - 1.8 - true - - - - - - - - releases - Corporate Releases - Repository Name for releasing - - - snapshot - Corporate Snapshots - Repository Name for releasing - - + + + + org.springframework + spring-core + ${spring-core-version} + + + + org.springframework + spring-context + ${spring-core-version} + + + + org.springframework + spring-beans + ${spring-core-version} + + + + org.springframework + spring-context-support + ${spring-core-version} + + + + + log4j + log4j + 1.2.16 + + + + + junit + junit + 4.10 + test + + + org.springframework + spring-test + ${spring-core-version} + test + +