Search in sources :

Example 1 with NumberValue

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

the class DefaultNumberValueTest method shouldReturnErrorWhenLongValueExactMustBeTruncated.

@Test(expectedExceptions = ArithmeticException.class)
public void shouldReturnErrorWhenLongValueExactMustBeTruncated() {
    NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.12));
    numberValue.longValueExact();
}
Also used : NumberValue(javax.money.NumberValue) Test(org.testng.annotations.Test)

Example 2 with NumberValue

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

the class DefaultNumberValueTest method shouldReturnNumberType.

@Test
public void shouldReturnNumberType() {
    NumberValue numberValueLong = DefaultNumberValue.of(10L);
    NumberValue numberValueInteger = DefaultNumberValue.of(10);
    NumberValue numberValueDouble = DefaultNumberValue.of(10D);
    NumberValue numberValueBigDecimal = DefaultNumberValue.of(BigDecimal.TEN);
    NumberValue numberValueBigInteger = DefaultNumberValue.of(BigInteger.TEN);
    assertEquals(numberValueLong.getNumberType(), Long.class);
    assertEquals(numberValueInteger.getNumberType(), Integer.class);
    assertEquals(numberValueDouble.getNumberType(), Double.class);
    assertEquals(numberValueBigDecimal.getNumberType(), BigDecimal.class);
    assertEquals(numberValueBigInteger.getNumberType(), BigInteger.class);
}
Also used : NumberValue(javax.money.NumberValue) Test(org.testng.annotations.Test)

Example 3 with NumberValue

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

the class DefaultNumberValueTest method shouldReturnErrorWhenIntValueExactMustBeTruncated.

@Test(expectedExceptions = ArithmeticException.class)
public void shouldReturnErrorWhenIntValueExactMustBeTruncated() {
    NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.12));
    numberValue.intValueExact();
}
Also used : NumberValue(javax.money.NumberValue) Test(org.testng.annotations.Test)

Example 4 with NumberValue

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

the class DefaultNumberValueTest method shouldReturnIntValue.

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

Example 5 with NumberValue

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

the class DefaultNumberValueTest method shoudReturnAmountFractionNumerator.

@Test
public void shoudReturnAmountFractionNumerator() {
    NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(62.5));
    assertEquals(5L, numberValue.getAmountFractionNumerator());
    assertEquals(10L, numberValue.getAmountFractionDenominator());
}
Also used : NumberValue(javax.money.NumberValue) 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