Search in sources :

Example 46 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri by JavaMoney.

the class ReciprocalOperatorTest method shouldReturnNegativeValue.

@Test
public void shouldReturnNegativeValue() {
    CurrencyUnit currency = Monetary.getCurrency("EUR");
    MonetaryAmount money = Money.parse("EUR -2.0");
    MonetaryAmount result = operator.apply(money);
    assertEquals(result.getCurrency(), currency);
    assertEquals(result.getNumber().doubleValue(), -0.5);
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 47 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri by JavaMoney.

the class ToStringMonetaryAmountFormatTest method shoudReturnToStringOnQueryFromWhenMonetaryWithFastMoney.

@Test
public void shoudReturnToStringOnQueryFromWhenMonetaryWithFastMoney() {
    MonetaryAmount money = Money.of(10, BRAZILIAN_REAL);
    String result = ToStringMonetaryAmountFormat.of(ToStringMonetaryAmountFormatStyle.FAST_MONEY).queryFrom(money);
    Assert.assertEquals(result, "BRL 10");
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 48 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri by JavaMoney.

the class ToStringMonetaryAmountFormatTest method shoudReturnToStringOnQueryFromWhenMonetaryWithRoundedMoney.

@Test
public void shoudReturnToStringOnQueryFromWhenMonetaryWithRoundedMoney() {
    MonetaryAmount money = Money.of(10, BRAZILIAN_REAL);
    String result = ToStringMonetaryAmountFormat.of(ToStringMonetaryAmountFormatStyle.ROUNDED_MONEY).queryFrom(money);
    Assert.assertEquals(result, "BRL 10");
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 49 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri by JavaMoney.

the class DefaultMonetaryAmountFormatSymbolsTest method shouldPrintMonetaryAmount.

@Test
public void shouldPrintMonetaryAmount() throws IOException {
    StringBuilder sb = new StringBuilder();
    MonetaryAmount money = Money.of(10, currency);
    monetaryAmountFormat.print(sb, money);
    String result = sb.toString();
    assertTrue(result.contains("R$"));
    assertTrue(result.contains("10,00"));
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 50 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri by JavaMoney.

the class MonetaryAmountDecimalFormatTest method shouldPrintMonetaryAmount.

@Test
public void shouldPrintMonetaryAmount() throws IOException {
    StringBuilder sb = new StringBuilder();
    MonetaryAmount money = Money.of(EXAMPLE_VALUE, currencyUnit);
    format.print(sb, money);
    assertEquals(sb.toString(), numberFormat.format(EXAMPLE_VALUE));
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Aggregations

MonetaryAmount (javax.money.MonetaryAmount)275 Test (org.testng.annotations.Test)260 CurrencyConversion (javax.money.convert.CurrencyConversion)88 BeforeTest (org.testng.annotations.BeforeTest)83 BigDecimal (java.math.BigDecimal)64 CurrencyUnit (javax.money.CurrencyUnit)57 ConversionQuery (javax.money.convert.ConversionQuery)10 RoundedMoney (org.javamoney.moneta.RoundedMoney)10 LocalDate (java.time.LocalDate)9 ExchangeRateProvider (javax.money.convert.ExchangeRateProvider)9 Test (org.junit.Test)9 FastMoney (org.javamoney.moneta.FastMoney)6 Money (org.javamoney.moneta.Money)6 MathContext (java.math.MathContext)4 MonetaryOperator (javax.money.MonetaryOperator)4 MonetaryAmountFormat (javax.money.format.MonetaryAmountFormat)4 MonetaryAmountFactory (javax.money.MonetaryAmountFactory)3 BookingBean (com.github.drbookings.model.data.BookingBean)2 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2