mirror of
https://github.com/google/nomulus
synced 2026-09-06 08:07:03 +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:
@@ -91,14 +91,14 @@ public class RegistrarSettingsActionTestCase {
|
||||
action.registrarChangesNotificationEmailAddresses = ImmutableList.of(
|
||||
"notification@test.example", "notification2@test.example");
|
||||
action.sendEmailUtils =
|
||||
new SendEmailUtils(getGSuiteOutgoingEmailAddress(), getGSuiteOutgoingEmailDisplayName());
|
||||
new SendEmailUtils(
|
||||
getGSuiteOutgoingEmailAddress(), getGSuiteOutgoingEmailDisplayName(), emailService);
|
||||
action.registryEnvironment = RegistryEnvironment.get();
|
||||
action.authResult =
|
||||
AuthResult.create(
|
||||
AuthLevel.USER,
|
||||
UserAuthInfo.create(new User("user@email.com", "email.com", "12345"), false));
|
||||
inject.setStaticField(Ofy.class, "clock", clock);
|
||||
inject.setStaticField(SendEmailUtils.class, "emailService", emailService);
|
||||
message = new MimeMessage(Session.getDefaultInstance(new Properties(), null));
|
||||
when(emailService.createMessage()).thenReturn(message);
|
||||
when(req.getMethod()).thenReturn("POST");
|
||||
|
||||
@@ -25,7 +25,6 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.testing.InjectRule;
|
||||
import google.registry.util.SendEmailService;
|
||||
import java.util.Properties;
|
||||
import javax.mail.Message;
|
||||
@@ -35,7 +34,6 @@ import javax.mail.Session;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
@@ -44,9 +42,6 @@ import org.junit.runners.JUnit4;
|
||||
@RunWith(JUnit4.class)
|
||||
public class SendEmailUtilsTest {
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
private final SendEmailService emailService = mock(SendEmailService.class);
|
||||
|
||||
private Message message;
|
||||
@@ -54,11 +49,11 @@ public class SendEmailUtilsTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
inject.setStaticField(SendEmailUtils.class, "emailService", emailService);
|
||||
message = new MimeMessage(Session.getDefaultInstance(new Properties(), null));
|
||||
when(emailService.createMessage()).thenReturn(message);
|
||||
sendEmailUtils =
|
||||
new SendEmailUtils(getGSuiteOutgoingEmailAddress(), getGSuiteOutgoingEmailDisplayName());
|
||||
new SendEmailUtils(
|
||||
getGSuiteOutgoingEmailAddress(), getGSuiteOutgoingEmailDisplayName(), emailService);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user