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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations