@Test @DisplayName("hogehoge@hoge.comで例外発生") public void loadUserByUsernameTest2() { assertThrows(UsernameNotFoundException.class, () -> { accountDetailsService.loadUserByUsername("hogehoge@hoge.com"); }); }
@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 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 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); }
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); }
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);  }