Merge pull request #1344 from eugenp/money

ESG-606 - refining tests
This commit is contained in:
slavisa-baeldung 2017-03-09 14:17:00 +01:00 committed by GitHub
commit 6e00fd16d5
1 changed files with 67 additions and 82 deletions

View File

@ -134,68 +134,53 @@ public class JavaMoneyTest {
}
@Test
public void givenAmount_whenCustomFormat_thanEquals() {
MonetaryAmount oneDolar = Monetary
public void givenAmount_whenConversion_thenNotNull() {
MonetaryAmount oneDollar = Monetary
.getDefaultAmountFactory()
.setCurrency("USD")
.setNumber(1)
.create();
CurrencyConversion conversionEUR = MonetaryConversions.getConversion("EUR");
MonetaryAmount convertedAmountUSDtoEUR = oneDollar.with(conversionEUR);
assertEquals("USD 1", oneDollar.toString());
assertNotNull(convertedAmountUSDtoEUR);
}
@Test
public void givenLocale_whenFormatted_thanEquals() {
MonetaryAmount oneDollar = Monetary
.getDefaultAmountFactory()
.setCurrency("USD")
.setNumber(1)
.create();
MonetaryAmountFormat formatUSD = MonetaryFormats.getAmountFormat(Locale.US);
String usFormatted = formatUSD.format(oneDolar);
String usFormatted = formatUSD.format(oneDollar);
assertEquals("USD 1", oneDollar.toString());
assertNotNull(formatUSD);
assertEquals("USD1.00", usFormatted);
}
@Test
public void givenAmount_whenCustomFormat_thanEquals() {
MonetaryAmount oneDollar = Monetary
.getDefaultAmountFactory()
.setCurrency("USD")
.setNumber(1)
.create();
MonetaryAmountFormat customFormat = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder
.of(Locale.US)
.set(CurrencyStyle.NAME)
.set("pattern", "00000.00 ¤")
.build());
String customFormatted = customFormat.format(oneDolar);
String customFormatted = customFormat.format(oneDollar);
assertEquals("USD 1", oneDolar.toString());
assertNotNull(formatUSD);
assertNotNull(customFormat);
assertEquals("USD1.00", usFormatted);
assertEquals("USD 1", oneDollar.toString());
assertEquals("00001.00 US Dollar", customFormatted);
}
@Test
public void givenAmount_whenConversion_thenNotNull() {
CurrencyUnit USD = Monetary.getCurrency("USD");
MonetaryAmount oneDolar = Monetary
.getDefaultAmountFactory()
.setCurrency("USD")
.setNumber(1)
.create();
MonetaryAmount fstAmtEUR = Monetary
.getDefaultAmountFactory()
.setCurrency("EUR")
.setNumber(1.30473908)
.create();
CurrencyConversion convEUR = MonetaryConversions.getConversion(ConversionQueryBuilder
.of()
.setTermCurrency("EUR")
.build());
CurrencyConversion convUSD = MonetaryConversions.getConversion(ConversionQueryBuilder
.of()
.setTermCurrency(USD)
.build());
CurrencyConversion conversionUSD = MonetaryConversions.getConversion("USD");
CurrencyConversion conversionEUR = MonetaryConversions.getConversion("EUR");
MonetaryAmount convertedAmountEURtoUSD = fstAmtEUR.with(conversionUSD);
MonetaryAmount convertedAmountEURtoUSD2 = fstAmtEUR.with(convUSD);
MonetaryAmount convertedAmountUSDtoEUR = oneDolar.with(conversionEUR);
MonetaryAmount convertedAmountUSDtoEUR2 = oneDolar.with(convEUR);
assertEquals("USD", USD.toString());
assertEquals("USD 1", oneDolar.toString());
assertEquals("EUR 1.30473908", fstAmtEUR.toString());
assertNotNull(convEUR);
assertNotNull(convUSD);
assertNotNull(convertedAmountEURtoUSD);
assertNotNull(convertedAmountEURtoUSD2);
assertNotNull(convertedAmountUSDtoEUR);
assertNotNull(convertedAmountUSDtoEUR2);
}
}