BigDecimalConverter implements Converter<BigDecimal> { public BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { return new BigDecimal(value); } catch (NumberFormatException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } }  BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle);  }
@Test public void shouldBeAbleToConvertIntegerNumbers() { assertThat(converter.convert("2.3", BigDecimal.class, bundle), is(equalTo(new BigDecimal("2.3")))); }
@Test public void shouldComplainAboutInvalidNumber() { try { converter.convert("---", BigDecimal.class, bundle); } catch (ConversionError e) { assertThat(e.getMessage(), is(equalTo("--- is not a valid number."))); } }
@Test public void shouldNotComplainAboutNull() { assertThat(converter.convert(null, BigDecimal.class, bundle), is(nullValue())); }
@Test public void shouldNotComplainAboutEmpty() { assertThat(converter.convert("", BigDecimal.class, bundle), is(nullValue())); }