UserViewControllerTest.java
3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package net.ziemers.swxercise.ui;
import net.ziemers.swxercise.lg.model.user.User;
import net.ziemers.swxercise.lg.testdatabuilder.user.UserDtoTestDataBuilder;
import net.ziemers.swxercise.lg.testdatabuilder.user.UserTestDataBuilder;
import net.ziemers.swxercise.lg.user.dto.UserDto;
import net.ziemers.swxercise.lg.user.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class UserViewControllerTest {
/*
* You have the @InjectMocks annotation which tries to do constructor,
* method and field dependency injection based on the type.
*/
@InjectMocks
private UserViewController underTest;
/*
* Mockito allows to configure the return values of its mocks via a fluent API.
* Unspecified method calls return "empty" values
*/
@Mock
private UserService userService;
private UserDto userDto;
private User user;
private RestResponse actual;
@Test
public void testJUnitFrameworkReturnsTrue() {
assertTrue(true);
}
@Test(expected = AssertionError.class)
public void testJUnitFrameworkThrowsException() {
assertTrue(false);
}
@Test
public void testGetAllUsersReturnsUsersJson() {
// TODO Test ist noch zu implementieren
}
@Test
public void testGetUserByIdReturnsUserJson() {
// TODO Test ist noch zu implementieren
}
@Test
public void testCreateUserReturnsSuccess() {
// TODO Test ist noch zu implementieren
}
@Test
public void testUpdateUserReturnsSuccess() {
// TODO Test ist noch zu implementieren
}
@Test
public void testDeleteUserByIdReturnsSuccess() {
// TODO Test ist noch zu implementieren
}
@Test
public void testDeleteSessionUserReturnsSuccess() {
// TODO Test ist noch zu implementieren
}
@Test
public void testLoginUserReturnsSuccess() {
given()
.userDto()
.user();
doing()
.loginUser();
then()
.assertLoginSuccess();
}
@Test
public void testLogoutUserReturnsSuccess() {
doing()
.logoutUser();
then()
.assertLogoutSuccess();
}
// given
private UserViewControllerTest given() {
return this;
}
private UserViewControllerTest userDto() {
userDto = new UserDtoTestDataBuilder().build();
return this;
}
private UserViewControllerTest user() {
user = new UserTestDataBuilder().build();
return this;
}
// doing
private UserViewControllerTest doing() {
return this;
}
private void loginUser() {
/*
* The when().thenReturn() method chain is used to specify
* a return value for a method call with pre-defined parameters.
*/
when(userService.loginUser(userDto)).thenReturn(true);
actual = underTest.loginUser(userDto);
}
private void logoutUser() {
when(userService.logoutUser()).thenReturn(true);
actual = underTest.logoutUser();
}
// then
private UserViewControllerTest then() {
return this;
}
private void assertLoginSuccess() {
final RestResponse expected = new RestResponse();
assertEquals(expected, actual);
}
private void assertLogoutSuccess() {
final RestResponse expected = new RestResponse();
assertEquals(expected, actual);
}
}