Add assertTldsExist(Iterable<String>) to check multiple TLDs at once

This is better than calling assertTldExists() inside a for loop because you can throw a single exception reporting all bad TLDs at once rather than only getting as far as the first failure.  And then it's also a one-liner instead of 3 lines.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=152412876
This commit is contained in:
nickfelt 2017-04-06 12:28:15 -07:00 committed by Ben McIlwain
parent 783033c261
commit 5081d780dc
8 changed files with 31 additions and 28 deletions

View file

@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.Sets.difference;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registries.assertTldExists;
import static google.registry.model.registry.Registries.assertTldsExist;
import static google.registry.util.TokenUtils.TokenType.LRP;
import static java.nio.charset.StandardCharsets.UTF_8;
@ -49,7 +49,7 @@ import google.registry.util.TokenUtils;
import java.io.StringReader;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Set;
import java.util.List;
import java.util.concurrent.Callable;
import javax.inject.Inject;
@ -74,7 +74,7 @@ public class CreateLrpTokensCommand implements RemoteApiCommand {
names = {"-t", "--tlds"},
description = "Comma-delimited list of TLDs that the tokens to create will be valid on",
required = true)
private String tlds;
private List<String> tlds;
@Parameter(
names = {"-i", "--input"},
@ -121,10 +121,7 @@ public class CreateLrpTokensCommand implements RemoteApiCommand {
checkArgument(
(assignee == null) || (metadataColumns == null),
"Metadata columns cannot be specified along with an assignee.");
final Set<String> validTlds = ImmutableSet.copyOf(Splitter.on(',').split(tlds));
for (String tld : validTlds) {
assertTldExists(tld);
}
ImmutableSet<String> validTlds = ImmutableSet.copyOf(assertTldsExist(tlds));
LineReader reader = new LineReader(
(assigneesFile != null)