Example #1
0
  @Test
  public void testAddAndRemoveUser() throws Exception {
    // given
    User user = new User();

    // call populate method in super class to populate test data
    // from a properties file matching this class name
    user = (User) populate(user);

    Role role = new Role(Constants.USER_ROLE);
    user.addRole(role);

    final User user1 = user;
    given(userDao.saveUser(user1)).willReturn(user1);

    // when
    user = userManager.saveUser(user);

    // then
    assertTrue(user.getUsername().equals("john"));
    assertTrue(user.getRoles().size() == 1);

    // given
    willDoNothing().given(userDao).remove(5L);
    userManager.removeUser("5");

    given(userDao.get(5L)).willReturn(null);

    // when
    user = userManager.getUser("5");

    // then
    assertNull(user);
    verify(userDao).remove(5L);
  }
Example #2
0
  @Test
  public void testGetUser() throws Exception {
    // given
    final User testData = new User("1");
    testData.getRoles().add(new Role("user"));

    given(userDao.get(1L)).willReturn(testData);

    // then
    User user = userManager.getUser("1");

    // then
    assertTrue(user != null);
    assert user != null;
    assertTrue(user.getRoles().size() == 1);
  }
Example #3
0
  @Test
  public void testSaveUser() throws Exception {
    // given
    final User testData = new User("1");
    testData.getRoles().add(new Role("user"));

    given(userDao.get(1L)).willReturn(testData);

    final User user = userManager.getUser("1");
    user.setPhoneNumber("303-555-1212");

    given(userDao.saveUser(user)).willReturn(user);

    // when
    User returned = userManager.saveUser(user);

    // then
    assertTrue(returned.getPhoneNumber().equals("303-555-1212"));
    assertTrue(returned.getRoles().size() == 1);
  }