Search in sources :

Example 76 with MonetaryAmount

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

the class MonetaryOperatorsTest method shouldRoudingUsingRoundingModeAndScale.

@Test
public void shouldRoudingUsingRoundingModeAndScale() {
    CurrencyUnit euro = Monetary.getCurrency("EUR");
    MonetaryAmount money = Money.parse("EUR 2.355432");
    MonetaryAmount result = MonetaryOperators.rounding(RoundingMode.HALF_EVEN, 4).apply(money);
    assertNotNull(result);
    assertEquals(result.getCurrency(), euro);
    assertEquals(Double.valueOf(2.3554), result.getNumber().doubleValue());
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 77 with MonetaryAmount

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

the class ExtractorMinorPartQueryTest method shouldReturnMajorPartNegative.

@Test
public void shouldReturnMajorPartNegative() {
    MonetaryAmount monetaryAmount = Money.parse("BHD -1.345");
    Long result = query.queryFrom(monetaryAmount);
    Long expected = -345L;
    assertEquals(result, expected);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 78 with MonetaryAmount

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

the class MonetaryOperatorsTest method testPermilNumberMathContext.

/**
 * Test method for
 * {@link org.javamoney.moneta.function.MonetaryOperators#permil(java.lang.Number, java.math.MathContext)}
 * .
 */
@Test
public void testPermilNumberMathContext() {
    MonetaryAmount m = Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(100).create();
    MonetaryAmount r = m.with(MonetaryOperators.permil(25, MathContext.DECIMAL64));
    assertEquals(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("2.5")).create(), r);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 79 with MonetaryAmount

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

the class MonetaryOperatorsTest method shouldReturnErrorWhenRoundingTypeIsNull.

@Test(expectedExceptions = NullPointerException.class)
public void shouldReturnErrorWhenRoundingTypeIsNull() {
    MonetaryAmount money = Money.parse("EUR 2.355432");
    MonetaryOperators.rounding(null).apply(money);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 80 with MonetaryAmount

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

the class MonetaryOperatorsTest method testReciprocal.

/**
 * Test method for
 * {@link org.javamoney.moneta.function.MonetaryOperators#reciprocal()}.
 */
@Test
public void testReciprocal() {
    MonetaryAmount m = Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(200).create();
    MonetaryAmount r = m.with(MonetaryOperators.reciprocal());
    // noinspection BigDecimalMethodWithoutRoundingCalled
    assertEquals(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(BigDecimal.ONE.divide(BigDecimal.valueOf(200))).create(), r);
}
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