### Question:
DateExtractorTransformator extends TransformatorProcess { public void apply(String idProcess, ParameterTransformation parameterTransformation, ObjectNode jsonValue) { String valueToFormat = at(parameterTransformation.getFormatDateValue().getKeyField(), jsonValue).asText(); if (StringUtils.isNotBlank(valueToFormat)) { FastDateFormat srcFormatter = srcFormats.computeIfAbsent(parameterTransformation.getFormatDateValue().getSrcFormat(), key -> FastDateFormat.getInstance(key)); try { Date asDate = srcFormatter.parse(valueToFormat); DateTimeFormatter dateTimeFormatter = destFormats.computeIfAbsent(parameterTransformation.getFormatDateValue().getTargetFormat(), key -> DateTimeFormatter.ofPattern(key)); String result = asDate.toInstant().atZone(ZoneId.systemDefault()).format(dateTimeFormatter); put(jsonValue, parameterTransformation.getFormatDateValue().getTargetField(), result); } catch (ParseException e) { log.error("ExecutionException on field {} for value {}", parameterTransformation.getFormatDateValue(), jsonValue.toString()); } } } DateExtractorTransformator(); void apply(String idProcess, ParameterTransformation parameterTransformation, ObjectNode jsonValue);  }### Answer:
@Test public void should_Process_Ok() throws Exception { DateExtractorTransformator dateExtractorTransformator = new DateExtractorTransformator(); RawDataGen rd = RawDataGen.builder().messageSend("2018-01-15").project("project").type("type").build(); ObjectMapper obj = new ObjectMapper(); String value = obj.writeValueAsString(rd); ObjectNode jsonValue = JSONUtils.getInstance().parseObj(value); dateExtractorTransformator.apply(null, ParameterTransformation.builder() .formatDateValue(FormatDateValue.builder() .keyField("messageSend") .srcFormat("yyyy-MM-dd") .targetFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") .targetField("timestamp") .build()) .build(), jsonValue); assertThat(jsonValue.path("timestamp").asText()).startsWith("2018-01-15T00:00:00.000"); }
@Test public void should_Process_OkISO() throws Exception { DateExtractorTransformator dateExtractorTransformator = new DateExtractorTransformator(); RawDataGen rd = RawDataGen.builder().messageSend("2018-08-10T15:22:01.253Z").project("project").type("type").build(); ObjectMapper obj = new ObjectMapper(); String value = obj.writeValueAsString(rd); ObjectNode jsonValue = JSONUtils.getInstance().parseObj(value); dateExtractorTransformator.apply(null, ParameterTransformation.builder() .formatDateValue(FormatDateValue.builder() .keyField("messageSend") .srcFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") .targetFormat("yyyy") .targetField("year") .build()) .build(), jsonValue); assertThat(jsonValue.path("year").asText()).startsWith("2018"); }
@Test public void should_Process_Ko() throws Exception { DateExtractorTransformator dateExtractorTransformator = new DateExtractorTransformator(); RawDataGen rd = RawDataGen.builder().messageSend("2018-01-15").project("project").type("type").build(); ObjectMapper obj = new ObjectMapper(); String value = obj.writeValueAsString(rd); ObjectNode jsonValue = JSONUtils.getInstance().parseObj(value); dateExtractorTransformator.apply(null, ParameterTransformation.builder() .formatDateValue(FormatDateValue.builder() .keyField("toto") .srcFormat("yyyy-MM-dd") .targetFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") .build()) .build(), jsonValue); assertThat(jsonValue.path("toto").asText()).isEqualTo(""); }