Search in sources :

Example 36 with NumberValue

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);
}
Also used : NumberValue(javax.money.NumberValue) Test(org.testng.annotations.Test)

Example 37 with NumberValue

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);
}
Also used : NumberValue(javax.money.NumberValue) Test(org.testng.annotations.Test)

Example 38 with NumberValue

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

Example 39 with NumberValue

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());
}
Also used : NumberValue(javax.money.NumberValue) Test(org.testng.annotations.Test)

Example 40 with NumberValue

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