Search in sources :

Example 81 with MonetaryAmount

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

the class MonetaryOperatorsTest method shouldRouding.

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

Example 82 with MonetaryAmount

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

the class MonetaryOperatorsTest method testMajorPart.

/**
 * Test method for
 * {@link org.javamoney.moneta.function.MonetaryOperators#majorPart()}.
 */
@Test
public void testMajorPart() {
    MonetaryAmount m = Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("1234.56789")).create();
    MonetaryAmount r = m.with(MonetaryOperators.majorPart());
    assertEquals(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("1234")).create(), r);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 83 with MonetaryAmount

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

the class PercentOperatorTest method shouldReturnNegativeValue.

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

Example 84 with MonetaryAmount

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

the class PercentOperatorTest method shouldReturnPositiveValue.

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

Example 85 with MonetaryAmount

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

the class PermilOperatorTest method shouldReturnNegativeValue.

@Test
public void shouldReturnNegativeValue() {
    CurrencyUnit currency = Monetary.getCurrency("EUR");
    MonetaryAmount money = Money.parse("EUR -2.35");
    MonetaryAmount result = operator.apply(money);
    assertEquals(result.getCurrency(), currency);
    assertEquals(result.getNumber().doubleValue(), -0.0235);
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) 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