@Test public void create_account_send_mail_to_confirm_validation() { when(authorityRepository.findByName(Role.MEMBER)).thenReturn(new Authority().setId(1L).setName(Role.MEMBER)); when(accountRepository.save(any(Account.class))).thenReturn(new Account()); createCesarAccountService.createNormalAccount(new Account()); verify(mailBuilder).buildContent(any(MailBuilder.TypeMail.class), any(Account.class), any()); }
public Account createNormalAccount(Account account) { account.setProvider(OAuthProvider.CESAR); account.setOauthId(UUID.randomUUID().toString()); tokenService.generateNewToken(account); if (accountRepository.findByLogin(account.getLogin()) != null) { throw new LoginExistException(); } Member member = tokenService.tryToLinkWithActualMember(account); if(member==null){ member = memberRepository.save(updateMember(new Member(), account)); } else{ member.getROLES().clear(); updateMember(member, account); } account .setValid(false) .setMember(member) .setPassword(cryptoService.passwordHash(account.getPassword())); accountRepository.save(account).addAuthority(authorityRepository.findByName(Role.MEMBER)); mailerService.send( account.getEmail(), mailBuilder.getTitle(MailBuilder.TypeMail.CESAR_ACCOUNT_VALIDATION, account), mailBuilder.buildContent(MailBuilder.TypeMail.CESAR_ACCOUNT_VALIDATION, account, Optional.empty())); return account; }
CreateCesarAccountService { public Account createNormalAccount(Account account) { account.setProvider(OAuthProvider.CESAR); account.setOauthId(UUID.randomUUID().toString()); tokenService.generateNewToken(account); if (accountRepository.findByLogin(account.getLogin()) != null) { throw new LoginExistException(); } Member member = tokenService.tryToLinkWithActualMember(account); if(member==null){ member = memberRepository.save(updateMember(new Member(), account)); } else{ member.getROLES().clear(); updateMember(member, account); } account .setValid(false) .setMember(member) .setPassword(cryptoService.passwordHash(account.getPassword())); accountRepository.save(account).addAuthority(authorityRepository.findByName(Role.MEMBER)); mailerService.send( account.getEmail(), mailBuilder.getTitle(MailBuilder.TypeMail.CESAR_ACCOUNT_VALIDATION, account), mailBuilder.buildContent(MailBuilder.TypeMail.CESAR_ACCOUNT_VALIDATION, account, Optional.empty())); return account; } }
CreateCesarAccountService { public Account createNormalAccount(Account account) { account.setProvider(OAuthProvider.CESAR); account.setOauthId(UUID.randomUUID().toString()); tokenService.generateNewToken(account); if (accountRepository.findByLogin(account.getLogin()) != null) { throw new LoginExistException(); } Member member = tokenService.tryToLinkWithActualMember(account); if(member==null){ member = memberRepository.save(updateMember(new Member(), account)); } else{ member.getROLES().clear(); updateMember(member, account); } account .setValid(false) .setMember(member) .setPassword(cryptoService.passwordHash(account.getPassword())); accountRepository.save(account).addAuthority(authorityRepository.findByName(Role.MEMBER)); mailerService.send( account.getEmail(), mailBuilder.getTitle(MailBuilder.TypeMail.CESAR_ACCOUNT_VALIDATION, account), mailBuilder.buildContent(MailBuilder.TypeMail.CESAR_ACCOUNT_VALIDATION, account, Optional.empty())); return account; }  }
CreateCesarAccountService { public Account createNormalAccount(Account account) { account.setProvider(OAuthProvider.CESAR); account.setOauthId(UUID.randomUUID().toString()); tokenService.generateNewToken(account); if (accountRepository.findByLogin(account.getLogin()) != null) { throw new LoginExistException(); } Member member = tokenService.tryToLinkWithActualMember(account); if(member==null){ member = memberRepository.save(updateMember(new Member(), account)); } else{ member.getROLES().clear(); updateMember(member, account); } account .setValid(false) .setMember(member) .setPassword(cryptoService.passwordHash(account.getPassword())); accountRepository.save(account).addAuthority(authorityRepository.findByName(Role.MEMBER)); mailerService.send( account.getEmail(), mailBuilder.getTitle(MailBuilder.TypeMail.CESAR_ACCOUNT_VALIDATION, account), mailBuilder.buildContent(MailBuilder.TypeMail.CESAR_ACCOUNT_VALIDATION, account, Optional.empty())); return account; }  Account createNormalAccount(Account account); Account updateAccount(Account account); }
CreateCesarAccountService { public Account createNormalAccount(Account account) { account.setProvider(OAuthProvider.CESAR); account.setOauthId(UUID.randomUUID().toString()); tokenService.generateNewToken(account); if (accountRepository.findByLogin(account.getLogin()) != null) { throw new LoginExistException(); } Member member = tokenService.tryToLinkWithActualMember(account); if(member==null){ member = memberRepository.save(updateMember(new Member(), account)); } else{ member.getROLES().clear(); updateMember(member, account); } account .setValid(false) .setMember(member) .setPassword(cryptoService.passwordHash(account.getPassword())); accountRepository.save(account).addAuthority(authorityRepository.findByName(Role.MEMBER)); mailerService.send( account.getEmail(), mailBuilder.getTitle(MailBuilder.TypeMail.CESAR_ACCOUNT_VALIDATION, account), mailBuilder.buildContent(MailBuilder.TypeMail.CESAR_ACCOUNT_VALIDATION, account, Optional.empty())); return account; }  Account createNormalAccount(Account account); Account updateAccount(Account account); @Autowired
    public AbsoluteUrlFactory urlFactory; }