PropertyUtil { public static Properties loadProperties(String propertyName) { if (propertyName == null || "".equals(propertyName)) { return null; } Properties retProps = new Properties(); StringBuilder resourceName = new StringBuilder(); resourceName.append(propertyName); if (!propertyName.endsWith(PROPERTY_EXTENSION)) { resourceName.append(PROPERTY_EXTENSION); } InputStream is = Thread.currentThread().getContextClassLoader() .getResourceAsStream(resourceName.toString()); if (is == null) { is = PropertyUtil.class.getResourceAsStream("/" + propertyName + PROPERTY_EXTENSION); } try { retProps.load(is); } catch (NullPointerException npe) { log.warn("*** Can not find property-file [" + propertyName + ".properties] ***", npe); retProps = null; } catch (IOException ie) { log.error("", ie); retProps = null; } finally { try { if (is != null) { is.close(); } } catch (IOException ie) { log.error("", ie); retProps = null; } } return retProps; }  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 testLoadProperties01() throws Exception { String input = "test_message_01_en_US"; Properties result = PropertyUtil.loadProperties(input); assertTrue(result.containsKey("SystemExceptionHandlerTest.key")); assertTrue(result.containsValue("{0}message")); }
@Test public void testLoadProperties02() throws Exception { String input = "test_message_01"; Properties result = PropertyUtil.loadProperties(input); assertTrue(result.containsKey( "SystemExceptionHandlerTest.error.message")); assertTrue(result.containsValue( "\u4f8b\u5916\u30e1\u30c3\u30bb\u30fc\u30b8")); assertTrue(result.containsKey( "SystemExceptionHandlerTest.error.message.null")); assertTrue(result.containsValue("")); assertTrue(result.containsKey("SystemExceptionHandlerTest.key")); assertTrue(result.containsValue( "{0}\u30c7\u30d5\u30a9\u30eb\u30c8\u30e1\u30c3\u30bb\u30fc\u30b8")); }
@Test public void testLoadProperties03() throws Exception { String input = null; Properties result = PropertyUtil.loadProperties(input); assertNull(result); }
@Test public void testLoadProperties04() throws Exception { String input = ""; Properties result = PropertyUtil.loadProperties(input); assertNull(result); }
@Test public void testLoadProperties05() throws Exception { String input = "test_message_10"; Properties result = PropertyUtil.loadProperties(input); assertTrue(result.isEmpty()); }
@Test public void testLoadProperties06() throws Exception { String input = "test_me"; Properties result = PropertyUtil.loadProperties(input); assertTrue(logger.getLoggingEvents().get(0).getMessage().equals( "*** Can not find property-file" + " [test_me.properties] ***") && logger.getLoggingEvents().get(0).getLevel().equals( Level.WARN)); assertNull(result); }
@Test public void testLoadProperties07() throws Exception { String input = "test_message_01_en_US.properties"; Properties result = PropertyUtil.loadProperties(input); assertTrue(result.containsKey("SystemExceptionHandlerTest.key")); assertTrue(result.containsValue("{0}message")); }