### Question:
PropertiesUtils { public static void copy(Properties source, Properties dest, CopyMode copyMode) { Set<String> propertyNames = source.stringPropertyNames(); if (CopyMode.overwrite.equals(copyMode)) { for (String propertyName : propertyNames) { dest.setProperty(propertyName, source.getProperty(propertyName)); } } else if (CopyMode.dont_overwrite.equals(copyMode)) { for (String propertyName : propertyNames) { String value = dest.getProperty(propertyName); if (value == null) dest.setProperty(propertyName, source.getProperty(propertyName)); } } else throw new UnsupportedOperationException(copyMode.name() + " " + CopyMode.class.getName() +" is not supported"); } private  PropertiesUtils(); static Properties subProperties(Properties properties, String prefix); static void listOrdered(Properties properties, Writer writer); static void copy(Properties source, Properties dest, CopyMode copyMode); static Properties loadFromResource(String resourceClasspath);  }### Answer:
@Test public void copy_overwrite_existing() { Properties source = new Properties(); source.setProperty("a", "1"); Properties dest = new Properties(); dest.setProperty("a", "0"); PropertiesUtils.copy(source, dest, CopyMode.overwrite); assertEquals("1", dest.getProperty("a")); }
@Test public void copy_skip_existing() { Properties source = new Properties(); source.setProperty("a", "1"); Properties dest = new Properties(); dest.setProperty("a", "0"); PropertiesUtils.copy(source, dest, CopyMode.dont_overwrite); assertEquals("0", dest.getProperty("a")); }
@Test public void copy_to_system_properties_too() { System.clearProperty("a"); assertNull(System.getProperty("a")); Properties source = new Properties(); source.setProperty("a", "1"); PropertiesUtils.copy(source, System.getProperties(), CopyMode.dont_overwrite); assertEquals("1", System.getProperty("a")); }