MCTProperties extends Properties { @Override public String getProperty(String key) { String value = System.getProperty(key); if (value != null) { return trim(value); } else { return trim(super.getProperty(key)); } } MCTProperties(String propertyFileName);  MCTProperties();  MCTProperties(Class<?> c); void load(InputStream is); @Override String getProperty(String key); @Override String getProperty(String key, String defaultValue); static final MCTProperties DEFAULT_MCT_PROPERTIES; }
@Test public void basicPositiveTest() throws Exception { assertEquals(thisPkgProps.getProperty("test"), "testing789000"); assertEquals(thisPkgProps.size(), 3); assertTrue(mctSystemProps.containsKey("locale")); }
@Test public void defaultPropertyTest() throws Exception { String value = null; value = thisPkgProps.getProperty("xxx", "fallbackValue"); assertEquals(value, "fallbackValue"); value = thisPkgProps.getProperty("xxx"); Assert.assertNull(value); }
@Test public void testSystemPropertyOverride() throws Exception { System.setProperty("new.property", "new.value"); assertTrue(!thisPkgProps.containsKey("new.property")); assertEquals(thisPkgProps.getProperty("new.property"), "new.value"); assertEquals(thisPkgProps.getProperty("new.property", "default.value"), "new.value"); }
@Test public void testTrailingSpaces() { assertEquals(thisPkgProps.getProperty("no_trailing_space_property"), "abc"); assertEquals(thisPkgProps.getProperty("trailing_space_property"), "abc"); assertNull(thisPkgProps.getProperty("no_such_property")); assertEquals(thisPkgProps.getProperty("no_such_property", "abc"), "abc"); assertEquals(thisPkgProps.getProperty("no_such_property", " abc"), "abc"); assertEquals(thisPkgProps.getProperty("no_such_property", "abc "), "abc"); assertEquals(thisPkgProps.getProperty("no_such_property", " abc "), "abc"); }
@Test public void testDefaultValue() { assertEquals(thisPkgProps.getProperty("test", "abc"), "testing789000"); assertEquals(thisPkgProps.getProperty("nonExistentSystemProperty", "abc"), "abc"); System.getProperties().put("nonExistentSystemProperty", "xyz"); assertEquals(thisPkgProps.getProperty("nonExistentSystemProperty", "abc"), "xyz"); System.getProperties().put("test", "xyz"); assertEquals(thisPkgProps.getProperty("test", "abc"), "xyz"); }