PropertyUtil { public static synchronized void addPropertyFile(String name) { if (!name.endsWith(PROPERTY_EXTENSION)) { StringBuilder nameBuf = new StringBuilder(); nameBuf.append(name); nameBuf.append(PROPERTY_EXTENSION); name = nameBuf.toString(); } if (!files.contains(name)) { load(name); } }  static synchronized void addPropertyFile(String name); static String getProperty(String key); static String getProperty(String key, String defaultValue); static Enumeration<String> getPropertyNames(); static Enumeration<String> getPropertyNames(String keyPrefix); static Set<?> getPropertiesValues(String propertyName,
            String keyPrefix); static Enumeration<String> getPropertyNames(Properties localProps,
            String keyPrefix); static Set<String> getPropertiesValues(Properties localProps,
            Enumeration<String> propertyNames); static Properties loadProperties(String propertyName); static final String DEFAULT_PROPERTY_FILE; }
@Test public void testAddPropertyFile01() throws Exception { String input = "system"; PropertyUtil.addPropertyFile(input); Field field = PropertyUtil.class.getDeclaredField("files"); field.setAccessible(true); Set<?> st = (Set<?>) field.get(PropertyUtil.class); assertTrue(st.contains("system.properties")); }
@Test public void testAddPropertyFile02() throws Exception { String input = "system.properties"; PropertyUtil.addPropertyFile(input); Field field = PropertyUtil.class.getDeclaredField("files"); field.setAccessible(true); Set<?> st = (Set<?>) field.get(PropertyUtil.class); assertTrue(st.contains("system.properties")); }
@Test public void testAddPropertyFile03() throws Exception { String input = "xxxxx"; PropertyUtil.addPropertyFile(input); Field field = PropertyUtil.class.getDeclaredField("files"); field.setAccessible(true); Set<?> st = (Set<?>) field.get(PropertyUtil.class); assertFalse(st.contains("xxxxx.properties")); }
@Test public void testAddPropertyFile04() throws Exception { String input = null; try { PropertyUtil.addPropertyFile(input); fail(); } catch (NullPointerException e) { return; } }
@Test public void testAddPropertyFile05() throws Exception { String input = ""; PropertyUtil.addPropertyFile(input); Field field = PropertyUtil.class.getDeclaredField("files"); field.setAccessible(true); Set<?> st = (Set<?>) field.get(PropertyUtil.class); assertFalse(st.contains(".properties")); }
@Test public void testAddPropertyFile06() throws Exception { String input = "system"; PropertyUtil.addPropertyFile(input); PropertyUtil.addPropertyFile(input); Field field = PropertyUtil.class.getDeclaredField("files"); field.setAccessible(true); Set<?> st = (Set<?>) field.get(PropertyUtil.class); assertTrue(st.contains("system.properties")); assertTrue(st.size() == 1); }