@Test public void create_social_account_but_without_token() { when(authorityRepository.findByName(Role.MEMBER)).thenReturn(new Authority().setName(Role.MEMBER)); when(accountRepository.save(any(Account.class))).thenAnswer(invocation -> cloneAccount.apply(invocation.getArgumentAt(0, Account.class))); assertThat(createSocialAccountService.createAccount(OAuthProvider.GOOGLE, "anOAUTHID").getToken()).isNull(); }
public Account createAccount(OAuthProvider provider, String oauthId) { Preconditions.checkNotNull(provider); Preconditions.checkNotNull(oauthId); Account account = accountRepository.save( new Account() .setProvider(provider) .setOauthId(oauthId) .setRegisteredAt(LocalDateTime.now()) .setDefaultLanguage(SessionLanguage.fr) .setValid(false) ); account.addAuthority(authorityRepository.findByName(Role.MEMBER)); accountRepository.save(account); return account; }
CreateSocialAccountService { public Account createAccount(OAuthProvider provider, String oauthId) { Preconditions.checkNotNull(provider); Preconditions.checkNotNull(oauthId); Account account = accountRepository.save( new Account() .setProvider(provider) .setOauthId(oauthId) .setRegisteredAt(LocalDateTime.now()) .setDefaultLanguage(SessionLanguage.fr) .setValid(false) ); account.addAuthority(authorityRepository.findByName(Role.MEMBER)); accountRepository.save(account); return account; } }
CreateSocialAccountService { public Account createAccount(OAuthProvider provider, String oauthId) { Preconditions.checkNotNull(provider); Preconditions.checkNotNull(oauthId); Account account = accountRepository.save( new Account() .setProvider(provider) .setOauthId(oauthId) .setRegisteredAt(LocalDateTime.now()) .setDefaultLanguage(SessionLanguage.fr) .setValid(false) ); account.addAuthority(authorityRepository.findByName(Role.MEMBER)); accountRepository.save(account); return account; }  }
CreateSocialAccountService { public Account createAccount(OAuthProvider provider, String oauthId) { Preconditions.checkNotNull(provider); Preconditions.checkNotNull(oauthId); Account account = accountRepository.save( new Account() .setProvider(provider) .setOauthId(oauthId) .setRegisteredAt(LocalDateTime.now()) .setDefaultLanguage(SessionLanguage.fr) .setValid(false) ); account.addAuthority(authorityRepository.findByName(Role.MEMBER)); accountRepository.save(account); return account; }  Account createAccount(OAuthProvider provider, String oauthId); void updateAccount(Account account, String token, String oauthId); }
CreateSocialAccountService { public Account createAccount(OAuthProvider provider, String oauthId) { Preconditions.checkNotNull(provider); Preconditions.checkNotNull(oauthId); Account account = accountRepository.save( new Account() .setProvider(provider) .setOauthId(oauthId) .setRegisteredAt(LocalDateTime.now()) .setDefaultLanguage(SessionLanguage.fr) .setValid(false) ); account.addAuthority(authorityRepository.findByName(Role.MEMBER)); accountRepository.save(account); return account; }  Account createAccount(OAuthProvider provider, String oauthId); void updateAccount(Account account, String token, String oauthId);  }