@Test public void generate_mail_for_social_account_validation_with_token() { Mockito.when(urlFactory.getBaseUrl()).thenReturn("http: assertThat(mailBuilder.buildContent(MailBuilder.TypeMail.SOCIAL_ACCOUNT_VALIDATION, new Account().setToken("MY-TOKEN-SECURED"), Optional.empty())) .contains("http: }
public String buildContent(TypeMail typeMail, Account account, Optional<OAuthProvider> provider) { Preconditions.checkNotNull(typeMail, "type is required"); Preconditions.checkNotNull(account, "credentials are required"); String lang = account.getDefaultLanguage().equals(SessionLanguage.en) ? "en" : "fr"; Map<String, Object> model = new HashMap<>(); model.put("account", account); switch (typeMail) { case REINIT_PASSWORD: model.put("url", String.format("%s/app/account/password?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-reinit-password-%s.vm", lang), "UTF-8", model); case EMAIL_CHANGED: model.put("url", String.format("%s/app/account/password?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-change-email-%s.vm", lang), "UTF-8", model); case ACCOUND_NEW_VALIDATION: model.put("provider", provider.orElse(OAuthProvider.TWITTER).toString()); model.put("url", String.format("%s/app/account/valid?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-account-validation-%s.vm", lang), "UTF-8", model); case CESAR_ACCOUNT_VALIDATION: case SOCIAL_ACCOUNT_VALIDATION: model.put("url", String.format("%s/app/account/valid?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-account-new-%s.vm", lang), "UTF-8", model); default: return null; } }
MailBuilder { public String buildContent(TypeMail typeMail, Account account, Optional<OAuthProvider> provider) { Preconditions.checkNotNull(typeMail, "type is required"); Preconditions.checkNotNull(account, "credentials are required"); String lang = account.getDefaultLanguage().equals(SessionLanguage.en) ? "en" : "fr"; Map<String, Object> model = new HashMap<>(); model.put("account", account); switch (typeMail) { case REINIT_PASSWORD: model.put("url", String.format("%s/app/account/password?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-reinit-password-%s.vm", lang), "UTF-8", model); case EMAIL_CHANGED: model.put("url", String.format("%s/app/account/password?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-change-email-%s.vm", lang), "UTF-8", model); case ACCOUND_NEW_VALIDATION: model.put("provider", provider.orElse(OAuthProvider.TWITTER).toString()); model.put("url", String.format("%s/app/account/valid?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-account-validation-%s.vm", lang), "UTF-8", model); case CESAR_ACCOUNT_VALIDATION: case SOCIAL_ACCOUNT_VALIDATION: model.put("url", String.format("%s/app/account/valid?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-account-new-%s.vm", lang), "UTF-8", model); default: return null; } } }
MailBuilder { public String buildContent(TypeMail typeMail, Account account, Optional<OAuthProvider> provider) { Preconditions.checkNotNull(typeMail, "type is required"); Preconditions.checkNotNull(account, "credentials are required"); String lang = account.getDefaultLanguage().equals(SessionLanguage.en) ? "en" : "fr"; Map<String, Object> model = new HashMap<>(); model.put("account", account); switch (typeMail) { case REINIT_PASSWORD: model.put("url", String.format("%s/app/account/password?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-reinit-password-%s.vm", lang), "UTF-8", model); case EMAIL_CHANGED: model.put("url", String.format("%s/app/account/password?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-change-email-%s.vm", lang), "UTF-8", model); case ACCOUND_NEW_VALIDATION: model.put("provider", provider.orElse(OAuthProvider.TWITTER).toString()); model.put("url", String.format("%s/app/account/valid?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-account-validation-%s.vm", lang), "UTF-8", model); case CESAR_ACCOUNT_VALIDATION: case SOCIAL_ACCOUNT_VALIDATION: model.put("url", String.format("%s/app/account/valid?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-account-new-%s.vm", lang), "UTF-8", model); default: return null; } }  }
MailBuilder { public String buildContent(TypeMail typeMail, Account account, Optional<OAuthProvider> provider) { Preconditions.checkNotNull(typeMail, "type is required"); Preconditions.checkNotNull(account, "credentials are required"); String lang = account.getDefaultLanguage().equals(SessionLanguage.en) ? "en" : "fr"; Map<String, Object> model = new HashMap<>(); model.put("account", account); switch (typeMail) { case REINIT_PASSWORD: model.put("url", String.format("%s/app/account/password?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-reinit-password-%s.vm", lang), "UTF-8", model); case EMAIL_CHANGED: model.put("url", String.format("%s/app/account/password?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-change-email-%s.vm", lang), "UTF-8", model); case ACCOUND_NEW_VALIDATION: model.put("provider", provider.orElse(OAuthProvider.TWITTER).toString()); model.put("url", String.format("%s/app/account/valid?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-account-validation-%s.vm", lang), "UTF-8", model); case CESAR_ACCOUNT_VALIDATION: case SOCIAL_ACCOUNT_VALIDATION: model.put("url", String.format("%s/app/account/valid?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-account-new-%s.vm", lang), "UTF-8", model); default: return null; } }  String buildContent(TypeMail typeMail, Account account, Optional<OAuthProvider> provider); String getTitle(TypeMail typeMail, Account account); }
MailBuilder { public String buildContent(TypeMail typeMail, Account account, Optional<OAuthProvider> provider) { Preconditions.checkNotNull(typeMail, "type is required"); Preconditions.checkNotNull(account, "credentials are required"); String lang = account.getDefaultLanguage().equals(SessionLanguage.en) ? "en" : "fr"; Map<String, Object> model = new HashMap<>(); model.put("account", account); switch (typeMail) { case REINIT_PASSWORD: model.put("url", String.format("%s/app/account/password?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-reinit-password-%s.vm", lang), "UTF-8", model); case EMAIL_CHANGED: model.put("url", String.format("%s/app/account/password?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-change-email-%s.vm", lang), "UTF-8", model); case ACCOUND_NEW_VALIDATION: model.put("provider", provider.orElse(OAuthProvider.TWITTER).toString()); model.put("url", String.format("%s/app/account/valid?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-account-validation-%s.vm", lang), "UTF-8", model); case CESAR_ACCOUNT_VALIDATION: case SOCIAL_ACCOUNT_VALIDATION: model.put("url", String.format("%s/app/account/valid?token=%s", urlFactory.getBaseUrl(), account.getToken())); return VelocityEngineUtils.mergeTemplateIntoString( this.velocityEngine, String.format("email-account-new-%s.vm", lang), "UTF-8", model); default: return null; } }  String buildContent(TypeMail typeMail, Account account, Optional<OAuthProvider> provider); String getTitle(TypeMail typeMail, Account account);  }