### Question:
TaskHelper { public static Map<String, String> mergeProperties(Map<String, String> defaultProps, Map<String, String> loadedProps) { if (loadedProps == null && defaultProps == null) { return Collections.emptyMap(); } else if (loadedProps == null) { return new HashMap<>(defaultProps); } else if (defaultProps == null) { return new HashMap<>(loadedProps); } else { Map<String, String> result = new HashMap<>(loadedProps); defaultProps.keySet().stream() .filter(k -> !stringStartWithOneOfPrefixes(k, loadedProps.keySet())) .filter(k -> !result.containsKey(k)) .forEach(k -> result.put(k, defaultProps.get(k))); return result; } } private  TaskHelper(); static String buildUrl(RuntimeCamelCatalog rcc, Map<String, String> props, String componentSchema, String endpointPropertiesPrefix, String pathPropertiesPrefix); static String buildUrl(Map<String, String> props, String componentSchema, String endpointPropertiesPrefix, String pathPropertiesPrefix); static String createEndpointOptionsFromProperties(Map<String, String> props, String prefix); static String createUrlPathFromProperties(Map<String, String> props, String prefix); static Map<String, String> mergeProperties(Map<String, String> defaultProps, Map<String, String> loadedProps); static void logRecordContent(Logger logger, ConnectRecord<?> record, CFG config);  }### Answer:
@Test public void testMergePropertiesNull() { Map result = TaskHelper.mergeProperties(null, null); assertEquals(Collections.EMPTY_MAP, result); }
@Test public void testMergePropertiesDefaultAreAdded() { Map<String, String> defaults = new HashMap<String, String>() { { put("property", "defaultValue"); } }; Map<String, String> loaded = new HashMap<String, String>() { { put("anotherProperty", "loadedValue"); } }; Map result = TaskHelper.mergeProperties(defaults, loaded); assertTrue(result.containsKey("property")); assertTrue(result.containsKey("anotherProperty")); assertEquals("defaultValue", result.get("property")); assertEquals("loadedValue", result.get("anotherProperty")); }
@Test public void testMergePropertiesLoadedHavePrecedence() { Map<String, String> defaults = new HashMap<String, String>() { { put("property", "defaultValue"); } }; Map<String, String> loaded = new HashMap<String, String>() { { put("property", "loadedValue"); } }; Map result = TaskHelper.mergeProperties(defaults, loaded); assertTrue(result.containsKey("property")); assertEquals("loadedValue", result.get("property")); }
@Test public void testMergePropertiesLoadedHavePrecedenceWithPrefixFiltering() { Map<String, String> defaults = new HashMap<String, String>() { { put("property", "defaultValue"); put("camel.component.x.objectProperty", "#class:my.package.MyClass"); put("camel.component.x.objectProperty.field", "defaultValue"); } }; Map<String, String> loaded = new HashMap<String, String>() { { put("camel.component.x.objectProperty", "#class:my.package.MyOtherClass"); put("camel.component.x.objectProperty.anotherField", "loadedValue"); put("camel.component.x.normalProperty", "loadedValue"); } }; Map result = TaskHelper.mergeProperties(defaults, loaded); assertEquals("defaultValue", result.get("property")); assertEquals("#class:my.package.MyOtherClass", result.get("camel.component.x.objectProperty")); assertEquals("loadedValue", result.get("camel.component.x.objectProperty.anotherField")); assertEquals("loadedValue", result.get("camel.component.x.normalProperty")); assertTrue(!result.containsKey("camel.component.x.objectProperty.field")); }