@Test
  public void testChangeToTutorWhenTutor() {
    when(mockUser.getRole()).thenReturn(ConstantVariables.TUTOR);

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

    assertEquals(this.mockUser, tmpUser);
  }
  @Test(expected = AssertionError.class)
  public void testSaveUserReturnsNull() {
    // GIVEN
    when(userDao.save(any(User.class))).thenReturn(null);

    // WHEN
    userService.save(this.mockUser);
  }
  @Test(expected = AssertionError.class)
  public void testGetNullUserByPrincipal() {
    // GIVEN
    when(userDao.findByEmail(anyString())).thenReturn(null);

    // WHEN
    userService.getUserByPrincipal(this.mockAuthUser);
  }
  @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);
  }
  @Test
  public void testGetUserByPrincipal() {
    // GIVEN
    when(userDao.findByEmail(anyString())).thenReturn(this.mockUser);

    // WHEN
    User tmpUser = userService.getUserByPrincipal(this.mockAuthUser);

    // THEN
    assertEquals(tmpUser, this.mockUser);
  }
  @Test
  public void testGetUserById() {
    // GIVEN
    when(userDao.findOne(anyLong())).thenReturn(this.mockUser);

    // WHEN
    User tmpUser = userService.getUserById(Long.valueOf(1));

    // THEN
    assertEquals(tmpUser, this.mockUser);
  }
  @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());
  }
 @Test(expected = AssertionError.class)
 public void testGetUserByIdNull() {
   userService.getUserById(null);
 }
 @Test(expected = AssertionError.class)
 public void testSaveNull() {
   userService.save(null);
 }
Esempio n. 10
0
 @Test(expected = AssertionError.class)
 public void testChangedToTutorWhenNull() {
   userService.changeToTutor(null);
 }