TaskDataConverterUtil { public static void convert(Map<String, String> typeDefinitions, Map<String, Object> data) { typeDefinitions.entrySet().stream() .filter(entry -> !isBypassType(entry.getValue()) && mightBeConstant(data.get(entry.getKey()))) .forEach(entry -> process(entry.getKey(), entry.getValue(), data.get(entry.getKey()), newValue -> data.put(entry.getKey(), newValue))); }  static void convert(Map<String, String> typeDefinitions, Map<String, Object> data);  }
@Test public void testSupportedConstantValuesWithParsingErrors() { Map<String, String> definitions = new HashMap<>(); definitions.put(DOUBLE, Double.class.getName()); definitions.put(FLOAT, Float.class.getName()); definitions.put(INTEGER, Integer.class.getName()); definitions.put(BOOLEAN, Boolean.class.getName()); Map<String, Object> values = new HashMap<>(); values.put(DOUBLE, "a wrong double constant"); values.put(FLOAT, "a wrong float constant"); values.put(INTEGER, "a wrong integer constant"); values.put(BOOLEAN, "a wrong boolean constant"); TaskDataConverterUtil.convert(definitions, values); Assertions.assertThat(values) .containsEntry(DOUBLE, null) .containsEntry(FLOAT, null) .containsEntry(INTEGER, null) .containsEntry(BOOLEAN, false); }
@Test public void testUnsupportedConstants() { Map<String, String> definitions = new HashMap<>(); definitions.put(DATE, Date.class.getName()); definitions.put(LIST, List.class.getName()); Map<String, Object> values = new HashMap<>(); values.put(DATE, "a date constant"); values.put(LIST, "a list constant"); TaskDataConverterUtil.convert(definitions, values); Assertions.assertThat(values) .containsEntry(DATE, null) .containsEntry(LIST, null); }