diff --git a/core/src/main/java/google/registry/schema/tld/PremiumListDao.java b/core/src/main/java/google/registry/schema/tld/PremiumListDao.java index 0e2e3d58b..76830d9f8 100644 --- a/core/src/main/java/google/registry/schema/tld/PremiumListDao.java +++ b/core/src/main/java/google/registry/schema/tld/PremiumListDao.java @@ -156,7 +156,11 @@ public class PremiumListDao { RevisionIdAndLabel.create(premiumList.getRevisionId(), label); try { Optional price = PremiumListCache.cachePremiumEntries.get(revisionIdAndLabel); - return price.map(p -> Money.of(premiumList.getCurrency(), p)); + return price.map( + p -> + Money.of( + premiumList.getCurrency(), + p.setScale(premiumList.getCurrency().getDecimalPlaces()))); } catch (InvalidCacheLoadException | ExecutionException e) { throw new RuntimeException( String.format( diff --git a/core/src/test/java/google/registry/schema/tld/PremiumListDaoTest.java b/core/src/test/java/google/registry/schema/tld/PremiumListDaoTest.java index 2b74d842d..ff9fdc34b 100644 --- a/core/src/test/java/google/registry/schema/tld/PremiumListDaoTest.java +++ b/core/src/test/java/google/registry/schema/tld/PremiumListDaoTest.java @@ -202,4 +202,38 @@ public class PremiumListDaoTest { () -> PremiumListDao.getPremiumPrice("foobar", Registry.get("tld"))); assertThat(thrown).hasMessageThat().isEqualTo("Could not load premium list 'tld'"); } + + @Test + public void testGetPremiumPrice_worksForJPY() { + persistResource( + newRegistry("foobar", "FOOBAR") + .asBuilder() + .setPremiumListKey( + Key.create( + getCrossTldKey(), + google.registry.model.registry.label.PremiumList.class, + "premlist")) + .build()); + PremiumListDao.saveNew( + PremiumList.create( + "premlist", + JPY, + ImmutableMap.of( + "silver", + BigDecimal.valueOf(10.00), + "gold", + BigDecimal.valueOf(1000.0), + "palladium", + BigDecimal.valueOf(15000)))); + assertThat(PremiumListDao.getPremiumPrice("silver", Registry.get("foobar"))) + .hasValue(moneyOf(JPY, 10)); + assertThat(PremiumListDao.getPremiumPrice("gold", Registry.get("foobar"))) + .hasValue(moneyOf(JPY, 1000)); + assertThat(PremiumListDao.getPremiumPrice("palladium", Registry.get("foobar"))) + .hasValue(moneyOf(JPY, 15000)); + } + + private static Money moneyOf(CurrencyUnit unit, double amount) { + return Money.of(unit, BigDecimal.valueOf(amount).setScale(unit.getDecimalPlaces())); + } }