PercentageBigDecimalConverter extends BigDecimalConverter { @Override public String convertToPresentation(BigDecimal value, ValueContext context) { String result = super.convertToPresentation(value, context); return result == null ? null : result + "%"; } PercentageBigDecimalConverter(String message, int precision, boolean useGrouping); @Override String convertToPresentation(BigDecimal value, ValueContext context); @Override Result<BigDecimal> convertToModel(String value, ValueContext context);  }
@Test public void testConvertToPresentation() { BigDecimalConverter converter = new PercentageBigDecimalConverter("message", 2, false); String result = converter.convertToPresentation(BigDecimal.valueOf(3.143), new ValueContext(new Locale("nl"))); assertEquals("3,14%", result); result = converter.convertToPresentation(BigDecimal.valueOf(3000.1434), new ValueContext(new Locale("nl"))); assertEquals("3000,14%", result); converter = new PercentageBigDecimalConverter("message", 2, true); result = converter.convertToPresentation(BigDecimal.valueOf(3000.14), new ValueContext(new Locale("nl"))); assertEquals("3.000,14%", result); converter = new PercentageBigDecimalConverter("message", 2, false); result = converter.convertToPresentation(BigDecimal.valueOf(3.14), new ValueContext(Locale.US)); assertEquals("3.14%", result); converter = new PercentageBigDecimalConverter("message", 2, true); result = converter.convertToPresentation(BigDecimal.valueOf(3000.14), new ValueContext(Locale.US)); assertEquals("3,000.14%", result); assertNull(converter.convertToPresentation(null, new ValueContext(new Locale("nl")))); }