### Question:
PasswordMasker { public String maskPasswordsIfNecessary(String unmasked) { if (containsPasswordFragment(unmasked)) { return maskPasswordFragments(unmasked); } else { return unmasked; } }  Map<String, String> mask(Map<String, String> unmasked); String mask(Map.Entry<String, String> unmasked); String maskPasswordsIfNecessary(String unmasked);  }### Answer:
@Test public void testMaskNothing() { assertEquals("abcd", passwordMasker.maskPasswordsIfNecessary("abcd")); assertEquals("abcd abcd", passwordMasker.maskPasswordsIfNecessary("abcd abcd")); assertEquals("-Djava.net.pasX=pwd1", passwordMasker.maskPasswordsIfNecessary("-Djava.net.pasX=pwd1")); }
@Test public void testMaskJavaSystemProp() { assertEquals("-Djava.sysprop.password=*****", passwordMasker.maskPasswordsIfNecessary("-Djava.sysprop.password=pwd123")); }
@Test public void testMaskJavaSystemPropWithWhiteSpaces() { assertEquals(" -Djava.sysprop.password=***** ", passwordMasker.maskPasswordsIfNecessary(" -Djava.sysprop.password=pwd123 ")); }
@Test public void testMaskTwoJavaSystemProps() { assertEquals("-Djava.sysprop.password=***** -Djava.another.password=*****", passwordMasker.maskPasswordsIfNecessary("-Djava.sysprop.password=pwd123 -Djava.another.password=pwd456")); }
@Test public void testMaskEnvironmentVariable() { assertEquals("DUMMY_PASSWORD=*****", passwordMasker.maskPasswordsIfNecessary("DUMMY_PASSWORD=dummy")); }
@Test public void testMaskTwoEnvironmentVariables() { assertEquals("DUMMY_PASSWORD=*****:ANOTHER_PASSWORD=*****", passwordMasker.maskPasswordsIfNecessary("DUMMY_PASSWORD=dummy:ANOTHER_PASSWORD=pwd123")); }
@Test public void testMaskRandomMatchingStuff() { assertEquals("aa -Djava.sysprop.password=***** bb DUMMY_PASSWORD=***** cc", passwordMasker.maskPasswordsIfNecessary("aa -Djava.sysprop.password=1234 bb DUMMY_PASSWORD=dummy cc")); }
@Test public void testMaskNullArgument() { assertEquals(null, passwordMasker.maskPasswordsIfNecessary(null)); }
@Test public void testMaskEmptyArgument() { assertEquals("", passwordMasker.maskPasswordsIfNecessary("")); }