LocalDateWeekCodeConverter implements Converter<String, LocalDate> { @Override public Result<LocalDate> convertToModel(String value, ValueContext context) { if (StringUtils.isEmpty(value)) { return Result.ok(null); } try { return Result.ok(DateUtils.getStartDateOfWeek(value)); } catch (OCSRuntimeException ex) { return Result.error(ex.getMessage()); } }  @Override Result<LocalDate> convertToModel(String value, ValueContext context); @Override String convertToPresentation(LocalDate value, ValueContext context);  }
@Test public void testToModel() { Result<LocalDate> date = converter.convertToModel(null, new ValueContext()); assertNull(date.getOrThrow(r -> new OCSRuntimeException())); date = converter.convertToModel("2014-52", new ValueContext()); assertEquals(DateUtils.createLocalDate("22122014"), date.getOrThrow(r -> new OCSRuntimeException())); date = converter.convertToModel("2015-01", new ValueContext()); assertEquals(DateUtils.createLocalDate("29122014"), date.getOrThrow(r -> new OCSRuntimeException())); date = converter.convertToModel("2015-02", new ValueContext()); assertEquals(DateUtils.createLocalDate("05012015"), date.getOrThrow(r -> new OCSRuntimeException())); date = converter.convertToModel("2015-52", new ValueContext()); assertEquals(DateUtils.createLocalDate("21122015"), date.getOrThrow(r -> new OCSRuntimeException())); date = converter.convertToModel("2015-53", new ValueContext()); assertEquals(DateUtils.createLocalDate("28122015"), date.getOrThrow(r -> new OCSRuntimeException())); date = converter.convertToModel("2016-01", new ValueContext()); assertEquals(DateUtils.createLocalDate("04012016"), date.getOrThrow(r -> new OCSRuntimeException())); }