[CONFIGURATION-766] BigDecimal(double) should not be used.
- Add a test to document current behavior.
- Add an ignored test from CONFIGURATION-766.
diff --git a/src/test/java/org/apache/commons/configuration2/convert/TestPropertyConverter.java b/src/test/java/org/apache/commons/configuration2/convert/TestPropertyConverter.java
index a76daf4..51104af 100644
--- a/src/test/java/org/apache/commons/configuration2/convert/TestPropertyConverter.java
+++ b/src/test/java/org/apache/commons/configuration2/convert/TestPropertyConverter.java
@@ -28,6 +28,7 @@
import java.util.regex.Pattern;
import org.apache.commons.configuration2.ex.ConversionException;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -40,6 +41,35 @@
private static final Class<ElementType> ENUM_CLASS = ElementType.class;
/**
+ * See CONFIGURATION-766.
+ */
+ @Test
+ @Ignore
+ public void testToBigDecimalStringConstructor()
+ {
+ // If the conversion uses new BigDecimal(0.1) the result is not exact due to round off.
+ // The result is 0.1000000000000000055511151231257827021181583404541015625.
+ // See Sonar rule: https://rules.sonarsource.com/java/type/Bug/RSPEC-2111
+ final double d = 0.1;
+ assertEquals("Incorrect BigDecimal value", new BigDecimal(Double.toString(d)),
+ PropertyConverter.toBigDecimal(d));
+ }
+
+ /**
+ * See CONFIGURATION-766.
+ */
+ @Test
+ public void testToBigDecimalDoubleConstructor()
+ {
+ // If the conversion uses new BigDecimal(0.1) the result is not exact due to round off.
+ // The result is 0.1000000000000000055511151231257827021181583404541015625.
+ // See Sonar rule: https://rules.sonarsource.com/java/type/Bug/RSPEC-2111
+ final double d = 0.1;
+ assertEquals("Incorrect BigDecimal value", new BigDecimal(d),
+ PropertyConverter.toBigDecimal(d));
+ }
+
+ /**
* Tests conversion to files when the passed in objects are already
* files.
*/
@@ -305,4 +335,5 @@
new DefaultConversionHandler());
assertEquals("Wrong resulting string", "42", result);
}
+
}