DoubleValueConverter extends AbstractValueConverter<Double> { @Override public Double convert(String s) { try { return Double.valueOf(s.replace(',', '.')); } catch (RuntimeException e) { throw new IllegalArgumentException("Can't convert '" + s + "' to Double.", e); } } private  DoubleValueConverter(); @Override Double convert(String s); @Override String toString(Double value); static final ValueConverter<Double> INSTANCE; }
@Test public void testConvert() throws Exception { assertEquals(3.1415, converter.convert(Double.toString(3.1415)), 0); }
@Test public void testConvertDot() throws Exception { assertEquals(3.1415, converter.convert("3.1415"), 0); }
@Test public void testConvertComma() throws Exception { assertEquals(3.1415, converter.convert("3,1415"), 0); }
@Test(expected = IllegalArgumentException.class) public void testConvertNull() throws Exception { converter.convert(null); }
@Test(expected = IllegalArgumentException.class) public void testConvertInvalidTrue() throws Exception { converter.convert("one"); }