Maps2 { public static Map<String,String> fromProperties(final Properties properties) { checkNotNull(properties); Map<String,String> result = new HashMap<String, String>(properties.size()); Enumeration names = properties.propertyNames(); while (names.hasMoreElements()) { String name = (String)names.nextElement(); result.put(name, properties.getProperty(name)); } return result; } private  Maps2(); static Map<String,String> fromProperties(final Properties properties);  }
@Test public void fromProperties_entryWithNullValue() throws Exception { Properties props1 = new Properties() { @Override public Enumeration<?> propertyNames() { return Iterators.asEnumeration(ImmutableList.of("foo").iterator()); } @Override public String getProperty(final String key) { if ("foo".equals(key)) { return null; } return super.getProperty(key); } }; Map<String, String> props2 = Maps2.fromProperties(props1); assertThat(props2, hasEntry("foo", null)); }