diff --git a/core/src/main/java/google/registry/tools/UpdatePremiumListCommand.java b/core/src/main/java/google/registry/tools/UpdatePremiumListCommand.java index cd5622d84..0c11bccb4 100644 --- a/core/src/main/java/google/registry/tools/UpdatePremiumListCommand.java +++ b/core/src/main/java/google/registry/tools/UpdatePremiumListCommand.java @@ -24,7 +24,6 @@ import google.registry.model.tld.label.PremiumList; import google.registry.model.tld.label.PremiumListDao; import google.registry.model.tld.label.PremiumListUtils; import java.nio.file.Files; -import java.util.Optional; /** Command to safely update {@link PremiumList} in Database for a given TLD. */ @Parameters(separators = " =", commandDescription = "Update a PremiumList in Database.") @@ -33,16 +32,19 @@ class UpdatePremiumListCommand extends CreateOrUpdatePremiumListCommand { @Override protected String prompt() throws Exception { name = Strings.isNullOrEmpty(name) ? convertFilePathToName(inputFile) : name; - Optional list = PremiumListDao.getLatestRevision(name); - checkArgument( - list.isPresent(), - String.format("Could not update premium list %s because it doesn't exist.", name)); + PremiumList existingList = + PremiumListDao.getLatestRevision(name) + .orElseThrow( + () -> + new IllegalArgumentException( + String.format( + "Could not update premium list %s because it doesn't exist", name))); inputData = Files.readAllLines(inputFile, UTF_8); checkArgument(!inputData.isEmpty(), "New premium list data cannot be empty"); - currency = list.get().getCurrency(); + currency = existingList.getCurrency(); PremiumList updatedPremiumList = PremiumListUtils.parseToPremiumList(name, currency, inputData); return String.format( "Update premium list for %s?\n Old List: %s\n New List: %s", - name, list, updatedPremiumList); + name, existingList, updatedPremiumList); } } diff --git a/core/src/test/java/google/registry/tools/UpdatePremiumListCommandTest.java b/core/src/test/java/google/registry/tools/UpdatePremiumListCommandTest.java index 212ec6eab..8a8e653fe 100644 --- a/core/src/test/java/google/registry/tools/UpdatePremiumListCommandTest.java +++ b/core/src/test/java/google/registry/tools/UpdatePremiumListCommandTest.java @@ -134,15 +134,13 @@ class UpdatePremiumListCommandTest @Test void commandPrompt_failureNoPreviousVersion() { - String fileName = "random"; - registry = createTld(fileName, null, null); + registry = createTld("random", null, null); UpdatePremiumListCommand command = new UpdatePremiumListCommand(); - command.name = fileName; + command.name = "random"; IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt); assertThat(thrown) .hasMessageThat() - .isEqualTo( - String.format("Could not update premium list %s because it doesn't exist.", fileName)); + .isEqualTo("Could not update premium list random because it doesn't exist"); } @Test @@ -153,27 +151,22 @@ class UpdatePremiumListCommandTest @Test void commandPrompt_failureTldFromNameDoesNotExist() { - String fileName = "random"; UpdatePremiumListCommand command = new UpdatePremiumListCommand(); - command.name = fileName; + command.name = "random2"; IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt); assertThat(thrown) .hasMessageThat() - .isEqualTo( - String.format("Could not update premium list %s because it doesn't exist.", fileName)); + .isEqualTo("Could not update premium list random2 because it doesn't exist"); } @Test void commandPrompt_failureTldFromInputFileDoesNotExist() { - String fileName = "random"; UpdatePremiumListCommand command = new UpdatePremiumListCommand(); // using tld extracted from file name but this tld is not part of the registry - command.inputFile = - Paths.get(tmpDir.resolve(String.format("%s.txt", fileName)).toFile().getPath()); + command.inputFile = Paths.get(tmpDir.resolve("random3.txt").toFile().getPath()); IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt); assertThat(thrown) .hasMessageThat() - .isEqualTo( - String.format("Could not update premium list %s because it doesn't exist.", fileName)); + .isEqualTo("Could not update premium list random3 because it doesn't exist"); } }