Search in sources :

Example 36 with MonetaryAmount

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

the class FastMoneyTest method testWithNumber.

/**
 * Test method for {@link FastMoney#getFactory()#setNumber(java.lang.Number)} .
 */
@Test
public void testWithNumber() {
    FastMoney[] moneys = new FastMoney[] { FastMoney.of(100, "CHF"), FastMoney.of(34242344, "CHF"), FastMoney.of(new BigDecimal("23123213.435"), "CHF"), FastMoney.of(new BigDecimal("-23123213.435"), "CHF"), FastMoney.of(-23123213, "CHF"), FastMoney.of(0, "CHF") };
    FastMoney s = FastMoney.of(10, "CHF");
    MonetaryAmount[] moneys2 = new MonetaryAmount[] { s.getFactory().setNumber(100).create(), s.getFactory().setNumber(34242344).create(), s.getFactory().setNumber(new BigDecimal("23123213.435")).create(), s.getFactory().setNumber(new BigDecimal("-23123213.435")).create(), s.getFactory().setNumber(-23123213).create(), s.getFactory().setNumber(0).create() };
    for (int i = 0; i < moneys.length; i++) {
        assertEquals(moneys[i], moneys2[i], "with(Number) failed.");
    }
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 37 with MonetaryAmount

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

the class FastMoneyTest method shouldRerturnMonetaryAmount.

@Test
public void shouldRerturnMonetaryAmount() {
    MonetaryAmount amount = FastMoney.ofMinor(DOLLAR, 1234L);
    assertEquals(Double.valueOf(12.34), amount.getNumber().doubleValue());
    assertEquals(DOLLAR, amount.getCurrency());
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 38 with MonetaryAmount

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

the class MonetaryOperatorsTest method testPermilNumber.

/**
 * Test method for
 * {@link org.javamoney.moneta.function.MonetaryOperators#permil(java.lang.Number)}
 * .
 */
@Test
public void testPermilNumber() {
    MonetaryAmount m = Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(100).create();
    MonetaryAmount r = m.with(MonetaryOperators.permil(25));
    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 39 with MonetaryAmount

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

the class MonetaryOperatorsTest method shouldRoudingUsingRoundingMode.

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

Example 40 with MonetaryAmount

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

the class MonetaryQueriesTest method shouldExtractMinorPart.

@Test
public void shouldExtractMinorPart() {
    MonetaryAmount money = Money.parse("EUR 2.35");
    Long result = money.query(MonetaryQueries.extractMinorPart());
    assertEquals(result, Long.valueOf(35L));
}
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