### Question:
XProperties extends OrderedProperties { @Nullable @Override public String getProperty(final String key) { final String value = super.getProperty(key); if (null == value) return null; return substitutor.replace(value); } XProperties();  XProperties(@Nonnull final Map<String, String> initial); @Nonnull static XProperties from(@Nonnull @NonNull final String absolutePath); void register(@Nonnull final String prefix,
            @Nonnull final Conversion<?, ? extends Exception> factory); @Override synchronized void load(@Nonnull final Reader reader); @Override synchronized void load(final InputStream inStream); @Nullable @Override String getProperty(final String key); @Nullable @Override synchronized Object get(final Object key); @Nullable T getObject(@Nonnull final String key); @Nullable @SuppressWarnings("unchecked") T getObjectOrDefault(@Nonnull final String key,
            @Nullable final T defaultValue);  }### Answer:
@Test public void shouldReplaceEnvironmentVariables() { xprops.setProperty("bar", isWindows() ? "${USERNAME}" : "${USER}"); assertThat(xprops.getProperty("bar"), is(not(nullValue()))); }
@Test public void shouldThrowOnMissingReplacement() { thrown.expect(MissingPropertyException.class); thrown.expectMessage(containsString("no-such-value")); xprops.setProperty("missing", "${no-such-value}"); xprops.getProperty("missing"); }
@Test public void shouldReplaceGetProperty() { xprops.setProperty("foo", "found"); xprops.setProperty("bar", "${foo}"); assertThat(xprops.getProperty("bar"), is(equalTo("found"))); }
@Test public void shouldReplaceGetPropertyFromSystemProperties() { try { System.setProperty("foo", "found"); xprops.setProperty("bar", "${foo}"); assertThat(xprops.getProperty("bar"), is(equalTo("found"))); } finally { System.clearProperty("foo"); } }
@Test public void shouldReplaceGetPropertyFromEnvironment() { new MockUp<System>() { @Mock(invocations = 1) public String getenv(final String key) { return "found"; } }; xprops.setProperty("bar", "${foo}"); assertThat(xprops.getProperty("bar"), is(equalTo("found"))); }
@Test public void shouldReplaceRepeatedGetProperty() { xprops.setProperty("baz", "found"); xprops.setProperty("foo", "${baz}"); xprops.setProperty("bar", "${foo}"); assertThat(xprops.getProperty("bar"), is(equalTo("found"))); }
@Test public void shouldReplaceNestedGetProperty() { xprops.setProperty("baz", "found"); xprops.setProperty("foo", "baz"); xprops.setProperty("bar", "${${foo}}"); assertThat(xprops.getProperty("bar"), is(equalTo("found"))); }
@Test public void shouldReplaceSystemProperty() { xprops.setProperty("bar", "${user.name}"); assertThat(xprops.getProperty("bar"), is(not(nullValue()))); }