/** * Replaces all the occurrences of variables in the given source object with * their matching values from the system properties. * * @param source the source text containing the variables to substitute, null returns null * @return the result of the replace operation */ public static String replaceSystemProperties(final Object source) { return new StrSubstitutor(StrLookup.systemPropertiesLookup()).replace(source); }
@Test public void testSystemPropertiesLookup() { assertEquals(System.getProperty("os.name"), StrLookup.systemPropertiesLookup().lookup("os.name")); assertNull(StrLookup.systemPropertiesLookup().lookup("")); assertNull(StrLookup.systemPropertiesLookup().lookup("other")); try { StrLookup.systemPropertiesLookup().lookup(null); fail(); } catch (final NullPointerException ex) { // expected } }
/** * Tests that a lookup object for system properties sees changes on system * properties. This test is related to LANG-1141. */ @Test public void testSystemPropertiesLookupUpdatedProperty() { final String osName = "os.name"; final String oldOs = System.getProperty(osName); final String newOsName = oldOs + "_changed"; final StrLookup<String> sysLookup = StrLookup.systemPropertiesLookup(); System.setProperty(osName, newOsName); try { assertEquals("Changed properties not detected", newOsName, sysLookup.lookup(osName)); } finally { System.setProperty(osName, oldOs); } }
/** * Tests that a lookup object for system properties can deal with a full * replacement of the system properties object. This test is related to * LANG-1055. */ @Test public void testSystemPropertiesLookupReplacedProperties() { final Properties oldProperties = System.getProperties(); final String osName = "os.name"; final String newOsName = oldProperties.getProperty(osName) + "_changed"; final StrLookup<String> sysLookup = StrLookup.systemPropertiesLookup(); final Properties newProps = new Properties(); newProps.setProperty(osName, newOsName); System.setProperties(newProps); try { assertEquals("Changed properties not detected", newOsName, sysLookup.lookup(osName)); } finally { System.setProperties(oldProperties); } }
/** * Replaces all the occurrences of variables in the given source object with * their matching values from the system properties. * * @param source the source text containing the variables to substitute, null returns null * @return the result of the replace operation */ public static String replaceSystemProperties(final Object source) { return new StrSubstitutor(StrLookup.systemPropertiesLookup()).replace(source); }
/** * Replaces all the occurrences of variables in the given source object with * their matching values from the system properties. * * @param source the source text containing the variables to substitute, null returns null * @return the result of the replace operation */ public static String replaceSystemProperties(final Object source) { return new StrSubstitutor(StrLookup.systemPropertiesLookup()).replace(source); }
/** * Replaces all the occurrences of variables in the given source object with * their matching values from the system properties. * * @param source the source text containing the variables to substitute, null returns null * @return the result of the replace operation */ public static String replaceSystemProperties(final Object source) { return new StrSubstitutor(StrLookup.systemPropertiesLookup()).replace(source); }