use of javax.money.MonetaryOperator in project jsr354-ri-bp by JavaMoney.
the class FastMoneyTest method testWithMonetaryOperator.
/**
* Test method for {@link FastMoney#with(javax.money.MonetaryOperator)} .
*/
@Test
public void testWithMonetaryOperator() {
MonetaryOperator adj = new MonetaryOperator() {
@Override
public MonetaryAmount apply(MonetaryAmount amount) {
return FastMoney.of(-100, amount.getCurrency());
}
};
FastMoney m = FastMoney.of(new BigDecimal("1.2345"), "XXX");
FastMoney a = m.with(adj);
assertNotNull(a);
assertNotSame(m, a);
assertEquals(m.getCurrency(), a.getCurrency());
assertEquals(FastMoney.of(-100, m.getCurrency()), a);
adj = new MonetaryOperator() {
@Override
public MonetaryAmount apply(MonetaryAmount amount) {
return amount.multiply(2).getFactory().setCurrency(Monetary.getCurrency("CHF")).create();
}
};
a = m.with(adj);
assertNotNull(a);
assertNotSame(m, a);
assertEquals(Monetary.getCurrency("CHF"), a.getCurrency());
assertEquals(FastMoney.of(1.2345 * 2, a.getCurrency()), a);
}
use of javax.money.MonetaryOperator in project jsr354-ri-bp by JavaMoney.
the class DefaultMonetaryRoundedFactoryTest method shouldReturnGetRoudingOperator.
@Test
public void shouldReturnGetRoudingOperator() {
MonetaryOperator roundingOperator = factory.getRoundingOperator();
assertEquals(identical, roundingOperator);
}
use of javax.money.MonetaryOperator in project jsr354-ri by JavaMoney.
the class MonetaryRoundedFactoryBuilderTest method shouldReturnMathContextOperator.
@Test
public void shouldReturnMathContextOperator() {
int precision = 6;
RoundingMode roundingMode = RoundingMode.HALF_EVEN;
MonetaryRoundedFactory factory = MonetaryRoundedFactory.withRoundingMode(roundingMode).withPrecision(precision).build();
assertNotNull(factory);
MonetaryOperator roundingOperator = factory.getRoundingOperator();
assertNotNull(roundingOperator);
assertTrue(PrecisionContextRoundedOperator.class.isInstance(roundingOperator));
MathContext result = PrecisionContextRoundedOperator.class.cast(roundingOperator).getMathContext();
assertEquals(precision, result.getPrecision());
assertEquals(roundingMode, result.getRoundingMode());
}
use of javax.money.MonetaryOperator in project jsr354-ri by JavaMoney.
the class MonetaryRoundedFactoryBuilderTest method shouldReturnMathContextScaleOperator.
@Test
public void shouldReturnMathContextScaleOperator() {
int precision = 6;
int scale = 3;
RoundingMode roundingMode = RoundingMode.HALF_EVEN;
MonetaryRoundedFactory factory = MonetaryRoundedFactory.withRoundingMode(roundingMode).withPrecision(precision).withScale(scale).build();
assertNotNull(factory);
MonetaryOperator roundingOperator = factory.getRoundingOperator();
assertNotNull(roundingOperator);
assertTrue(PrecisionScaleRoundedOperator.class.isInstance(roundingOperator));
PrecisionScaleRoundedOperator result = PrecisionScaleRoundedOperator.class.cast(roundingOperator);
assertEquals(precision, result.getMathContext().getPrecision());
assertEquals(scale, result.getScale());
assertEquals(roundingMode, result.getMathContext().getRoundingMode());
}
use of javax.money.MonetaryOperator in project jsr354-ri by JavaMoney.
the class MonetaryRoundedFactoryBuilderTest method shouldReturnScaleRoundingOperator.
@Test
public void shouldReturnScaleRoundingOperator() {
int scale = 6;
RoundingMode roundingMode = RoundingMode.HALF_EVEN;
MonetaryRoundedFactory factory = MonetaryRoundedFactory.withRoundingMode(roundingMode).withScale(scale).build();
assertNotNull(factory);
MonetaryOperator roundingOperator = factory.getRoundingOperator();
assertNotNull(roundingOperator);
assertTrue(ScaleRoundedOperator.class.isInstance(roundingOperator));
ScaleRoundedOperator result = ScaleRoundedOperator.class.cast(roundingOperator);
assertEquals(scale, result.getScale());
assertEquals(roundingMode, result.getRoundingMode());
}
Aggregations