コード例 #1
0
  @Test
  public void shouldNotGetAuthenticatedUserProfile() {

    when(authenticatedUserService.getAuthenticatedUser()).thenReturn(null);
    when(userRepository.findOne(Matchers.anyInt())).thenReturn(new User());

    service.getAuthenticatedUserProfile();

    verify(authenticatedUserService, times(1)).getAuthenticatedUser();
    verify(userRepository, times(0)).findOne(Matchers.anyInt());
  }
コード例 #2
0
  @Test
  public void shouldGetAuthenticatedUserProfile() {
    User user = new User();
    user.setId(0);
    AuthenticatedUser authUser = new AuthenticatedUser(user);

    when(authenticatedUserService.getAuthenticatedUser()).thenReturn(authUser);
    when(userRepository.findOne(Matchers.anyInt())).thenReturn(new User());

    service.getAuthenticatedUserProfile();

    verify(authenticatedUserService, times(1)).getAuthenticatedUser();
    verify(userRepository, times(1)).findOne(Matchers.anyInt());
  }
コード例 #3
0
  @Test
  public void shouldGetAllConnections() {
    User user = new User();
    user.setId(0);
    AuthenticatedUser authUser = new AuthenticatedUser(user);
    when(authenticatedUserService.getAuthenticatedUser()).thenReturn(authUser);
    when(userRepository.findAllConnectedUsers(Matchers.any(User.class)))
        .thenReturn(new ArrayList<User>());

    service.getAllConnections();

    verify(authenticatedUserService, times(1)).getAuthenticatedUser();
    verify(userRepository, times(1)).findAllConnectedUsers(Matchers.any(User.class));
  }