mirror of
https://github.com/google/nomulus
synced 2026-01-11 08:20:27 +00:00
Change SendEmailService to an instance field.
This allows us to inject it with Dagger and avoid using InjectRule to set it in unit tests. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=217571475
This commit is contained in:
@@ -25,7 +25,6 @@ import dagger.Provides;
|
||||
import google.registry.bigquery.BigqueryConnection;
|
||||
import google.registry.request.HttpException.BadRequestException;
|
||||
import google.registry.request.Parameter;
|
||||
import google.registry.util.SendEmailService;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.util.Optional;
|
||||
@@ -115,11 +114,6 @@ public final class IcannReportingModule {
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
static SendEmailService provideSendEmailService() {
|
||||
return new SendEmailService();
|
||||
}
|
||||
|
||||
/** Dagger qualifier for the subdirectory we stage to/upload from. */
|
||||
@Qualifier
|
||||
@Documented
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.util.NonFinalForTesting;
|
||||
import google.registry.util.SendEmailService;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -39,18 +38,18 @@ public class SendEmailUtils {
|
||||
|
||||
private final String gSuiteOutgoingEmailAddress;
|
||||
private final String gSuiteOutoingEmailDisplayName;
|
||||
private final SendEmailService emailService;
|
||||
|
||||
@Inject
|
||||
public SendEmailUtils(
|
||||
@Config("gSuiteOutgoingEmailAddress") String gSuiteOutgoingEmailAddress,
|
||||
@Config("gSuiteOutoingEmailDisplayName") String gSuiteOutoingEmailDisplayName) {
|
||||
@Config("gSuiteOutoingEmailDisplayName") String gSuiteOutoingEmailDisplayName,
|
||||
SendEmailService emailService) {
|
||||
this.gSuiteOutgoingEmailAddress = gSuiteOutgoingEmailAddress;
|
||||
this.gSuiteOutoingEmailDisplayName = gSuiteOutoingEmailDisplayName;
|
||||
this.emailService = emailService;
|
||||
}
|
||||
|
||||
@NonFinalForTesting
|
||||
private static SendEmailService emailService = new SendEmailService();
|
||||
|
||||
/**
|
||||
* Sends an email from Nomulus to the specified recipient(s). Returns true iff sending was
|
||||
* successful.
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
package google.registry.util;
|
||||
|
||||
import java.util.Properties;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Session;
|
||||
@@ -22,8 +24,12 @@ import javax.mail.Transport;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
/** Wrapper around javax.mail's Transport.send that can be mocked for testing purposes. */
|
||||
@Singleton
|
||||
public class SendEmailService {
|
||||
|
||||
@Inject
|
||||
SendEmailService() {};
|
||||
|
||||
/** Returns a new MimeMessage using default App Engine transport settings. */
|
||||
public Message createMessage() {
|
||||
return new MimeMessage(Session.getDefaultInstance(new Properties(), null));
|
||||
|
||||
Reference in New Issue
Block a user