Commits

Anonymous committed ea35a8b

Solved bug XW-676, XW-677 and some additional tests

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1926e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

src/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java

         try {
             if (double.class == toType || Double.class == toType) {
                 bigValue = new BigDecimal(stringValue);
-                lowerBound = BigDecimal.valueOf(Double.MIN_VALUE);
+                // Double.MIN_VALUE is the smallest positive non-zero number
+                lowerBound = BigDecimal.valueOf(Double.MAX_VALUE).negate();
                 upperBound = BigDecimal.valueOf(Double.MAX_VALUE);
             } else if (float.class == toType || Float.class == toType) {
                 bigValue = new BigDecimal(stringValue);
-                lowerBound = BigDecimal.valueOf(Float.MIN_VALUE);
+                // Float.MIN_VALUE is the smallest positive non-zero number
+                lowerBound = BigDecimal.valueOf(Float.MAX_VALUE).negate();
                 upperBound = BigDecimal.valueOf(Float.MAX_VALUE);
             } else if (byte.class == toType || Byte.class == toType) {
                 bigValue = new BigInteger(stringValue);

src/test/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverterTest.java

         assertEquals("123,99", value);
     }    
     */
+
+    public void testDoubleValues() {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+
+        assertTrue(basicConverter.isInRange(-1.2, "-1.2", Double.class));
+        assertTrue(basicConverter.isInRange(1.5, "1.5", Double.class));
+
+        Object value = basicConverter.convertValue("-1.3", double.class);
+        assertNotNull(value);
+        assertEquals(-1.3, value);
+
+        value = basicConverter.convertValue("1.8", double.class);
+        assertNotNull(value);
+        assertEquals(1.8, value);
+
+        value = basicConverter.convertValue("-1.9", double.class);
+        assertNotNull(value);
+        assertEquals(-1.9, value);
+
+        value = basicConverter.convertValue("1.7", Double.class);
+        assertNotNull(value);
+        assertEquals(1.7, value);
+    }
+
+    public void testFloatValues() {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+
+        assertTrue(basicConverter.isInRange(-1.65, "-1.65", Float.class));
+        assertTrue(basicConverter.isInRange(1.9876, "1.9876", float.class));
+
+        Float value = (Float) basicConverter.convertValue("-1.444401", Float.class);
+        assertNotNull(value);
+        assertEquals(Float.valueOf("-1.444401"), value);
+
+        value = (Float) basicConverter.convertValue("1.46464989", Float.class);
+        assertNotNull(value);
+        assertEquals(Float.valueOf(1.46464989f), value);
+    }
+
+    public void testNegativeFloatValue() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue("-94.1231233", Float.class);
+        assertTrue(convertedObject instanceof Float);
+        assertEquals(-94.1231233f, ((Float) convertedObject).floatValue(), 0.0001);
+    }
+
+    public void testPositiveFloatValue() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue("94.1231233", Float.class);
+        assertTrue(convertedObject instanceof Float);
+        assertEquals(94.1231233f, ((Float) convertedObject).floatValue(), 0.0001);
+    }
+
+
+    public void testNegativeDoubleValue() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue("-94.1231233", Double.class);
+        assertTrue(convertedObject instanceof Double);
+        assertEquals(-94.1231233d, ((Double) convertedObject).doubleValue(), 0.0001);
+    }
+
+    public void testPositiveDoubleValue() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue("94.1231233", Double.class);
+        assertTrue(convertedObject instanceof Double);
+        assertEquals(94.1231233d, ((Double) convertedObject).doubleValue(), 0.0001);
+    }
+
 }