TaskVariablesPayloadValidator { public Map<String, Object> handlePayloadVariables(Map<String, Object> variables) { if (variables != null) { Set<String> mismatchedVars = variableNameValidator.validateVariables(variables); if (!mismatchedVars.isEmpty()) { throw new IllegalStateException("Variables have not valid names: " + String.join(", ", mismatchedVars)); } handleStringVariablesAsDates(variables); } return variables; } TaskVariablesPayloadValidator(DateFormatterProvider dateFormatterProvider,
                                         VariableNameValidator variableNameValidator); CreateTaskVariablePayload handleCreateTaskVariablePayload(CreateTaskVariablePayload createTaskVariablePayload); UpdateTaskVariablePayload handleUpdateTaskVariablePayload(UpdateTaskVariablePayload updateTaskVariablePayload); Map<String, Object> handlePayloadVariables(Map<String, Object> variables);  }
@Test public void should_convertStringToDate_when_stringRepresentsADate() { Map<String, Object> payloadMap = map( "date", "1970-01-01", "dateTime", "1970-01-01T01:01:01.001Z", "notADate", "this is not a date", "int", 1, "boolean", true ); long time = Duration.ofHours(1).toMillis() + Duration.ofMinutes(1).toMillis() + Duration.ofSeconds(1).toMillis() + 1; Map<String, Object> handledDates = taskVariablesPayloadValidator.handlePayloadVariables(payloadMap); assertThat(handledDates).containsEntry("date", new Date(0)); assertThat(handledDates).containsEntry("dateTime", new Date(time)); assertThat(handledDates).containsEntry("notADate", "this is not a date"); assertThat(handledDates).containsEntry("int", 1); assertThat(handledDates).containsEntry("boolean", true); }