@Override public Long toNonNullValue(MonetaryAmount value) { if (!currencyUnit.equals(value.getCurrency())) { throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrency()); } return MonetaryUtil.majorPart().apply(value).getNumber().longValue(); }
AssertJUnit.assertNotNull("Section 4.2.3: Amount creation failed for " + type, result); AssertJUnit.assertEquals("Section 4.2.3: Number value (long) returned is not correct for " + type.getName(), num, result.longValue()); AssertJUnit .assertEquals("Section 4.2.3: Exact number (long) (double) returned is not correct for " + type.getName(), num,
AssertJUnit.assertTrue( "Section 4.2.2: Multiplication with 0 does not return correct value for " + type.getName(), mActualResult.getNumber().longValue() == 0);
@Override public Long toNonNullValue(MonetaryAmount value) { if (!currencyUnit.equals(value.getCurrency())) { throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrency()); } return MonetaryUtil.majorPart().apply(value).getNumber().longValue(); }
AssertJUnit.assertEquals( "Section 4.2.3: Number value (long, truncating) returned is not correct for " + num + ", type; " + type.getName(), 0L, result.longValue()); try { result.longValueExact();
/** * Check if a correct number value is returned, truncation is * allowed to be performed. Check should be done for every JDK type * supported. */ @SpecAssertion(section = "4.2.3", id = "423-B9") @Test(description = "4.2.3 Checks if a correct Number value is returned, truncation is" + " allowed to be performed. Check should be done for every JDK type.") public void testNumberValueWithTruncationNegative_Long() { Number[] nums = new Number[]{-1213243544435L, -3234, -3.5f - 1.1, -1.2d, -21323234324324.23}; for (Number num : nums) { for (Class type : Monetary.getAmountTypes()) { if (type.equals(TestAmount.class)) { continue; } MonetaryAmount mAmount1 = Monetary.getAmountFactory(type).setCurrency(DEFAULT_CURRENCY).setNumber(num).create(); NumberValue result = mAmount1.getNumber(); AssertJUnit .assertEquals("Section 4.2.3: Number value (BigDecimal -> byte) returned is not correct for " + type.getName(), new BigDecimal(String.valueOf(num)).longValue(), (long) result.numberValue(Long.class)); AssertJUnit .assertEquals("Section 4.2.3: Number value (BigDecimal -> byte) returned is not correct for " + type.getName(), new BigDecimal(String.valueOf(num)).longValue(), result.longValue()); } } }
AssertJUnit.assertNotNull("Section 4.2.3: Amount creation failed for " + type, result); AssertJUnit.assertEquals("Section 4.2.3: Number value (long) returned is not correct for " + type.getName(), num, result.longValue()); AssertJUnit.assertEquals("Section 4.2.3: Exact number (long) returned is not correct for " + type.getName(), num, result.longValueExact());
AssertJUnit.assertEquals( "Section 4.2.3: Number value (long, truncating) returned is not correct for " + num + ", type; " + type.getName(), 0L, result.longValue()); AssertJUnit.assertEquals("Section 4.2.3: Number value (long, exact) returned is not correct for " + num + ", type; " + type.getName(), 0L, result.longValue());
@Override protected Object[] toConvertedColumns(MonetaryAmount value) { return new Object[] { value.getCurrency(), MonetaryUtil.majorPart().apply(value).getNumber().longValue() }; }
@Override protected Object[] toConvertedColumns(MonetaryAmount value) { return new Object[] { value.getCurrency(), MonetaryUtil.majorPart().apply(value).getNumber().longValue() }; }
} else if (Long.class.equals(numType)) { AssertJUnit.assertEquals("Section 4.2.3: Truncating conversion to long failed for type " + type.getName(), dec.longValue(), result.longValue()); } else if (Float.class.equals(numType)) { AssertJUnit.assertEquals("Section 4.2.3: Truncating conversion to float failed for type " + type.getName(),
intNums[i], nv.intValue()); AssertJUnit.assertEquals("Section 4.2.2: getNumber().longValue() incorrect for " + type.getName(), longNums[i], nv.longValue()); AssertJUnit.assertEquals("Section 4.2.2: getNumber().doubleValue() incorrect for " + type.getName(), doubleNums[i], nv.doubleValue(), 0.0d);
AssertJUnit.assertEquals( "Section 4.2.7: MonetaryAmountFactory creates non zero amounts for " + amountType.getName(), 0L, m1.getNumber().longValue()); AssertJUnit.assertTrue( "Section 4.2.7: MonetaryAmountFactory creates non assignable amounts instances for " +