PercentageIntegerConverter extends GroupingStringToIntegerConverter { @Override public Result<Integer> convertToModel(String value, ValueContext context) { value = value == null ? null : value.replace("%", ""); return super.convertToModel(value, context); } PercentageIntegerConverter(String message, boolean useGrouping); @Override String convertToPresentation(Integer value, ValueContext context); @Override Result<Integer> convertToModel(String value, ValueContext context);  }
@Test public void testConvertToModel() { PercentageIntegerConverter cv = new PercentageIntegerConverter("message", true); assertNull(cv.convertToModel(null, createContext()).getOrThrow(r -> new OCSRuntimeException())); Result<Integer> result = cv.convertToModel("4%", createContext()); assertEquals(4L, result.getOrThrow(r -> new OCSRuntimeException()).longValue()); result = cv.convertToModel("4", createContext()); assertEquals(4L, result.getOrThrow(r -> new OCSRuntimeException()).longValue()); }