Search in sources :

Example 41 with MonetaryAmount

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

the class MonetaryQueriesTest method shouldExtractMajorPart.

@Test
public void shouldExtractMajorPart() {
    MonetaryAmount money = Money.parse("EUR 2.35");
    Long result = money.query(MonetaryQueries.extractMajorPart());
    assertEquals(result, Long.valueOf(2L));
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 42 with MonetaryAmount

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

the class MoneyProducerTest method shouldCreateUsingMoneyImplementation.

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

Example 43 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri 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 44 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri 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)

Example 45 with MonetaryAmount

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

the class PrecisionScaleRoundedOperatorTest method shouldRoundedMonetaryOperatorWhenTheImplementationIsMoney.

@Test
public void shouldRoundedMonetaryOperatorWhenTheImplementationIsMoney() {
    int scale = 3;
    int precision = 5;
    CurrencyUnit real = Monetary.getCurrency("BRL");
    BigDecimal valueOf = BigDecimal.valueOf(35.34567);
    MonetaryAmount money = Money.of(valueOf, real);
    MathContext mathContext = new MathContext(precision, RoundingMode.HALF_EVEN);
    PrecisionScaleRoundedOperator monetaryOperator = PrecisionScaleRoundedOperator.of(scale, mathContext);
    MonetaryAmount result = monetaryOperator.apply(money);
    assertTrue(RoundedMoney.class.isInstance(result));
    assertEquals(result.getCurrency(), real);
    assertEquals(result.getNumber().getScale(), scale);
    assertEquals(result.getNumber().getPrecision(), precision);
    assertEquals(BigDecimal.valueOf(35.346), result.getNumber().numberValue(BigDecimal.class));
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) RoundedMoney(org.javamoney.moneta.RoundedMoney) BigDecimal(java.math.BigDecimal) MathContext(java.math.MathContext) 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