ViewUsersControllerTest.java
1.31 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
package fr.plil.sio.web.mvc;
import org.junit.Before;
import org.junit.Test;
import java.util.LinkedList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class ViewUsersControllerTest {
private ViewUsersController viewUsersController;
private UserRepository userRepository;
private UserSession userSession;
@Before
public void createInstances() {
viewUsersController = new ViewUsersController();
userRepository = mock(UserRepository.class);
List<User> users = new LinkedList<>();
users.add(new User("admin", "password"));
when(userRepository.findAll()).thenReturn(users);
viewUsersController.setUserRepository(userRepository);
userSession = new UserSession();
userSession.setUsername("admin");
viewUsersController.setUserSession(userSession);
}
@Test
public void testPopulateUsers() {
assertEquals(1, viewUsersController.populateUsers().size());
}
@Test
public void testPopulateUser() {
assertEquals("admin", viewUsersController.populateUser().getUsername());
}
@Test
public void testGetViewUsers() {
assertEquals("viewUsers",viewUsersController.getViewUsers());
}
}