Use method references when possible

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179586059
This commit is contained in:
mcilwain 2017-12-19 12:06:12 -08:00 committed by Ben McIlwain
parent ed0670b614
commit 842689f0c1
22 changed files with 90 additions and 98 deletions

View file

@ -185,8 +185,7 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
fieldMap.putAll(getFieldOverrides(object)); fieldMap.putAll(getFieldOverrides(object));
// Next, add to the mapping all the aliases, with their values defined as whatever was in the // Next, add to the mapping all the aliases, with their values defined as whatever was in the
// map under the aliased field's original name. // map under the aliased field's original name.
fieldMap.putAll( fieldMap.putAll(new HashMap<>(Maps.transformValues(getFieldAliases(), fieldMap::get)));
new HashMap<>(Maps.transformValues(getFieldAliases(), value -> fieldMap.get(value))));
Set<String> expectedFields = ImmutableSortedSet.copyOf(fieldMap.keySet()); Set<String> expectedFields = ImmutableSortedSet.copyOf(fieldMap.keySet());
for (String field : fields) { for (String field : fields) {
checkArgument(fieldMap.containsKey(field), checkArgument(fieldMap.containsKey(field),

View file

@ -646,7 +646,7 @@ public class ExpandRecurringBillingEventsActionTest
public void testFailure_cursorAfterExecutionTime() throws Exception { public void testFailure_cursorAfterExecutionTime() throws Exception {
action.cursorTimeParam = Optional.of(clock.nowUtc().plusYears(1)); action.cursorTimeParam = Optional.of(clock.nowUtc().plusYears(1));
IllegalArgumentException thrown = IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> runMapreduce()); expectThrows(IllegalArgumentException.class, this::runMapreduce);
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Cursor time must be earlier than execution time."); .contains("Cursor time must be earlier than execution time.");
@ -657,7 +657,7 @@ public class ExpandRecurringBillingEventsActionTest
// The clock advances one milli on runMapreduce. // The clock advances one milli on runMapreduce.
action.cursorTimeParam = Optional.of(clock.nowUtc().plusMillis(1)); action.cursorTimeParam = Optional.of(clock.nowUtc().plusMillis(1));
IllegalArgumentException thrown = IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> runMapreduce()); expectThrows(IllegalArgumentException.class, this::runMapreduce);
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Cursor time must be earlier than execution time."); .contains("Cursor time must be earlier than execution time.");

View file

@ -276,7 +276,7 @@ public class DomainTransferApproveFlowTest
.setEventTime(domain.getRegistrationExpirationTime()) .setEventTime(domain.getRegistrationExpirationTime())
.setParent(historyEntryTransferApproved) .setParent(historyEntryTransferApproved)
.build())) .build()))
.toArray(size -> new BillingEvent[size])); .toArray(BillingEvent[]::new));
// There should be a grace period for the new transfer billing event. // There should be a grace period for the new transfer billing event.
assertGracePeriods( assertGracePeriods(
domain.getGracePeriods(), domain.getGracePeriods(),
@ -311,7 +311,7 @@ public class DomainTransferApproveFlowTest
.setEventTime(domain.getRegistrationExpirationTime()) .setEventTime(domain.getRegistrationExpirationTime())
.setParent(historyEntryTransferApproved) .setParent(historyEntryTransferApproved)
.build())) .build()))
.toArray(size -> new BillingEvent[size])); .toArray(BillingEvent[]::new));
// There should be no grace period. // There should be no grace period.
assertGracePeriods(domain.getGracePeriods(), ImmutableMap.of()); assertGracePeriods(domain.getGracePeriods(), ImmutableMap.of());
} }

View file

