@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);
  }
  @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(Float.valueOf(21), 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));
  }
예제 #3
0
 @SuppressWarnings("NullableProblems")
 @Override
 public int compareTo(NumberValue o) {
   return numberValue(BigDecimal.class).compareTo(o.numberValue(BigDecimal.class));
 }
 @Test(expectedExceptions = ArithmeticException.class)
 public void shouldReturnErrorWhenLongValueExactMustBeTruncated() {
   NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.12));
   numberValue.longValueExact();
 }
 @Test
 public void shouldReturnLongValueExact() {
   NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132));
   assertEquals(numberValue.longValueExact(), 132L);
 }
 @Test
 public void shouldReturnIntValue() {
   NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.21));
   assertEquals(numberValue.intValue(), 132);
 }
 @Test
 public void shouldReturnPrecision() {
   NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.21));
   assertEquals(numberValue.getPrecision(), 5);
 }
 @Test
 public void shouldReturnScale() {
   NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.21));
   assertEquals(numberValue.getScale(), 2);
 }
 @Test
 public void shouldReturnAmountFractionDenominatorForNegativeScale() {
   NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(10.00));
   assertEquals(1, numberValue.getAmountFractionDenominator());
 }
 @Test
 public void shouldReturnAmountFractionDenominator() {
   NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.21));
   assertEquals(100L, numberValue.getAmountFractionDenominator());
 }
 @Test
 public void shoudReturnAmountFractionNumerator() {
   NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(62.5));
   assertEquals(5L, numberValue.getAmountFractionNumerator());
   assertEquals(10L, numberValue.getAmountFractionDenominator());
 }
 @Test
 public void shouldReturnDoubleExact() {
   NumberValue numberValue = DefaultNumberValue.of(BigDecimal.valueOf(132.21));
   assertEquals(numberValue.doubleValueExact(), 132.21);
 }