DefaultTransformer implements NumberTransformer, Serializable { public double transform(Object o) throws NullArgumentException, MathIllegalArgumentException { if (o == null) { throw new NullArgumentException(LocalizedFormats.OBJECT_TRANSFORMATION); } if (o instanceof Number) { return ((Number)o).doubleValue(); } try { return Double.parseDouble(o.toString()); } catch (NumberFormatException e) { throw new MathIllegalArgumentException(LocalizedFormats.CANNOT_TRANSFORM_TO_DOUBLE, o.toString()); } }  double transform(Object o); @Override boolean equals(Object other); @Override int hashCode();  }
@Test public void testTransformDouble() throws Exception { double expected = 1.0; Double input = Double.valueOf(expected); DefaultTransformer t = new DefaultTransformer(); Assert.assertEquals(expected, t.transform(input), 1.0e-4); }
@Test public void testTransformNull() throws Exception { DefaultTransformer t = new DefaultTransformer(); try { t.transform(null); Assert.fail("Expecting NullArgumentException"); } catch (NullArgumentException e) { } }
@Test public void testTransformInteger() throws Exception { double expected = 1.0; Integer input = Integer.valueOf(1); DefaultTransformer t = new DefaultTransformer(); Assert.assertEquals(expected, t.transform(input), 1.0e-4); }
@Test public void testTransformBigDecimal() throws Exception { double expected = 1.0; BigDecimal input = new BigDecimal("1.0"); DefaultTransformer t = new DefaultTransformer(); Assert.assertEquals(expected, t.transform(input), 1.0e-4); }
@Test public void testTransformString() throws Exception { double expected = 1.0; String input = "1.0"; DefaultTransformer t = new DefaultTransformer(); Assert.assertEquals(expected, t.transform(input), 1.0e-4); }
@Test(expected=MathIllegalArgumentException.class) public void testTransformObject(){ Boolean input = Boolean.TRUE; DefaultTransformer t = new DefaultTransformer(); t.transform(input); }