Search in sources :

Example 21 with NumberValue

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

the class DefaultNumberValueTest method shouldReturnAmountFractionDenominator.

@Test
public void shouldReturnAmountFractionDenominator() {
    NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.21));
    assertEquals(100L, numberValue.getAmountFractionDenominator());
}
Also used : NumberValue(javax.money.NumberValue) Test(org.testng.annotations.Test)

Example 22 with NumberValue

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

the class DefaultNumberValueTest method shouldReturnScale.

@Test
public void shouldReturnScale() {
    NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.21));
    assertEquals(numberValue.getScale(), 2);
}
Also used : NumberValue(javax.money.NumberValue) Test(org.testng.annotations.Test)

Example 23 with NumberValue

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

the class DefaultNumberValueTest method shouldReturnLong.

@Test
public void shouldReturnLong() {
    NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.21));
    assertEquals(numberValue.longValue(), 132L);
}
Also used : NumberValue(javax.money.NumberValue) Test(org.testng.annotations.Test)

Example 24 with NumberValue

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

the class DefaultNumberValueTest method shouldReturnAmountFractionDenominatorForNegativeScale.

@Test
public void shouldReturnAmountFractionDenominatorForNegativeScale() {
    NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(10.00));
    assertEquals(1, numberValue.getAmountFractionDenominator());
}
Also used : NumberValue(javax.money.NumberValue) Test(org.testng.annotations.Test)

Example 25 with NumberValue

use of javax.money.NumberValue in project jsr354-ri 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(Float.valueOf(21), 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));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) NumberValue(javax.money.NumberValue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

NumberValue (javax.money.NumberValue)40 Test (org.testng.annotations.Test)36 BigDecimal (java.math.BigDecimal)6 BigInteger (java.math.BigInteger)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 CurrencyConversionException (javax.money.convert.CurrencyConversionException)2 ExchangeRate (javax.money.convert.ExchangeRate)2