Use Dagger to @Inject WhoisReader instances

This is a precursor to adding metrics to WHOIS queries (as I'd like
to be able to @Inject the metrics builders).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=149418018
This commit is contained in:
mcilwain 2017-03-07 07:47:38 -08:00 committed by Ben McIlwain
parent 53785c2fc7
commit bd7db61606
8 changed files with 51 additions and 51 deletions

View file

@ -34,6 +34,7 @@ import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import google.registry.testing.InjectRule;
import google.registry.testing.Providers;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.After;
@ -53,26 +54,22 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class WhoisHttpServerTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
@Rule
public final InjectRule inject = new InjectRule();
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule public final InjectRule inject = new InjectRule();
private final FakeResponse response = new FakeResponse();
private final FakeClock clock = new FakeClock(DateTime.parse("2009-06-29T20:13:00Z"));
private WhoisHttpServer newWhoisHttpServer(String pathInfo) {
WhoisHttpServer result = new WhoisHttpServer();
result.clock = clock;
result.expires = Duration.standardHours(1);
result.requestPath = WhoisHttpServer.PATH + pathInfo;
result.response = response;
result.disclaimer = "Doodle Disclaimer";
result.commandFactory = new WhoisCommandFactory();
return result;
WhoisHttpServer whoisServer = new WhoisHttpServer();
whoisServer.clock = clock;
whoisServer.expires = Duration.standardHours(1);
whoisServer.requestPath = WhoisHttpServer.PATH + pathInfo;
whoisServer.response = response;
whoisServer.whoisReaderFactory =
new WhoisReaderFactory(Providers.of(new WhoisCommandFactory()));
whoisServer.disclaimer = "Doodle Disclaimer";
return whoisServer;
}
@Before

View file

@ -45,8 +45,8 @@ public class WhoisReaderTest {
@SuppressWarnings("unchecked") // XXX: Generic abuse ftw.
<T> T readCommand(String commandStr) throws Exception {
return (T)
new WhoisReader(new StringReader(commandStr), new WhoisCommandFactory(), clock.nowUtc())
.readCommand();
new WhoisReader(new WhoisCommandFactory(), clock.nowUtc())
.readCommand(new StringReader(commandStr));
}
void assertLoadsExampleTld(String commandString) throws Exception {

View file

@ -36,6 +36,7 @@ import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import google.registry.testing.InjectRule;
import google.registry.testing.Providers;
import java.io.StringReader;
import org.joda.time.DateTime;
import org.junit.Before;
@ -49,25 +50,21 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class WhoisServerTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
@Rule
public final InjectRule inject = new InjectRule();
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule public final InjectRule inject = new InjectRule();
private final FakeResponse response = new FakeResponse();
private final FakeClock clock = new FakeClock(DateTime.parse("2009-06-29T20:13:00Z"));
private WhoisServer newWhoisServer(String input) {
WhoisServer result = new WhoisServer();
result.clock = clock;
result.input = new StringReader(input);
result.response = response;
result.disclaimer = "Doodle Disclaimer";
result.commandFactory = new WhoisCommandFactory();
return result;
WhoisServer whoisServer = new WhoisServer();
whoisServer.clock = clock;
whoisServer.input = new StringReader(input);
whoisServer.response = response;
whoisServer.whoisReaderFactory =
new WhoisReaderFactory(Providers.of(new WhoisCommandFactory()));
whoisServer.disclaimer = "Doodle Disclaimer";
return whoisServer;
}
@Before