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