use of javax.money.NumberValue in project jsr354-ri-bp by JavaMoney.
the class DefaultNumberValueTest method shouldReturnDoubleExact.
@Test
public void shouldReturnDoubleExact() {
NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.21));
assertEquals(numberValue.doubleValueExact(), 132.21);
}
use of javax.money.NumberValue in project jsr354-ri-bp by JavaMoney.
the class DefaultNumberValueTest method shouldReturnLong.
@Test
public void shouldReturnLong() {
NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.21));
assertEquals(numberValue.longValue(), 132L);
}
use of javax.money.NumberValue in project jsr354-ri-bp by JavaMoney.
the class DefaultNumberValueTest method shouldReturnNumberValue.
@Test
public void shouldReturnNumberValue() {
NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(21));
assertEquals(Long.valueOf(21L), numberValue.numberValue(Long.class));
assertEquals(Integer.valueOf(21), numberValue.numberValue(Integer.class));
assertEquals(21f, numberValue.numberValue(Float.class));
assertEquals(Byte.valueOf((byte) 21), numberValue.numberValue(Byte.class));
assertEquals(Short.valueOf((short) 21), numberValue.numberValue(Short.class));
assertEquals(new AtomicLong(21L).get(), numberValue.numberValue(AtomicLong.class).get());
assertEquals(new AtomicInteger(21).get(), numberValue.numberValue(AtomicInteger.class).get());
assertEquals(BigDecimal.valueOf(21L), numberValue.numberValue(BigDecimal.class));
assertEquals(BigInteger.valueOf(21L), numberValue.numberValue(BigInteger.class));
}
use of javax.money.NumberValue in project jsr354-ri-bp by JavaMoney.
the class DefaultNumberValueTest method shouldReturnAmountFractionDenominatorForNegativeScale.
@Test
public void shouldReturnAmountFractionDenominatorForNegativeScale() {
NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(10.00));
assertEquals(1, numberValue.getAmountFractionDenominator());
}
use of javax.money.NumberValue in project jsr354-ri-bp by JavaMoney.
the class DefaultNumberValueTest method shouldReturnNumberValueExact.
@Test
public void shouldReturnNumberValueExact() {
NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(21));
assertEquals(Long.valueOf(21L), numberValue.numberValueExact(Long.class));
assertEquals(Integer.valueOf(21), numberValue.numberValueExact(Integer.class));
assertEquals(21f, numberValue.numberValueExact(Float.class));
assertEquals(Byte.valueOf((byte) 21), numberValue.numberValueExact(Byte.class));
assertEquals(Short.valueOf((short) 21), numberValue.numberValueExact(Short.class));
assertEquals(new AtomicLong(21L).get(), numberValue.numberValueExact(AtomicLong.class).get());
assertEquals(new AtomicInteger(21).get(), numberValue.numberValueExact(AtomicInteger.class).get());
assertEquals(BigDecimal.valueOf(21L), numberValue.numberValueExact(BigDecimal.class));
assertEquals(BigInteger.valueOf(21L), numberValue.numberValueExact(BigInteger.class));
}
Aggregations