### Question:
LazinessEnvironment implements Environment { @Override public String getProperty(String key) { String value = null; while (true) { LOG.info("Evaluating property '{}'...", key); value = environment.getProperty(key); if (value != null) break; String[] parts = StringUtils.split(key, '.'); if (parts.length == 1) break; String[] newParts = ArrayUtils.remove(parts, parts.length - 2); key = StringUtils.join(newParts, "."); } LOG.info("... returning '{}'", value); return value; } LazinessEnvironment(Environment environment); @Override boolean containsProperty(String key); @Override String getProperty(String key); @Override String getProperty(String key, String defaultValue); @Override T getProperty(String key, Class<T> targetType); @Override T getProperty(String key, Class<T> targetType, T defaultValue); @SuppressWarnings("deprecation") @Override Class<T> getPropertyAsClass(String key, Class<T> targetType); @Override String getRequiredProperty(String key); @Override T getRequiredProperty(String key, Class<T> targetType); @Override String resolvePlaceholders(String text); @Override String resolveRequiredPlaceholders(String text); @Override String[] getActiveProfiles(); @Override String[] getDefaultProfiles(); @Override boolean acceptsProfiles(String... profiles);  }### Answer:
@Test public void simple_property() { context.checking(new Expectations() {{ oneOf(environment).getProperty("simple-property"); will(returnValue("hello-world")); }}); assertEquals("hello-world", lazinessEnv.getProperty("simple-property")); }
@Test public void laziness_one_level() { context.checking(new Expectations() {{ oneOf(environment).getProperty("useless.required-property"); will(returnValue(null)); oneOf(environment).getProperty("required-property"); will(returnValue("found")); }}); assertEquals("found", lazinessEnv.getProperty("useless.required-property")); }
@Test public void laziness_complex_props() { context.checking(new Expectations() {{ oneOf(environment).getProperty("options.customers.retrieve-sql"); will(returnValue(null)); oneOf(environment).getProperty("options.retrieve-sql"); will(returnValue(null)); oneOf(environment).getProperty("retrieve-sql"); will(returnValue("found")); }}); assertEquals("found", lazinessEnv.getProperty("options.customers.retrieve-sql")); }