@Test public void shouldThrowExceptionWhenUserNotFound() { // arrange thrown.expect(UsernameNotFoundException.class); thrown.expectMessage("user not found"); when(accountRepositoryMock.findOneByEmail("*****@*****.**")).thenReturn(null); // act accountService.loadUserByUsername("*****@*****.**"); }
@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(); }