Search in sources :

Example 91 with MonetaryAmount

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

the class RoundedMoneyProducerTest method shouldCreateUsingRoundedMoneyImplementation.

@Test
public void shouldCreateUsingRoundedMoneyImplementation() {
    Long value = 10L;
    MonetaryAmount amount = producer.create(currency, value);
    assertTrue(RoundedMoney.class.isInstance(amount));
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) RoundedMoney(org.javamoney.moneta.RoundedMoney) Test(org.testng.annotations.Test)

Example 92 with MonetaryAmount

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

the class RoundedMoneyProducerTest method shouldCreateMonetaryAmount.

@Test
public void shouldCreateMonetaryAmount() {
    Long value = 10L;
    MonetaryAmount amount = producer.create(currency, value);
    assertEquals(amount.getCurrency(), currency);
    assertEquals(Long.valueOf(amount.getNumber().longValue()), value);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 93 with MonetaryAmount

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

the class ScaleRoundedOperatorTest method shouldRoundedMonetaryOperatorWhenTheImplementationIsMoney.

@Test
public void shouldRoundedMonetaryOperatorWhenTheImplementationIsMoney() {
    int scale = 4;
    CurrencyUnit real = Monetary.getCurrency("BRL");
    MonetaryAmount money = Money.of(BigDecimal.valueOf(35.34567), real);
    ScaleRoundedOperator monetaryOperator = ScaleRoundedOperator.of(scale, RoundingMode.HALF_EVEN);
    MonetaryAmount result = monetaryOperator.apply(money);
    assertTrue(RoundedMoney.class.isInstance(result));
    assertEquals(result.getCurrency(), real);
    assertEquals(result.getNumber().getScale(), scale);
    assertEquals(BigDecimal.valueOf(35.3457), result.getNumber().numberValue(BigDecimal.class));
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) RoundedMoney(org.javamoney.moneta.RoundedMoney) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 94 with MonetaryAmount

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

the class RoundedMoneyTest method shouldRerturnZeroWhenUsingZero.

@Test
public void shouldRerturnZeroWhenUsingZero() {
    MonetaryAmount zero = RoundedMoney.zero(DOLLAR);
    assertEquals(BigDecimal.ZERO, zero.getNumber().numberValue(BigDecimal.class));
    assertEquals(DOLLAR, zero.getCurrency());
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 95 with MonetaryAmount

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

the class RoundedMoneyTest method shouldRerturnMonetaryAmount.

@Test
public void shouldRerturnMonetaryAmount() {
    MonetaryAmount amount = RoundedMoney.ofMinor(DOLLAR, 1234L);
    assertEquals(12.34, amount.getNumber().doubleValue());
    assertEquals(DOLLAR, amount.getCurrency());
}
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