ConfigUtils { public static Properties loadProperties(String fileName) { return loadProperties(fileName, false, false); } private  ConfigUtils(); static boolean isNotEmpty(String value); static boolean isEmpty(String value); static boolean isDefault(String value); static List<String> mergeValues(Class<?> type, String cfg, List<String> def); static String replaceProperty(String expression, Map<String, String> params); static Properties getProperties(); static void addProperties(Properties properties); static void setProperties(Properties properties); static String getProperty(String key); @SuppressWarnings({ "unchecked", "rawtypes" }) static String getProperty(String key, String defaultValue); static Properties loadProperties(String fileName); static Properties loadProperties(String fileName, boolean allowMultiFile); static Properties loadProperties(String fileName, boolean allowMultiFile, boolean optional); static int getPid();  }
@Test public void test_loadProperties_noFile() throws Exception { Properties p = ConfigUtils.loadProperties("notExisted", true); Properties expected = new Properties(); Assert.assertEquals(expected, p); p = ConfigUtils.loadProperties("notExisted", false); Assert.assertEquals(expected, p); }
@Test public void test_loadProperties_oneFile() throws Exception { Properties p = ConfigUtils.loadProperties("properties.load", false); Properties expected = new Properties(); expected.put("a", "12"); expected.put("b", "34"); expected.put("c", "56"); Assert.assertEquals(expected, p); }
@Test public void test_loadProperties_oneFile_allowMulti() throws Exception { Properties p = ConfigUtils.loadProperties("properties.load", true); Properties expected = new Properties(); expected.put("a", "12"); expected.put("b", "34"); expected.put("c", "56"); Assert.assertEquals(expected, p); }
@Test public void test_loadProperties_oneFile_notRootPath() throws Exception { Properties p = ConfigUtils.loadProperties("META-INF/dubbo/internal/com.alibaba.dubbo.common.threadpool.ThreadPool", false); Properties expected = new Properties(); expected.put("fixed", "com.alibaba.dubbo.common.threadpool.support.fixed.FixedThreadPool"); expected.put("cached", "com.alibaba.dubbo.common.threadpool.support.cached.CachedThreadPool"); expected.put("limited", "com.alibaba.dubbo.common.threadpool.support.limited.LimitedThreadPool"); Assert.assertEquals(expected, p); }
@Ignore("see http: @Test public void test_loadProperties_multiFile_notRootPath_Exception() throws Exception { try { ConfigUtils.loadProperties("META-INF/services/com.alibaba.dubbo.common.status.StatusChecker", false); Assert.fail(); } catch (IllegalStateException expected) { assertThat(expected.getMessage(), containsString("only 1 META-INF/services/com.alibaba.dubbo.common.status.StatusChecker file is expected, but 2 dubbo.properties files found on class path:")); } }
@Test public void test_loadProperties_multiFile_notRootPath() throws Exception { Properties p = ConfigUtils.loadProperties("META-INF/dubbo/internal/com.alibaba.dubbo.common.status.StatusChecker", true); Properties expected = new Properties(); expected.put("memory", "com.alibaba.dubbo.common.status.support.MemoryStatusChecker"); expected.put("load", "com.alibaba.dubbo.common.status.support.LoadStatusChecker"); expected.put("aa", "12"); Assert.assertEquals(expected, p); }