Blame view

src/test/java/fr/plil/sio/web/mvc/ViewUsersControllerTest.java 1.31 KB
aa193b2b   Julien Iguchi-Cartigny   First version
1
2
  package fr.plil.sio.web.mvc;
  
aa193b2b   Julien Iguchi-Cartigny   First version
3
4
5
  import org.junit.Before;
  import org.junit.Test;
  
2070653e   Julien Iguchi-Cartigny   Switching to spri...
6
7
8
9
10
11
12
  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;
  
aa193b2b   Julien Iguchi-Cartigny   First version
13
14
15
  public class ViewUsersControllerTest {
  
      private ViewUsersController viewUsersController;
8efec875   Julien Iguchi-Cartigny   switch to spring ...
16
      private UserRepository userRepository;
aa193b2b   Julien Iguchi-Cartigny   First version
17
18
19
20
21
      private UserSession userSession;
  
      @Before
      public void createInstances() {
          viewUsersController = new ViewUsersController();
2070653e   Julien Iguchi-Cartigny   Switching to spri...
22
23
24
25
          userRepository = mock(UserRepository.class);
          List<User> users = new LinkedList<>();
          users.add(new User("admin", "password"));
          when(userRepository.findAll()).thenReturn(users);
8efec875   Julien Iguchi-Cartigny   switch to spring ...
26
          viewUsersController.setUserRepository(userRepository);
aa193b2b   Julien Iguchi-Cartigny   First version
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
          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());
      }
  }