Commit e49ac6a1f92d683ea84c2f6c49bdd5c84e07a0c4
1 parent
360c7bde
test: ViewController- und ServiceTest verbessert
Showing
2 changed files
with
106 additions
and
3 deletions
src/test/java/net/ziemers/swxercise/lg/user/service/UserServiceTest.java
... | ... | @@ -73,6 +73,26 @@ public class UserServiceTest extends JpaTestUtils { |
73 | 73 | } |
74 | 74 | |
75 | 75 | @Test |
76 | + public void testLogoutUserSuccess() { | |
77 | + // TODO Test ist noch zu implementieren | |
78 | + } | |
79 | + | |
80 | + @Test | |
81 | + public void testFindUserById() { | |
82 | + // TODO Test ist noch zu implementieren | |
83 | + } | |
84 | + | |
85 | + @Test | |
86 | + public void testFindUser() { | |
87 | + // TODO Test ist noch zu implementieren | |
88 | + } | |
89 | + | |
90 | + @Test | |
91 | + public void testFindAllUsers() { | |
92 | + // TODO Test ist noch zu implementieren | |
93 | + } | |
94 | + | |
95 | + @Test | |
76 | 96 | public void testCreateUserReturnsSuccess() { |
77 | 97 | |
78 | 98 | given() |
... | ... | @@ -111,6 +131,26 @@ public class UserServiceTest extends JpaTestUtils { |
111 | 131 | .assertUpdateSuccess(); |
112 | 132 | } |
113 | 133 | |
134 | + @Test | |
135 | + public void testDeleteUserByIdReturnsSuccess() { | |
136 | + // TODO Test ist noch zu implementieren | |
137 | + } | |
138 | + | |
139 | + @Test | |
140 | + public void testDeleteUserReturnsSuccess() { | |
141 | + // TODO Test ist noch zu implementieren | |
142 | + } | |
143 | + | |
144 | + @Test | |
145 | + public void testIsUserAllowedReturnsSuccess() { | |
146 | + // TODO Test ist noch zu implementieren | |
147 | + } | |
148 | + | |
149 | + @Test | |
150 | + public void testIsUserAllowedReturnsFailure() { | |
151 | + // TODO Test ist noch zu implementieren | |
152 | + } | |
153 | + | |
114 | 154 | // given |
115 | 155 | |
116 | 156 | private UserServiceTest given() { | ... | ... |
src/test/java/net/ziemers/swxercise/ui/UserViewControllerTest.java
1 | 1 | package net.ziemers.swxercise.ui; |
2 | 2 | |
3 | +import java.util.ArrayList; | |
4 | +import java.util.Collection; | |
5 | + | |
6 | +import net.ziemers.swxercise.lg.model.user.User; | |
3 | 7 | import net.ziemers.swxercise.lg.testdatabuilder.user.UserDtoTestDataBuilder; |
4 | 8 | import net.ziemers.swxercise.lg.user.dto.UserDto; |
5 | 9 | import net.ziemers.swxercise.lg.user.service.UserService; |
6 | 10 | import net.ziemers.swxercise.ui.enums.ResponseState; |
11 | + | |
7 | 12 | import org.junit.Test; |
8 | 13 | import org.junit.runner.RunWith; |
9 | 14 | import org.mockito.InjectMocks; |
... | ... | @@ -16,6 +21,9 @@ import static org.mockito.Mockito.*; |
16 | 21 | @RunWith(MockitoJUnitRunner.class) |
17 | 22 | public class UserViewControllerTest { |
18 | 23 | |
24 | + private static String USER_FIRSTNAME = "Hein"; | |
25 | + private static Long EXISTING_USER_ID = 2L; | |
26 | + | |
19 | 27 | /* |
20 | 28 | * You have the @InjectMocks annotation which tries to do constructor, |
21 | 29 | * method and field dependency injection based on the type. |
... | ... | @@ -34,6 +42,10 @@ public class UserViewControllerTest { |
34 | 42 | |
35 | 43 | private RestResponse actual; |
36 | 44 | |
45 | + private Collection<User> actualCollection; | |
46 | + | |
47 | + private User actualUser; | |
48 | + | |
37 | 49 | @Test |
38 | 50 | public void testJUnitFrameworkReturnsTrue() { |
39 | 51 | assertTrue(true); |
... | ... | @@ -46,12 +58,32 @@ public class UserViewControllerTest { |
46 | 58 | |
47 | 59 | @Test |
48 | 60 | public void testGetAllUsersReturnsUsersJson() { |
49 | - // TODO Test ist noch zu implementieren | |
61 | + | |
62 | + doing() | |
63 | + .getAllUsers(); | |
64 | + | |
65 | + then() | |
66 | + .assertGetAllUsersSuccess(); | |
50 | 67 | } |
51 | 68 | |
52 | 69 | @Test |
53 | 70 | public void testGetUserByIdReturnsUserJson() { |
54 | - // TODO Test ist noch zu implementieren | |
71 | + | |
72 | + doing() | |
73 | + .getUserById(EXISTING_USER_ID); | |
74 | + | |
75 | + then() | |
76 | + .assertGetUserByIdSuccess(); | |
77 | + } | |
78 | + | |
79 | + @Test | |
80 | + public void testGetUserReturnsUserJson() { | |
81 | + | |
82 | + doing() | |
83 | + .getUser(); | |
84 | + | |
85 | + then() | |
86 | + .assertGetUserSuccess(); | |
55 | 87 | } |
56 | 88 | |
57 | 89 | @Test |
... | ... | @@ -100,7 +132,7 @@ public class UserViewControllerTest { |
100 | 132 | .userDto(); |
101 | 133 | |
102 | 134 | doing() |
103 | - .updateUser(1L); | |
135 | + .updateUser(EXISTING_USER_ID); | |
104 | 136 | |
105 | 137 | then() |
106 | 138 | .assertUpdateSuccess(); |
... | ... | @@ -179,6 +211,24 @@ public class UserViewControllerTest { |
179 | 211 | actual = underTest.createUser(userDto); |
180 | 212 | } |
181 | 213 | |
214 | + private void getAllUsers() { | |
215 | + when(userService.findAllUsers()).thenReturn(new ArrayList<User>()); | |
216 | + | |
217 | + actualCollection = underTest.getAllUsers(); | |
218 | + } | |
219 | + | |
220 | + private void getUserById(final Long id) { | |
221 | + when(userService.findUser(id)).thenReturn(new User(USER_FIRSTNAME, "")); | |
222 | + | |
223 | + actualUser = underTest.getUser(id); | |
224 | + } | |
225 | + | |
226 | + private void getUser() { | |
227 | + when(userService.findUser()).thenReturn(new User(USER_FIRSTNAME, "")); | |
228 | + | |
229 | + actualUser = underTest.getUser(); | |
230 | + } | |
231 | + | |
182 | 232 | private void updateUser() { |
183 | 233 | when(userService.updateUser(userDto)).thenReturn(true); |
184 | 234 | |
... | ... | @@ -219,6 +269,19 @@ public class UserViewControllerTest { |
219 | 269 | assertEquals(expected, actual); |
220 | 270 | } |
221 | 271 | |
272 | + private void assertGetAllUsersSuccess() { | |
273 | + final Collection<User> expectedCollection = new ArrayList<>(); | |
274 | + assertEquals(expectedCollection, actualCollection); | |
275 | + } | |
276 | + | |
277 | + private void assertGetUserByIdSuccess() { | |
278 | + assertEquals(USER_FIRSTNAME, actualUser.getFirstname()); | |
279 | + } | |
280 | + | |
281 | + private void assertGetUserSuccess() { | |
282 | + assertEquals(USER_FIRSTNAME, actualUser.getFirstname()); | |
283 | + } | |
284 | + | |
222 | 285 | private void assertUpdateSuccess() { |
223 | 286 | final RestResponse expected = new RestResponse(); |
224 | 287 | assertEquals(expected, actual); | ... | ... |