mirror of
https://github.com/google/nomulus.git
synced 2025-07-09 04:33:28 +02:00
Fix money conversion for JPY in PremiumListDao (#463)
This commit is contained in:
parent
d03cea2443
commit
955c3d9aeb
2 changed files with 39 additions and 1 deletions
|
@ -156,7 +156,11 @@ public class PremiumListDao {
|
|||
RevisionIdAndLabel.create(premiumList.getRevisionId(), label);
|
||||
try {
|
||||
Optional<BigDecimal> 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(
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue