-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ranga Rao Karanam
authored and
Ranga Rao Karanam
committed
Nov 21, 2015
1 parent
caac587
commit a9c079d
Showing
2 changed files
with
124 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> todosAboutSpring = todoBusinessServiceImpl.getTodosAboutSpring(); | ||
assertEquals(1,todosAboutSpring.size()); | ||
} | ||
} | ||
|
||
@Component | ||
class TodoBusinessServiceImpl { | ||
|
||
@Autowired | ||
TodoDataService todoDataServiceImpl; | ||
|
||
List<String> getTodosAboutSpring(){ | ||
List<String> todos = todoDataServiceImpl.getTodos(); | ||
List<String> todosAboutSpring = new ArrayList<String>(); | ||
for(String todo:todos){ | ||
if(todo.contains("Spring")) | ||
todosAboutSpring.add(todo); | ||
} | ||
return todosAboutSpring; | ||
} | ||
} | ||
|
||
interface TodoDataService { | ||
List<String> getTodos(); | ||
} | ||
|
||
@Component | ||
class TodoDataServiceStubImpl implements TodoDataService{ | ||
Connection jdbcConnection; | ||
public List<String> getTodos() { | ||
//make a call; | ||
return new ArrayList<String>(); | ||
} | ||
} | ||
|
||
@Component | ||
class TodoDataServiceRealImpl implements TodoDataService { | ||
Connection jdbcConnection; | ||
public List<String> getTodos() { | ||
return Arrays.asList("Learn Spring","Learn Struts"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters