コード例 #1
0
 @Test
 public void shouldInitializeWithTwoDemoUsers() {
   // act
   accountService.initialize();
   // assert
   verify(accountRepositoryMock, times(2)).save(any(Account.class));
 }
コード例 #2
0
  @Test
  public void shouldThrowExceptionWhenUserNotFound() {
    // arrange
    thrown.expect(UsernameNotFoundException.class);
    thrown.expectMessage("user not found");

    when(accountRepositoryMock.findOneByEmail("*****@*****.**")).thenReturn(null);
    // act
    accountService.loadUserByUsername("*****@*****.**");
  }
コード例 #3
0
  @Test
  public void shouldReturnUserDetails() {
    // arrange
    Account demoUser = new Account("*****@*****.**", "demo", "ROLE_USER");
    when(accountRepositoryMock.findOneByEmail("*****@*****.**")).thenReturn(demoUser);

    // act
    UserDetails userDetails = accountService.loadUserByUsername("*****@*****.**");

    // assert
    assertThat(demoUser.getEmail()).isEqualTo(userDetails.getUsername());
    assertThat(demoUser.getPassword()).isEqualTo(userDetails.getPassword());
    assertThat(hasAuthority(userDetails, demoUser.getRole())).isTrue();
  }