コード例 #1
0
  @Test
  public void testSave() {
    // GIVEN
    when(userDao.save(any(User.class))).then(returnsFirstArg());

    // WHEN
    ReflectionTestUtils.setField(mockUser, "email", "*****@*****.**");

    User tmpUser = userService.save(this.mockUser);

    // THEN
    assertEquals(this.mockUser.getEmail(), tmpUser.getEmail());
  }
コード例 #2
0
  @Test
  public void testChangeToTutorWhenTutor() {
    when(mockUser.getRole()).thenReturn(ConstantVariables.TUTOR);

    User tmpUser = userService.changeToTutor(this.mockUser);

    assertEquals(this.mockUser, tmpUser);
  }
コード例 #3
0
  @Test
  public void testChangeToTutorWhenStudent() {
    when(userDao.save(mockUser)).then(returnsFirstArg());
    when(mockUser.getRole()).thenReturn(ConstantVariables.STUDENT);

    userService.changeToTutor(this.mockUser);

    verify(mockUser).setRole(ConstantVariables.TUTOR);
  }