mirror of
https://github.com/google/nomulus
synced 2026-09-08 17:17:02 +00:00
Don't throw errors when existing premium list is empty (#1479)
* Don't throw errors when existing premium list is empty This state is possible to get into when things go wrong and it shouldn't prevent saving new revisions of the list. Note that it will continue to throw errors if you attempt to save a new revision that is blank (which is usually a mistake). See http://b/211774375
This commit is contained in:
@@ -22,6 +22,7 @@ import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static org.joda.money.CurrencyUnit.JPY;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
import static org.joda.time.Duration.standardDays;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@@ -239,6 +240,15 @@ public class PremiumListDaoTest {
|
||||
.hasValue(moneyOf(JPY, 15000));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSave_throwsOnEmptyInputData() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> PremiumListDao.save("test-list", CurrencyUnit.GBP, ImmutableList.of()));
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("New premium list data cannot be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_savePremiumList_clearsCache() {
|
||||
assertThat(PremiumListDao.premiumListCache.getIfPresent("testname")).isNull();
|
||||
|
||||
@@ -84,6 +84,27 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
|
||||
assertThat(entries.contains("eth,USD 9999.00")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void commandRun_successUpdateList_whenExistingListIsEmpty() throws Exception {
|
||||
File existingPremiumFile = tmpDir.resolve(TLD_TEST + ".txt").toFile();
|
||||
Files.asCharSink(existingPremiumFile, UTF_8).write("");
|
||||
|
||||
File newPremiumFile = tmpDir.resolve(String.format("%s.txt", TLD_TEST)).toFile();
|
||||
String newPremiumListData = "eth,USD 9999";
|
||||
Files.asCharSink(newPremiumFile, UTF_8).write(newPremiumListData);
|
||||
|
||||
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
|
||||
// data come from @beforeEach of CreateOrUpdatePremiumListCommandTestCase.java
|
||||
command.inputFile = Paths.get(newPremiumFile.getPath());
|
||||
runCommandForced("--name=" + TLD_TEST, "--input=" + command.inputFile);
|
||||
|
||||
ImmutableSet<String> entries =
|
||||
command.getExistingPremiumEntry(PremiumListDao.getLatestRevision(TLD_TEST).get());
|
||||
assertThat(entries.size()).isEqualTo(1);
|
||||
// verify that list is updated; cannot use only string since price is formatted;
|
||||
assertThat(entries.contains("eth,USD 9999.00")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void commandRun_successUpdateMultiLineList() throws Exception {
|
||||
File tmpFile = tmpDir.resolve(TLD_TEST + ".txt").toFile();
|
||||
@@ -112,7 +133,7 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
|
||||
command.inputFile = tmpPath;
|
||||
command.name = TLD_TEST;
|
||||
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
|
||||
assertThat(thrown).hasMessageThat().contains("Input cannot be empty");
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("New premium list data cannot be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user