forked from roghughe/captaindebug
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Roger Hughes
committed
Jun 7, 2014
1 parent
b04c5a8
commit 936821a
Showing
12 changed files
with
243 additions
and
13 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
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
8 changes: 8 additions & 0 deletions
8
cargo-cult/src/main/java/com/captaindebug/cargocult/brief/SimpleUserController.java
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,8 @@ | ||
package com.captaindebug.cargocult.brief; | ||
|
||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
public class SimpleUserController { | ||
|
||
} |
5 changes: 0 additions & 5 deletions
5
cargo-cult/src/main/java/com/captaindebug/cargocult/brief/UserController.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...bug/cargocult/user/FindUserRowMapper.java → ...ug/cargocult/ntier/FindUserRowMapper.java
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
2 changes: 1 addition & 1 deletion
2
...ndebug/cargocult/user/UserController.java → ...debug/cargocult/ntier/UserController.java
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
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
2 changes: 1 addition & 1 deletion
2
...taindebug/cargocult/user/UserService.java → ...aindebug/cargocult/ntier/UserService.java
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
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
73 changes: 73 additions & 0 deletions
73
cargo-cult/src/test/java/com/captaindebug/cargocult/ntier/UserControllerTest.java
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,73 @@ | ||
package com.captaindebug.cargocult.ntier; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Date; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
import org.springframework.ui.Model; | ||
|
||
import com.captaindebug.cargocult.User; | ||
|
||
public class UserControllerTest { | ||
|
||
private static final String NAME = "Woody Allen"; | ||
|
||
private UserController instance; | ||
|
||
@Mock | ||
private Model model; | ||
|
||
@Mock | ||
private UserService userService; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
|
||
MockitoAnnotations.initMocks(this); | ||
|
||
instance = new UserController(); | ||
ReflectionTestUtils.setField(instance, "userService", userService); | ||
} | ||
|
||
@Test | ||
public void testFindUser_valid_user() { | ||
|
||
User expected = new User(0L, NAME, "[email protected]", new Date()); | ||
when(userService.findUser(NAME)).thenReturn(expected); | ||
|
||
String result = instance.findUser(NAME, model); | ||
assertEquals("user", result); | ||
|
||
verify(model).addAttribute("user", expected); | ||
} | ||
|
||
@Test | ||
public void testFindUser_null_user() { | ||
|
||
when(userService.findUser(null)).thenReturn(User.NULL_USER); | ||
|
||
String result = instance.findUser(null, model); | ||
assertEquals("user", result); | ||
|
||
verify(model).addAttribute("user", User.NULL_USER); | ||
} | ||
|
||
@Test | ||
public void testFindUser_empty_user() { | ||
|
||
when(userService.findUser("")).thenReturn(User.NULL_USER); | ||
|
||
String result = instance.findUser("", model); | ||
assertEquals("user", result); | ||
|
||
verify(model).addAttribute("user", User.NULL_USER); | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
cargo-cult/src/test/java/com/captaindebug/cargocult/ntier/UserDaoTest.java
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,71 @@ | ||
package com.captaindebug.cargocult.ntier; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Matchers.anyObject; | ||
import static org.mockito.Matchers.anyString; | ||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Matchers.isNull; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Date; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.RowMapper; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import com.captaindebug.cargocult.User; | ||
|
||
public class UserDaoTest { | ||
|
||
private static final String NAME = "Woody Allen"; | ||
|
||
private UserDao instance; | ||
|
||
@Mock | ||
private JdbcTemplate jdbcTemplate; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
|
||
MockitoAnnotations.initMocks(this); | ||
|
||
instance = new UserDao(); | ||
ReflectionTestUtils.setField(instance, "jdbcTemplate", jdbcTemplate); | ||
} | ||
|
||
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
@Test | ||
public void testFindUser_valid_user() { | ||
|
||
User expected = new User(0L, NAME, "[email protected]", new Date()); | ||
when(jdbcTemplate.queryForObject(anyString(), (RowMapper) anyObject(), eq(NAME))).thenReturn(expected); | ||
|
||
User result = instance.findUser(NAME); | ||
assertEquals(expected, result); | ||
} | ||
|
||
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
@Test | ||
public void testFindUser_null_user() { | ||
|
||
when(jdbcTemplate.queryForObject(anyString(), (RowMapper) anyObject(), isNull())).thenReturn(User.NULL_USER); | ||
|
||
User result = instance.findUser(null); | ||
assertEquals(User.NULL_USER, result); | ||
} | ||
|
||
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
@Test | ||
public void testFindUser_empty_user() { | ||
|
||
when(jdbcTemplate.queryForObject(anyString(), (RowMapper) anyObject(), eq(""))).thenReturn(User.NULL_USER); | ||
|
||
User result = instance.findUser(""); | ||
assertEquals(User.NULL_USER, result); | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
cargo-cult/src/test/java/com/captaindebug/cargocult/ntier/UserServiceTest.java
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,62 @@ | ||
package com.captaindebug.cargocult.ntier; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Date; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import com.captaindebug.cargocult.User; | ||
|
||
public class UserServiceTest { | ||
|
||
private static final String NAME = "Annie Hall"; | ||
|
||
private UserService instance; | ||
|
||
@Mock | ||
private UserDao userDao; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
|
||
MockitoAnnotations.initMocks(this); | ||
|
||
instance = new UserService(); | ||
|
||
ReflectionTestUtils.setField(instance, "userDao", userDao); | ||
} | ||
|
||
@Test | ||
public void testFindUser_valid_user() { | ||
|
||
User expected = new User(0L, NAME, "[email protected]", new Date()); | ||
when(userDao.findUser(NAME)).thenReturn(expected); | ||
|
||
User result = instance.findUser(NAME); | ||
assertEquals(expected, result); | ||
} | ||
|
||
@Test | ||
public void testFindUser_null_user() { | ||
|
||
when(userDao.findUser(null)).thenReturn(User.NULL_USER); | ||
|
||
User result = instance.findUser(null); | ||
assertEquals(User.NULL_USER, result); | ||
} | ||
|
||
@Test | ||
public void testFindUser_empty_user() { | ||
|
||
when(userDao.findUser("")).thenReturn(User.NULL_USER); | ||
|
||
User result = instance.findUser(""); | ||
assertEquals(User.NULL_USER, result); | ||
} | ||
} |