### Question:
AccountDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Optional<Account> accountOptional = accountRepository.findByEmail(username); Account account = accountOptional.orElseThrow(() -> new UsernameNotFoundException("user not found")); AccountDetails accountDetails = new AccountDetails(account); return accountDetails; } AccountDetailsService(AccountRepository accountRepository); @Override UserDetails loadUserByUsername(String username);  }### Answer:
@Test @DisplayName("user@example.comでユーザーを検索できる") public void loadUserByUsernameTest1() { AccountDetails accountDetails = (AccountDetails) accountDetailsService.loadUserByUsername("user@example.com"); Account account = accountDetails.getAccount(); assertNotNull(account); List<String> authorities = account.getAuthorities(); assertEquals(1, authorities.size()); assertAll( () -> assertEquals(Integer.valueOf(1), account.getId()), () -> assertEquals("user", account.getName()), () -> assertEquals("user@example.com", account.getEmail()), () -> assertTrue(passwordEncoder.matches("user", account.getPassword())), () -> assertTrue(accountDetails.isAccountNonExpired()), () -> assertTrue(accountDetails.isAccountNonLocked()), () -> assertTrue(accountDetails.isCredentialsNonExpired()), () -> assertTrue(accountDetails.isEnabled()) ); }
@Test @DisplayName("hogehoge@hoge.comで例外発生") public void loadUserByUsernameTest2() { assertThrows(UsernameNotFoundException.class, () -> { accountDetailsService.loadUserByUsername("hogehoge@hoge.com"); }); }