PrimitiveDoubleConverter implements Converter<Double> { public Double convert(String value, Class<? extends Double> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return 0d; } try { return Double.parseDouble(value); } catch (NumberFormatException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } }  Double convert(String value, Class<? extends Double> type, ResourceBundle bundle);  }
@Test public void shouldBeAbleToConvertNumbers() { assertThat((Double) converter.convert("2.3", double.class, bundle), is(equalTo(2.3d))); }
@Test public void shouldComplainAboutInvalidNumber() { try { converter.convert("---", double.class, bundle); } catch (ConversionError e) { assertThat(e.getMessage(), is(equalTo("--- is not a valid number."))); } }
@Test public void shouldConvertToZeroWhenNull() { assertThat((Double) converter.convert(null, double.class, bundle), is(equalTo(0D))); }
@Test public void shouldConvertToZeroWhenEmpty() { assertThat((Double) converter.convert("", double.class, bundle), is(equalTo(0D))); }