/** * Check if a correct double 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 double value is returned, truncation is" + " allowed to be performed. Check should be done for every JDK type.") public void testNumberValueWithTruncationNegative_Float() { 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 -> float) returned is not correct for " + type.getName(), new BigDecimal(String.valueOf(num)).floatValue(), result.numberValue(Float.class).floatValue(), 0.0f); AssertJUnit.assertEquals( "Section 4.2.3: Number value (BigDecimal -> float) returned is not correct for " + type.getName(), new BigDecimal(String.valueOf(num)).floatValue(), result.floatValue(), 0.0f); } } }
} else if (Float.class.equals(numType)) { AssertJUnit.assertEquals("Section 4.2.3: Truncating conversion to float failed for type " + type.getName(), dec.floatValue(), result.floatValue(), 0.0f); } else if (Double.class.equals(numType)) { AssertJUnit.assertEquals("Section 4.2.3: Truncating conversion to double failed for type " + type.getName(),
doubleNums[i], nv.doubleValue(), 0.0d); AssertJUnit.assertEquals("Section 4.2.2: getNumber().floatValue() incorrect for " + type.getName(), floatNums[i], nv.floatValue(), 0.0d);