@ -114,7 +114,7 @@ public class DirectoryGroupsConnectionTest {
public void test_addMemberToGroup_handlesExceptionThrownByDirectoryService() throws Exception { public void test_addMemberToGroup_handlesExceptionThrownByDirectoryService() throws Exception {
when(membersInsert.execute()).thenThrow( when(membersInsert.execute()).thenThrow(
makeResponseException(SC_INTERNAL_SERVER_ERROR, "Could not contact Directory server.")); makeResponseException(SC_INTERNAL_SERVER_ERROR, "Could not contact Directory server."));
assertThrows(GoogleJsonResponseException.class, () -> runAddMemberTest()); assertThrows(GoogleJsonResponseException.class, this::runAddMemberTest);
} }
@Test @Test
@ -178,7 +178,7 @@ public class DirectoryGroupsConnectionTest {
public void test_createGroup_handlesExceptionThrownByDirectoryService() throws Exception { public void test_createGroup_handlesExceptionThrownByDirectoryService() throws Exception {
when(groupsInsert.execute()).thenThrow( when(groupsInsert.execute()).thenThrow(
makeResponseException(SC_INTERNAL_SERVER_ERROR, "Could not contact Directory server.")); makeResponseException(SC_INTERNAL_SERVER_ERROR, "Could not contact Directory server."));
assertThrows(GoogleJsonResponseException.class, () -> runCreateGroupTest()); assertThrows(GoogleJsonResponseException.class, this::runCreateGroupTest);
} }
@Test @Test

View file

@ -74,8 +74,7 @@ public class RdeParserTest {
@Test @Test
public void testGetContactNotAtElement_throwsIllegalStateException() throws Exception { public void testGetContactNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) { try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = IllegalStateException thrown = expectThrows(IllegalStateException.class, parser::getContact);
expectThrows(IllegalStateException.class, () -> parser.getContact());
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeContact-1.0:contact"); .contains("Not at element urn:ietf:params:xml:ns:rdeContact-1.0:contact");
@ -159,8 +158,7 @@ public class RdeParserTest {
@Test @Test
public void testGetDomainNotAtElement_throwsIllegalStateException() throws Exception { public void testGetDomainNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) { try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = IllegalStateException thrown = expectThrows(IllegalStateException.class, parser::getDomain);
expectThrows(IllegalStateException.class, () -> parser.getDomain());
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeDomain-1.0:domain"); .contains("Not at element urn:ietf:params:xml:ns:rdeDomain-1.0:domain");
@ -272,8 +270,7 @@ public class RdeParserTest {
@Test @Test
public void testGetHostNotAtElement_throwsIllegalStateException() throws Exception { public void testGetHostNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) { try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = IllegalStateException thrown = expectThrows(IllegalStateException.class, parser::getHost);
expectThrows(IllegalStateException.class, () -> parser.getHost());
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeHost-1.0:host"); .contains("Not at element urn:ietf:params:xml:ns:rdeHost-1.0:host");
@ -387,7 +384,7 @@ public class RdeParserTest {
public void testGetRegistrarNotAtElement_throwsIllegalStateException() throws Exception { public void testGetRegistrarNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) { try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = IllegalStateException thrown =
expectThrows(IllegalStateException.class, () -> parser.getRegistrar()); expectThrows(IllegalStateException.class, parser::getRegistrar);
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeRegistrar-1.0:registrar"); .contains("Not at element urn:ietf:params:xml:ns:rdeRegistrar-1.0:registrar");
@ -426,8 +423,7 @@ public class RdeParserTest {
@Test @Test
public void testGetNndnNotAtElement_throwsIllegalStateException() throws Exception { public void testGetNndnNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) { try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = IllegalStateException thrown = expectThrows(IllegalStateException.class, parser::getNndn);
expectThrows(IllegalStateException.class, () -> parser.getNndn());
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeNNDN-1.0:NNDN"); .contains("Not at element urn:ietf:params:xml:ns:rdeNNDN-1.0:NNDN");
@ -465,8 +461,7 @@ public class RdeParserTest {
@Test @Test
public void testGetIdnNotAtElement_throwsIllegalStateException() throws Exception { public void testGetIdnNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) { try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = IllegalStateException thrown = expectThrows(IllegalStateException.class, parser::getIdn);
expectThrows(IllegalStateException.class, () -> parser.getIdn());
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeIDN-1.0:idnTableRef"); .contains("Not at element urn:ietf:params:xml:ns:rdeIDN-1.0:idnTableRef");
@ -507,7 +502,7 @@ public class RdeParserTest {
public void testGetEppParamsNotAtElement_throwsIllegalStateException() throws Exception { public void testGetEppParamsNotAtElement_throwsIllegalStateException() throws Exception {
try (RdeParser parser = new RdeParser(xml)) { try (RdeParser parser = new RdeParser(xml)) {
IllegalStateException thrown = IllegalStateException thrown =
expectThrows(IllegalStateException.class, () -> parser.getEppParams()); expectThrows(IllegalStateException.class, parser::getEppParams);
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Not at element urn:ietf:params:xml:ns:rdeEppParams-1.0:eppParams"); .contains("Not at element urn:ietf:params:xml:ns:rdeEppParams-1.0:eppParams");

View file

@ -127,6 +127,6 @@ public class AuthModuleTest {
public void test_provideCredential_notStored() { public void test_provideCredential_notStored() {
// Doing this without the mock setup should cause us to throw an exception because the // Doing this without the mock setup should cause us to throw an exception because the
// credential has not been stored. // credential has not been stored.
assertThrows(AuthModule.LoginRequiredException.class, () -> getCredential()); assertThrows(AuthModule.LoginRequiredException.class, this::getCredential);
} }
} }

View file

@ -60,7 +60,7 @@ public class CreateContactCommandTest extends EppToolCommandTestCase<CreateConta
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
assertThrows(ParameterException.class, () -> runCommandForced()); assertThrows(ParameterException.class, this::runCommandForced);
} }
@Test @Test

View file

@ -102,7 +102,7 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
@Test @Test
public void testRun_noInputFileSpecified_throwsException() throws Exception { public void testRun_noInputFileSpecified_throwsException() throws Exception {
ParameterException thrown = expectThrows(ParameterException.class, () -> runCommand()); ParameterException thrown = expectThrows(ParameterException.class, this::runCommand);
assertThat(thrown).hasMessageThat().contains("The following option is required"); assertThat(thrown).hasMessageThat().contains("The following option is required");
} }

View file

@ -434,7 +434,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test @Test
public void testFailure_noTldName() throws Exception { public void testFailure_noTldName() throws Exception {
ParameterException thrown = expectThrows(ParameterException.class, () -> runCommandForced()); ParameterException thrown = expectThrows(ParameterException.class, this::runCommandForced);
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Main parameters are required (\"Names of the TLDs\")"); .contains("Main parameters are required (\"Names of the TLDs\")");

View file

@ -321,7 +321,7 @@ public class GenerateAuctionDataCommandTest extends CommandTestCase<GenerateAuct
@Test @Test
public void testFailure_missingTldName() throws Exception { public void testFailure_missingTldName() throws Exception {
assertThrows(ParameterException.class, () -> runCommand()); assertThrows(ParameterException.class, this::runCommand);
} }
@Test @Test

View file

@ -88,7 +88,7 @@ public class GetApplicationCommandTest extends CommandTestCase<GetApplicationCom
@Test @Test
public void testFailure_noApplicationId() throws Exception { public void testFailure_noApplicationId() throws Exception {
assertThrows(ParameterException.class, () -> runCommand()); assertThrows(ParameterException.class, this::runCommand);
} }
@Test @Test

View file

@ -78,7 +78,7 @@ public class GetApplicationIdsCommandTest extends CommandTestCase<GetApplication
@Test @Test
public void testFailure_noDomainName() throws Exception { public void testFailure_noDomainName() throws Exception {
assertThrows(ParameterException.class, () -> runCommand()); assertThrows(ParameterException.class, this::runCommand);
} }
private void persistDomainApplication(String domainName, String repoId) { private void persistDomainApplication(String domainName, String repoId) {

View file

@ -80,7 +80,7 @@ public class GetContactCommandTest extends CommandTestCase<GetContactCommand> {
@Test @Test
public void testFailure_noContact() throws Exception { public void testFailure_noContact() throws Exception {
assertThrows(ParameterException.class, () -> runCommand()); assertThrows(ParameterException.class, this::runCommand);
} }
@Test @Test

View file

@ -96,7 +96,7 @@ public class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
@Test @Test
public void testFailure_noDomainName() throws Exception { public void testFailure_noDomainName() throws Exception {
assertThrows(ParameterException.class, () -> runCommand()); assertThrows(ParameterException.class, this::runCommand);
} }
@Test @Test

View file

@ -107,6 +107,6 @@ public class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
@Test @Test
public void testFailure_noHostName() throws Exception { public void testFailure_noHostName() throws Exception {
assertThrows(ParameterException.class, () -> runCommand()); assertThrows(ParameterException.class, this::runCommand);
} }
} }

View file

@ -82,7 +82,7 @@ public class GetLrpTokenCommandTest extends CommandTestCase<GetLrpTokenCommand>
@Test @Test
public void testFailure_noArgs() throws Exception { public void testFailure_noArgs() throws Exception {
IllegalArgumentException thrown = IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> runCommand()); expectThrows(IllegalArgumentException.class, this::runCommand);
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Exactly one of either token or assignee must be specified."); .contains("Exactly one of either token or assignee must be specified.");

View file

@ -45,7 +45,7 @@ public class GetRegistrarCommandTest extends CommandTestCase<GetRegistrarCommand
@Test @Test
public void testFailure_noRegistrarName() throws Exception { public void testFailure_noRegistrarName() throws Exception {
assertThrows(ParameterException.class, () -> runCommand()); assertThrows(ParameterException.class, this::runCommand);
} }
@Test @Test

View file

@ -224,6 +224,6 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
@Test @Test
public void testFailure_noParameters() throws Exception { public void testFailure_noParameters() throws Exception {
assertThrows(ParameterException.class, () -> runCommand()); assertThrows(ParameterException.class, this::runCommand);
} }
} }

View file

@ -44,7 +44,7 @@ public class GetTldCommandTest extends CommandTestCase<GetTldCommand> {
@Test @Test
public void testFailure_noTldName() throws Exception { public void testFailure_noTldName() throws Exception {
assertThrows(ParameterException.class, () -> runCommand()); assertThrows(ParameterException.class, this::runCommand);
} }
@Test @Test

View file

@ -295,22 +295,21 @@ public class MutatingCommandTest {
stageEntityChange(null, null); stageEntityChange(null, null);
} }
}; };
assertThrows(IllegalArgumentException.class, () -> command.init()); assertThrows(IllegalArgumentException.class, command::init);
} }
@Test @Test
public void testFailure_updateSameEntityTwice() throws Exception { public void testFailure_updateSameEntityTwice() throws Exception {
MutatingCommand command = new MutatingCommand() { MutatingCommand command =
@Override new MutatingCommand() {
protected void init() { @Override
stageEntityChange(host1, newHost1); protected void init() {
stageEntityChange(host1, host1.asBuilder() stageEntityChange(host1, newHost1);
.setLastEppUpdateTime(DateTime.now(UTC)) stageEntityChange(
.build()); host1, host1.asBuilder().setLastEppUpdateTime(DateTime.now(UTC)).build());
} }
}; };
IllegalArgumentException thrown = IllegalArgumentException thrown = expectThrows(IllegalArgumentException.class, command::init);
expectThrows(IllegalArgumentException.class, () -> command.init());
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Cannot apply multiple changes for the same entity"); .contains("Cannot apply multiple changes for the same entity");
@ -324,8 +323,7 @@ public class MutatingCommandTest {
stageEntityChange(host1, host2); stageEntityChange(host1, host2);
} }
}; };
IllegalArgumentException thrown = IllegalArgumentException thrown = expectThrows(IllegalArgumentException.class, command::init);
expectThrows(IllegalArgumentException.class, () -> command.init());
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Both entity versions in an update must have the same Key."); .contains("Both entity versions in an update must have the same Key.");
@ -333,14 +331,14 @@ public class MutatingCommandTest {
@Test @Test
public void testFailure_updateDifferentStringId() throws Exception { public void testFailure_updateDifferentStringId() throws Exception {
MutatingCommand command = new MutatingCommand() { MutatingCommand command =
@Override new MutatingCommand() {
public void init() { @Override
stageEntityChange(registrar1, registrar2); public void init() {
} stageEntityChange(registrar1, registrar2);
}; }
IllegalArgumentException thrown = };
expectThrows(IllegalArgumentException.class, () -> command.init()); IllegalArgumentException thrown = expectThrows(IllegalArgumentException.class, command::init);
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Both entity versions in an update must have the same Key."); .contains("Both entity versions in an update must have the same Key.");
@ -348,14 +346,14 @@ public class MutatingCommandTest {
@Test @Test
public void testFailure_updateDifferentKind() throws Exception { public void testFailure_updateDifferentKind() throws Exception {
MutatingCommand command = new MutatingCommand() { MutatingCommand command =
@Override new MutatingCommand() {
public void init() { @Override
stageEntityChange(host1, registrar1); public void init() {
} stageEntityChange(host1, registrar1);
}; }
IllegalArgumentException thrown = };
expectThrows(IllegalArgumentException.class, () -> command.init()); IllegalArgumentException thrown = expectThrows(IllegalArgumentException.class, command::init);
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Both entity versions in an update must have the same Key."); .contains("Both entity versions in an update must have the same Key.");
@ -363,61 +361,61 @@ public class MutatingCommandTest {
@Test @Test
public void testFailure_updateModifiedEntity() throws Exception { public void testFailure_updateModifiedEntity() throws Exception {
MutatingCommand command = new MutatingCommand() { MutatingCommand command =
@Override new MutatingCommand() {
public void init() { @Override
stageEntityChange(host1, newHost1); public void init() {
} stageEntityChange(host1, newHost1);
}; }
};
command.init(); command.init();
persistResource(newHost1); persistResource(newHost1);
IllegalStateException thrown = IllegalStateException thrown = expectThrows(IllegalStateException.class, command::execute);
expectThrows(IllegalStateException.class, () -> command.execute());
assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called."); assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
} }
@Test @Test
public void testFailure_createExistingEntity() throws Exception { public void testFailure_createExistingEntity() throws Exception {
MutatingCommand command = new MutatingCommand() { MutatingCommand command =
@Override new MutatingCommand() {
protected void init() { @Override
stageEntityChange(null, newHost1); protected void init() {
} stageEntityChange(null, newHost1);
}; }
};
command.init(); command.init();
persistResource(newHost1); persistResource(newHost1);
IllegalStateException thrown = IllegalStateException thrown = expectThrows(IllegalStateException.class, command::execute);
expectThrows(IllegalStateException.class, () -> command.execute());
assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called."); assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
} }
@Test @Test
public void testFailure_deleteChangedEntity() throws Exception { public void testFailure_deleteChangedEntity() throws Exception {
MutatingCommand command = new MutatingCommand() { MutatingCommand command =
@Override new MutatingCommand() {
protected void init() { @Override
stageEntityChange(host1, null); protected void init() {
} stageEntityChange(host1, null);
}; }
};
command.init(); command.init();
persistResource(newHost1); persistResource(newHost1);
IllegalStateException thrown = IllegalStateException thrown = expectThrows(IllegalStateException.class, command::execute);
expectThrows(IllegalStateException.class, () -> command.execute());
assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called."); assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
} }
@Test @Test
public void testFailure_deleteRemovedEntity() throws Exception { public void testFailure_deleteRemovedEntity() throws Exception {
MutatingCommand command = new MutatingCommand() { MutatingCommand command =
@Override new MutatingCommand() {
protected void init() { @Override
stageEntityChange(host1, null); protected void init() {
} stageEntityChange(host1, null);
}; }
};
command.init(); command.init();
deleteResource(host1); deleteResource(host1);
IllegalStateException thrown = IllegalStateException thrown = expectThrows(IllegalStateException.class, command::execute);
expectThrows(IllegalStateException.class, () -> command.execute());
assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called."); assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
} }
} }

View file

@ -27,7 +27,7 @@ public class RegistryToolEnvironmentTest {
@Test @Test
public void testGet_withoutSetup_throws() throws Exception { public void testGet_withoutSetup_throws() throws Exception {
assertThrows(IllegalStateException.class, () -> RegistryToolEnvironment.get()); assertThrows(IllegalStateException.class, RegistryToolEnvironment::get);
} }
@Test @Test

View file

@ -736,7 +736,7 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
@Test @Test
public void testFailure_noTldName() throws Exception { public void testFailure_noTldName() throws Exception {
ParameterException thrown = expectThrows(ParameterException.class, () -> runCommandForced()); ParameterException thrown = expectThrows(ParameterException.class, this::runCommandForced);
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Main parameters are required (\"Names of the TLDs\")"); .contains("Main parameters are required (\"Names of the TLDs\")");