tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [03/18] incubator-tamaya-extensions git commit: Adapted to comply with JSR API.
Date Wed, 03 Jan 2018 00:08:59 GMT
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/581c92e7/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
b/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
index 99cb944..23a8c00 100644
--- a/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
+++ b/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
@@ -18,16 +18,14 @@
  */
 package org.apache.tamaya.functions;
 
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource;
-import org.apache.tamaya.spisupport.propertysource.SystemPropertySource;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.base.configsource.EnvironmentConfigSource;
+import org.apache.tamaya.base.configsource.SystemConfigSource;
 import org.junit.Test;
 
+import javax.config.Config;
+import javax.config.spi.ConfigBuilder;
+import javax.config.spi.ConfigProviderResolver;
 import java.io.PrintStream;
-import java.util.Map;
-import java.util.TreeMap;
 
 import static org.junit.Assert.*;
 
@@ -146,32 +144,32 @@ public class ConfigurationFunctionsTest {
 
     @Test
     public void testEmptyConfiguration() throws Exception {
-        Configuration ps = ConfigurationFunctions.emptyConfiguration();
+        Config ps = ConfigurationFunctions.emptyConfig();
         assertNotNull(ps);
-        assertNotNull(ps.getProperties());
-        assertTrue(ps.getProperties().isEmpty());
+        assertNotNull(ps.getPropertyNames());
+        assertFalse(ps.getPropertyNames().iterator().hasNext());
     }
 
 
     private void testSection(boolean stripKeys){
-        ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder();
-        b.addPropertySources(new EnvironmentPropertySource(), new SystemPropertySource());
-        Configuration cfg = ConfigurationProvider.createConfiguration(b.build()).with(
-                ConfigurationFunctions.section("java.", stripKeys));
+        ConfigBuilder b = ConfigProviderResolver.instance().getBuilder()
+                .withSources(new EnvironmentConfigSource(), new SystemConfigSource());
+        Config cfg = ConfigurationFunctions.section("java.", stripKeys)
+            .apply(b.build());
         System.out.println("*****************************************************");
         System.out.println("stripKeys: " + stripKeys);
         System.out.println("*****************************************************");
-        dump(cfg.getProperties(), System.out);
+        dump(cfg.getPropertyNames(), cfg, System.out);
         System.out.println();
         System.out.println("Example Metadata:");
-        System.out.println("\tjava.version         :  " + cfg.get("java.version"));
-        System.out.println("\tversion                 :  " + cfg.get("version"));
+        System.out.println("\tjava.version         :  " + cfg.getValue("java.version", String.class));
+        System.out.println("\tversion                 :  " + cfg.getValue("version", String.class));
     }
 
-    private void dump(Map<String, String> properties, PrintStream stream) {
+    private void dump(Iterable<String> keys, Config config, PrintStream stream) {
         stream.println("FULL DUMP:");
-        for (Map.Entry<String, String> en : new TreeMap<>(properties).entrySet())
{
-            stream.println("\t" + en.getKey() + " = " + en.getValue());
+        for (String key : keys) {
+            stream.println("\t" + key + " = " + config.getValue(key, String.class));
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/581c92e7/modules/functions/src/test/java/org/apache/tamaya/functions/EnrichedConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/EnrichedConfigurationTest.java
b/modules/functions/src/test/java/org/apache/tamaya/functions/EnrichedConfigurationTest.java
index 6bf97ac..6134144 100644
--- a/modules/functions/src/test/java/org/apache/tamaya/functions/EnrichedConfigurationTest.java
+++ b/modules/functions/src/test/java/org/apache/tamaya/functions/EnrichedConfigurationTest.java
@@ -25,13 +25,17 @@ import org.assertj.core.api.ThrowableAssert;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import java.util.HashMap;
-import java.util.Map;
+import javax.config.Config;
+import java.lang.reflect.Type;
+import java.util.*;
 
 import static java.util.Collections.EMPTY_MAP;
 import static org.apache.tamaya.functions.MethodNotMockedAnswer.NOT_MOCKED_ANSWER;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.eq;
@@ -47,13 +51,13 @@ public class EnrichedConfigurationTest {
 
     @Test
     public void getKeyIsNull() throws Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
         final EnrichedConfiguration sut = new EnrichedConfiguration(base, EMPTY_MAP, true);
 
         assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
             @Override
             public void call() throws Throwable {
-                sut.get(null);
+                sut.getValue(null, String.class);
             }
         }).isInstanceOf(NullPointerException.class)
           .hasMessage("Key must be given.");
@@ -61,9 +65,9 @@ public class EnrichedConfigurationTest {
 
     @Test
     public void getKeyIsNotKownAndHasNotAnOverriderWithOverridingOn() throws Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("9").when(base).get(eq("b"));
-        doReturn(null).when(base).get(eq("y"));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.of("9")).when(base).getOptionalValue(eq("b"), any());
+        doReturn(Optional.empty()).when(base).getOptionalValue(eq("y"), any());
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("z0", "0");
@@ -71,7 +75,7 @@ public class EnrichedConfigurationTest {
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.get("y");
+        String result = sut.getValue("y", String.class);
 
         assertThat(result).isNull();
 
@@ -79,9 +83,9 @@ public class EnrichedConfigurationTest {
 
     @Test
     public void getKeyIsNotKownAndHasNotAnOverriderWithOverridingOff() throws Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("9").when(base).get(eq("b"));
-        doReturn(null).when(base).get(eq("y"));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.of("9")).when(base).getOptionalValue(eq("b"), any());
+        doReturn(Optional.empty()).when(base).getOptionalValue(eq("y"), eq(String.class));
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("z0", "0");
@@ -89,15 +93,15 @@ public class EnrichedConfigurationTest {
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, false);
 
-        String result = sut.get("y");
+        String result = sut.getValue("y", String.class);
 
         assertThat(result).isNull();
     }
 
     @Test
     public void getKeyIsNotKownAndHasOverriderAndConfigurationIsOverridingIsOn() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("9").when(base).get(eq("y"));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn("9").when(base).getValue(eq("y"),any() );
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("z0", "0");
@@ -105,15 +109,16 @@ public class EnrichedConfigurationTest {
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.get("b");
+        String result = sut.getValue("b", String.class);
 
         assertThat(result).isNotNull().isEqualTo("1");
     }
 
     @Test
     public void getKeyIsNotKownAndHasOverriderAndConfigurationIsOverridingIsOff() throws
Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(null).when(base).get(eq("b"));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.empty()).when(base).getOptionalValue(eq("y"),any() );
+        doReturn(Optional.empty()).when(base).getOptionalValue(eq("b"),any() );
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("z0", "0");
@@ -121,15 +126,15 @@ public class EnrichedConfigurationTest {
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, false);
 
-        String result = sut.get("b");
+        String result = sut.getValue("b", String.class);
 
         assertThat(result).isNotNull().isEqualTo("1");
     }
 
     @Test
     public void getKeyIsKownAndHasOverriderAndConfigurationIsNotOverriding() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("9").when(base).get(eq("b"));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.of("9")).when(base).getOptionalValue(eq("b"),any() );
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("z0", "0");
@@ -137,15 +142,15 @@ public class EnrichedConfigurationTest {
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, false);
 
-        String result = sut.get("b");
+        String result = sut.getValue("b", String.class);
 
         assertThat(result).isNotNull().isEqualTo("9");
     }
 
     @Test
     public void getKeyIsKownAndHasOverriderAndConfigurationIsOverriding() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("9").when(base).get(eq("b"));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn("9").when(base).getValue(eq("b"),any() );
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("z0", "0");
@@ -153,22 +158,22 @@ public class EnrichedConfigurationTest {
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.get("b");
+        String result = sut.getValue("b", String.class);
 
         assertThat(result).isNotNull().isEqualTo("1");
     }
 
     @Test
     public void getKeyIsKnownAndHasNoOverrider() throws Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("9").when(base).get(eq("b"));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.of("9")).when(base).getOptionalValue(eq("b"),any() );
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("z0", "0");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.get("b");
+        String result = sut.getValue("b", String.class);
 
         assertThat(result).isNotNull().isEqualTo("9");
     }
@@ -178,194 +183,156 @@ public class EnrichedConfigurationTest {
      */
 
     @Test
-    public void getOrDefaultStringStringWithKeyIsNull() throws Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
+    public void getOptionalValueStringWithKeyIsNull() throws Exception {
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
 
         final EnrichedConfiguration sut = new EnrichedConfiguration(base, EMPTY_MAP, true);
 
         assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
             @Override
             public void call() throws Throwable {
-                sut.getOrDefault(null, "v");
+                sut.getOptionalValue(null, String.class);
             }
         }).isInstanceOf(NullPointerException.class)
           .hasMessage("Key must be given.");
     }
 
     @Test
-    public void getOrDefaultStringStringWithDefaultValueIsNull() throws Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-
-        final EnrichedConfiguration sut = new EnrichedConfiguration(base, EMPTY_MAP, true);
-
-        assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
-            @Override
-            public void call() throws Throwable {
-                sut.getOrDefault("v", null);
-            }
-        }).isInstanceOf(NullPointerException.class)
-          .hasMessage("Default value must be given.");
-    }
-
-    @Test
-    public void getOrDefaultStringStringWithKeyIsOverriddenAndOverridingOn() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("9").when(base).get(eq("b"));
+    public void getOptionalValueStringWithKeyIsOverriddenAndOverridingOn() throws Exception
{
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.of("9")).when(base).getOptionalValue(eq("b"), eq(String.class));
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("b", "0");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.getOrDefault("b", "100");
-
-        assertThat(result).isNotNull().isEqualTo("0");
+        Optional<String> result = sut.getOptionalValue("b", String.class);
+        assertNotNull(result);
+        assertTrue(result.isPresent());
+        assertEquals("0", result.get());
     }
 
     @Test
-    public void getOrDefaultStringStringWithKeyIsOverriddenAndOverridingOff() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("9").when(base).get(eq("b"));
+    public void getOptionalValueStringWithKeyIsOverriddenAndOverridingOff() throws Exception
{
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.of("9")).when(base).getOptionalValue(eq("b"), any());
+        doReturn(Optional.of("9")).when(base).getOptionalValue(eq("b"), any());
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("b", "0");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, false);
 
-        String result = sut.get("b");
+        String result = sut.getValue("b", String.class);
 
         assertThat(result).isNotNull().isEqualTo("9");
     }
 
     @Test
     public void getOrDefaultStringStringWithKeyIsKnownAndIsNotOverridden() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("9").when(base).get(eq("b"));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.of("9")).when(base).getOptionalValue(eq("b"), any());
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("z0", "0");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.getOrDefault("b", "100");
+        String result = sut.getOptionalValue("b", String.class).orElse("100");
 
         assertThat(result).isNotNull().isEqualTo("9");
     }
 
     @Test
     public void getOrDefaultStringStringWithKeyIsNotKnownButIsOverridden() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(null).when(base).get(eq("b"));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn("9").when(base).getValue(eq("b"), any());
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("b", "0");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.get("b");
+        String result = sut.getValue("b", String.class);
 
         assertThat(result).isNotNull().isEqualTo("0");
     }
 
     @Test
     public void getOrDefaultStringStringWithKeyIsUnKnownAndIsNotOverridden() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(null).when(base).get(eq("b"));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.of("9")).when(base).getOptionalValue("b", String.class);
+        doReturn(Optional.empty()).when(base).getOptionalValue("z", String.class);
         EnrichedConfiguration sut = new EnrichedConfiguration(base, EMPTY_MAP, true);
 
-        String result = sut.getOrDefault("b", "1000");
+        String result = sut.getOptionalValue("z", String.class).orElse("1000");
 
         assertThat(result).isNotNull().isEqualTo("1000");
     }
 
     /*
-     * Tests for getOrDefault(String, Class<T>, T)
+     * Tests for getOptionalValue(String, Class<T>)
      */
 
-    @Test
-    public void getOrDefaultStringClassTThrowsNPEIfKeyIsNull() throws Exception {
-        final EnrichedConfiguration sut = mock(EnrichedConfiguration.class, NOT_MOCKED_ANSWER);
-        doCallRealMethod().when(sut).getOrDefault(anyString(), any(Class.class), anyString());
-
-        assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
-            @Override
-            public void call() throws Throwable {
-                sut.getOrDefault("b", String.class, null);
-            }
-        }).isInstanceOf(NullPointerException.class)
-          .hasMessage("Default value not given.");
-    }
 
     @Test
-    public void getOrDefaultStringClassTThrowsNPEIfClassIsNull() throws Exception {
+    public void getOptionalValueStringClassTThrowsNPEIfClassIsNull() throws Exception {
         final EnrichedConfiguration sut = mock(EnrichedConfiguration.class, NOT_MOCKED_ANSWER);
-        doCallRealMethod().when(sut).getOrDefault(anyString(), any(Class.class), anyString());
+        doCallRealMethod().when(sut).getOptionalValue(anyString(), any(Class.class));
 
         assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
             @Override
             public void call() throws Throwable {
-                sut.getOrDefault("b", (Class<String>)null, "20");
+                sut.getOptionalValue("b", (Class<String>)null);
             }
         }).isInstanceOf(NullPointerException.class)
-          .hasMessage("Class not given.");
+          .hasMessage("Type must be given.");
     }
 
     @Test
-    public void getOrDefaultStringClassTThrowsNPEIfDefaultValueIsNull() throws Exception
{
-        final EnrichedConfiguration sut = mock(EnrichedConfiguration.class, NOT_MOCKED_ANSWER);
-        doCallRealMethod().when(sut).getOrDefault(anyString(), any(Class.class), anyString());
-
-        assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
-            @Override
-            public void call() throws Throwable {
-                sut.getOrDefault("b", String.class, null);
-            }
-        }).isInstanceOf(NullPointerException.class)
-          .hasMessage("Default value not given.");
-    }
-
-    @Test
-    public void getOrDefaultStringClassTKeyInBaseAndInAdditionsNotOverriding() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("1").when(base).get(eq("b"), any(TypeLiteral.class));
+    public void getOptionalValueStringClassTKeyInBaseAndInAdditionsNotOverriding() throws
Exception {
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.of("1")).when(base).getOptionalValue(eq("b"), any());
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("b", "2");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, false);
 
-        String result = sut.getOrDefault("b", String.class, "3");
-
-        assertThat(result).isEqualTo("1");
+        Optional<String> result = sut.getOptionalValue("b", String.class);
+        assertNotNull(result);
+        assertTrue(result.isPresent());
+        assertEquals("1", result.get());
     }
 
 
     @Test
     public void getOrDefaultStringClassTKeyInBaseAndInAddtionsOverriding() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("1").when(base).get(eq("b"), any(TypeLiteral.class));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn("1").when(base).getValue(eq("b"), any());
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("b", "2");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.getOrDefault("b", String.class, "3");
+        String result = sut.getOptionalValue("b", String.class).orElse("3");
 
         assertThat(result).isEqualTo("2");
     }
 
     @Test
     public void getOrDefaultStringClassTKeyNotInBaseInAdditionsNotOverriding() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(null).when(base).get(eq("b"), any(TypeLiteral.class));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.empty()).when(base).getOptionalValue(eq("b"), any());
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("b", "20");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, false);
 
-        String result = sut.getOrDefault("b", String.class, "B");
+        String result = sut.getOptionalValue("b", String.class).orElse("B");
 
         assertThat(result).isEqualTo("20");
     }
@@ -374,15 +341,15 @@ public class EnrichedConfigurationTest {
 
     @Test
     public void getOrDefaultStringClassTKeyNotInBaseInAddtionsOverriding() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(null).when(base).get(eq("b"), any(TypeLiteral.class));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(null).when(base).getValue(eq("b"), any());
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("b", "20");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.getOrDefault("b", String.class, "B");
+        String result = sut.getOptionalValue("b", String.class).orElse("B");
 
         assertThat(result).isEqualTo("20");
     }
@@ -390,28 +357,28 @@ public class EnrichedConfigurationTest {
 
     @Test
     public void getOrDefaultStringClassTKeyNotInBaseNotInAdditionsAndNotOverrding() throws
Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(null).when(base).get(eq("b"), any(TypeLiteral.class));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.empty()).when(base).getOptionalValue(eq("b"), any());
 
         Map<String, Object> additions = new HashMap<>();
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, false);
 
-        String result = sut.getOrDefault("b", String.class, "B");
+        String result = sut.getOptionalValue("b", String.class).orElse("B");
 
         assertThat(result).isEqualTo("B");
     }
 
     @Test
     public void getOrDefaultStringClassTKeyNotInBaseNotInAdditionsAndOverriding() throws
Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(null).when(base).get(eq("b"), any(TypeLiteral.class));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(null).when(base).getOptionalValue(eq("b"), any());
 
         Map<String, Object> additions = new HashMap<>();
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.getOrDefault("b", String.class, "3");
+        String result = sut.getOptionalValue("b", String.class).orElse("3");
 
         assertThat(result).isEqualTo("3");
     }
@@ -434,58 +401,43 @@ public class EnrichedConfigurationTest {
     @Test
     public void getOrDefaultStringTypeLiteralTThrowsNPEIfKeyIsNull() throws Exception {
         final EnrichedConfiguration sut = mock(EnrichedConfiguration.class, NOT_MOCKED_ANSWER);
-        doCallRealMethod().when(sut).getOrDefault(anyString(), any(TypeLiteral.class), anyString());
+        doCallRealMethod().when(sut).getOptionalValue(anyString(), any(Class.class));
 
         assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
             @Override
             public void call() throws Throwable {
-                sut.getOrDefault("b", TypeLiteral.<String>of(String.class), null);
+                sut.getOptionalValue(null,String.class);
             }
-        }).isInstanceOf(NullPointerException.class)
-          .hasMessage("Default value not given.");
+        }).isInstanceOf(NullPointerException.class);
 
     }
 
     @Test
     public void getOrDefaultStringLiteralTThrowsNPEIfClassIsNull() throws Exception {
         final EnrichedConfiguration sut = mock(EnrichedConfiguration.class, NOT_MOCKED_ANSWER);
-        doCallRealMethod().when(sut).getOrDefault(anyString(), any(TypeLiteral.class), anyString());
+        doCallRealMethod().when(sut).getOptionalValue(anyString(), any(Class.class));
 
         assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
             @Override
             public void call() throws Throwable {
-                sut.getOrDefault("b", (TypeLiteral<String>)null, "20");
+                sut.getOptionalValue("b", (Class)null).orElse("20");
             }
         }).isInstanceOf(NullPointerException.class)
-          .hasMessage("Type not given.");
+          .hasMessage("Type must be given.");
 
     }
 
     @Test
-    public void getOrDefaultStringTypeLiteralThrowsNPEIfDefaultValueIsNull() throws Exception
{
-        final EnrichedConfiguration sut = mock(EnrichedConfiguration.class, NOT_MOCKED_ANSWER);
-        doCallRealMethod().when(sut).getOrDefault(anyString(), any(TypeLiteral.class), anyString());
-
-        assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
-            @Override
-            public void call() throws Throwable {
-                sut.getOrDefault("b", TypeLiteral.<String>of(String.class), null);
-            }
-        }).isInstanceOf(NullPointerException.class)
-          .hasMessage("Default value not given.");
-    }
-
-    @Test
     public void getOrDefaultStringTypeLiteralTKeyInBaseAndInAdditionsNotOverriding() throws
Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("1").when(base).get(eq("b"), any(TypeLiteral.class));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.of("1")).when(base).getOptionalValue(eq("b"), any(Class.class));
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("b", "2");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, false);
 
-        String result = sut.getOrDefault("b", TypeLiteral.<String>of(String.class),
"3");
+        String result = sut.getOptionalValue("b", String.class).orElse("3");
 
         assertThat(result).isEqualTo("1");
     }
@@ -493,47 +445,48 @@ public class EnrichedConfigurationTest {
 
     @Test
     public void getOrDefaultStringTypeLiteralTKeyInBaseAndInAddtionsOverriding() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn("1").when(base).get(eq("b"), any(TypeLiteral.class));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn("1").when(base).getValue(eq("b"), any(Class.class));
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("b", "2");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.getOrDefault("b", TypeLiteral.<String>of(String.class),
"3");
+        String result = sut.getOptionalValue("b", String.class).orElse("3");
 
         assertThat(result).isEqualTo("2");
     }
 
     @Test
     public void getOrDefaultStringTypeLiteralTKeyNotInBaseInAdditionsNotOverriding() throws
Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(null).when(base).get(eq("b"), any(TypeLiteral.class));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.empty()).when(base).getOptionalValue(eq("b"), any());
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("b", "20");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, false);
 
-        String result = sut.getOrDefault("b", TypeLiteral.<String>of(String.class),
"B");
-
-        assertThat(result).isEqualTo("20");
+        Optional<String> result = sut.getOptionalValue("b", String.class);
+        assertNotNull(result);
+        assertTrue(result.isPresent());
+        assertEquals("20", result.get());
     }
 
 
 
     @Test
     public void getOrDefaultStringTypeLiteralTKeyNotInBaseInAddtionsOverriding() throws Exception
{
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(null).when(base).get(eq("b"), any(TypeLiteral.class));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(null).when(base).getValue(eq("b"), any(Class.class));
 
         Map<String, Object> additions = new HashMap<>();
         additions.put("b", "20");
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.getOrDefault("b", TypeLiteral.<String>of(String.class),
"B");
+        String result = sut.getOptionalValue("b", String.class).orElse("B");
 
         assertThat(result).isEqualTo("20");
     }
@@ -541,28 +494,28 @@ public class EnrichedConfigurationTest {
 
     @Test
     public void getOrDefaultStringTypeLiteralTKeyNotInBaseNotInAdditionsAndNotOverrding()
throws Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(null).when(base).get(eq("b"), any(TypeLiteral.class));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(Optional.empty()).when(base).getOptionalValue(eq("b"), any(Class.class));
 
         Map<String, Object> additions = new HashMap<>();
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, false);
 
-        String result = sut.getOrDefault("b", TypeLiteral.<String>of(String.class),
"B");
+        String result = sut.getOptionalValue("b", String.class).orElse("B");
 
         assertThat(result).isEqualTo("B");
     }
 
     @Test
     public void getOrDefaultStringTypeLiteralTKeyNotInBaseNotInAdditionsAndOverriding() throws
Exception {
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(null).when(base).get(eq("b"), any(TypeLiteral.class));
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(null).when(base).getOptionalValue("b", String.class);
 
         Map<String, Object> additions = new HashMap<>();
 
         EnrichedConfiguration sut = new EnrichedConfiguration(base, additions, true);
 
-        String result = sut.getOrDefault("b", TypeLiteral.<String>of(String.class),
"3");
+        String result = sut.getOptionalValue("b", String.class).orElse("3");
 
         assertThat(result).isEqualTo("3");
     }
@@ -579,18 +532,21 @@ public class EnrichedConfigurationTest {
         baseProps.put("b", "B");
         baseProps.put("c", "C");
 
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(baseProps).when(base).getProperties();
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(baseProps.keySet()).when(base).getPropertyNames();
+        doReturn(Optional.of("A")).when(base).getOptionalValue("a", String.class);
+        doReturn(Optional.of("B")).when(base).getOptionalValue("b", String.class);
+        doReturn(Optional.of("C")).when(base).getOptionalValue("c", String.class);
 
         EnrichedConfiguration enrichedConfiguration = new EnrichedConfiguration(base, EMPTY_MAP,
true);
 
-        Map<String, String> result = enrichedConfiguration.getProperties();
+        Iterable<String> result = enrichedConfiguration.getPropertyNames();
 
         assertThat(result).isNotEmpty()
-                          .hasSize(3)
-                          .containsEntry("a", "A")
-                          .containsEntry("b", "B")
-                          .containsEntry("c", "C");
+                          .hasSize(3);
+        assertEquals("A", enrichedConfiguration.getValue("a", String.class));
+        assertEquals("B", enrichedConfiguration.getValue("b", String.class));
+        assertEquals("C", enrichedConfiguration.getValue("c", String.class));
 
     }
 
@@ -601,21 +557,22 @@ public class EnrichedConfigurationTest {
         baseProps.put("b", "B");
         baseProps.put("c", "C");
 
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(baseProps).when(base).getProperties();
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(baseProps.keySet()).when(base).getPropertyNames();
+        doReturn(Optional.empty()).when(base).getOptionalValue(any(), any());
 
         Map<String, Object> additionalProps = new HashMap<>();
-        additionalProps.put("b", "b");
+        additionalProps.put("b", "B");
 
         EnrichedConfiguration enrichedConfiguration = new EnrichedConfiguration(base, additionalProps,
true);
 
-        Map<String, String> result = enrichedConfiguration.getProperties();
+        Iterable<String> result = enrichedConfiguration.getPropertyNames();
 
         assertThat(result).isNotEmpty()
                           .hasSize(3)
-                          .containsEntry("a", "A")
-                          .containsEntry("b", "b")
-                          .containsEntry("c", "C");
+                .contains("a").contains("b").contains("c");
+        assertEquals(null, enrichedConfiguration.getValue("a", String.class));
+        assertEquals("B", enrichedConfiguration.getValue("b", String.class));
     }
 
     @Test
@@ -625,23 +582,24 @@ public class EnrichedConfigurationTest {
         baseProps.put("b", "B");
         baseProps.put("c", "C");
 
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(baseProps).when(base).getProperties();
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(baseProps.keySet()).when(base).getPropertyNames();
+        doReturn(Optional.empty()).when(base).getOptionalValue(any(), any());
 
         Map<String, Object> additionalProps = new HashMap<>();
         additionalProps.put("e", "E");
 
         EnrichedConfiguration enrichedConfiguration = new EnrichedConfiguration(base, additionalProps,
true);
 
-        Map<String, String> result = enrichedConfiguration.getProperties();
-
-        assertThat(result).isNotEmpty()
-                          .hasSize(4)
-                          .containsEntry("a", "A")
-                          .containsEntry("b", "B")
-                          .containsEntry("c", "C")
-                          .containsEntry("e", "E");
+        Iterable<String> result = enrichedConfiguration.getPropertyNames();
 
+        assertThat(result)
+                .isNotEmpty()
+                .hasSize(4)
+                .contains("a")
+                .contains("b")
+                .contains("c")
+                .contains("e");
     }
 
     @Test
@@ -651,22 +609,26 @@ public class EnrichedConfigurationTest {
         baseProps.put("b", "B");
         baseProps.put("c", "C");
 
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(baseProps).when(base).getProperties();
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(baseProps.keySet()).when(base).getPropertyNames();
+        doReturn(Optional.of("A")).when(base).getOptionalValue(eq("a"), any());
+        doReturn(Optional.of("B")).when(base).getOptionalValue(eq("b"), any());
+        doReturn(Optional.of("C")).when(base).getOptionalValue(eq("c"), any());
+        doReturn(Optional.empty()).when(base).getOptionalValue(eq("e"), any());
 
         Map<String, Object> additionalProps = new HashMap<>();
         additionalProps.put("e", "E");
 
         EnrichedConfiguration enrichedConfiguration = new EnrichedConfiguration(base, additionalProps,
false);
 
-        Map<String, String> result = enrichedConfiguration.getProperties();
+        Iterable<String> result = enrichedConfiguration.getPropertyNames();
 
         assertThat(result).isNotEmpty()
-                          .hasSize(4)
-                          .containsEntry("a", "A")
-                          .containsEntry("b", "B")
-                          .containsEntry("c", "C")
-                          .containsEntry("e", "E");
+                          .hasSize(4);
+        assertEquals("A", enrichedConfiguration.getValue("a", String.class));
+        assertEquals("B", enrichedConfiguration.getValue("b", String.class));
+        assertEquals("C", enrichedConfiguration.getValue("c", String.class));
+        assertEquals("E", enrichedConfiguration.getValue("e", String.class));
 
     }
 
@@ -677,21 +639,22 @@ public class EnrichedConfigurationTest {
         baseProps.put("b", "B");
         baseProps.put("c", "C");
 
-        Configuration base = mock(Configuration.class, NOT_MOCKED_ANSWER);
-        doReturn(baseProps).when(base).getProperties();
+        Config base = mock(Config.class, NOT_MOCKED_ANSWER);
+        doReturn(baseProps.keySet()).when(base).getPropertyNames();
+        doReturn(Optional.empty()).when(base).getOptionalValue(any(), any());
 
         Map<String, Object> additionalProps = new HashMap<>();
         additionalProps.put("b", "b");
 
         EnrichedConfiguration enrichedConfiguration = new EnrichedConfiguration(base, additionalProps,
false);
 
-        Map<String, String> result = enrichedConfiguration.getProperties();
+        Iterable<String> result = enrichedConfiguration.getPropertyNames();
 
         assertThat(result).isNotEmpty()
                           .hasSize(3)
-                          .containsEntry("a", "A")
-                          .containsEntry("b", "B")
-                          .containsEntry("c", "C");
+                            .contains("a")
+                            .contains("b")
+                            .contains("c");
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/581c92e7/modules/functions/src/test/java/org/apache/tamaya/functions/MappedConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/MappedConfigurationTest.java
b/modules/functions/src/test/java/org/apache/tamaya/functions/MappedConfigurationTest.java
index 2a470a2..2b79250 100644
--- a/modules/functions/src/test/java/org/apache/tamaya/functions/MappedConfigurationTest.java
+++ b/modules/functions/src/test/java/org/apache/tamaya/functions/MappedConfigurationTest.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.functions;
 
 import org.junit.Test;
 
+import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doCallRealMethod;
@@ -34,18 +35,18 @@ public class MappedConfigurationTest {
     @Test(expected = NullPointerException.class)
     public void getOrDefaultWithTwoStringParametersThrowsNPEIfValueIsNull() throws Exception
{
         MappedConfiguration mc = mock(MappedConfiguration.class);
-        doReturn("z").when(mc).get(eq("a)"));
-        doCallRealMethod().when(mc).getOrDefault(anyString(), anyString());
+        doReturn("z").when(mc).getValue(eq("a)"), any());
+        doCallRealMethod().when(mc).getOptionalValue(anyString(), any());
 
-        mc.getOrDefault("a", (String)null);
+        mc.getOptionalValue("a", String.class);
     }
 
     @Test(expected = NullPointerException.class)
     public void getOrDefaultWithTwoStringParametersThrowsNPEIfKeyIsNull() throws Exception
{
         MappedConfiguration mc = mock(MappedConfiguration.class);
-        doCallRealMethod().when(mc).getOrDefault(anyString(), anyString());
+        doCallRealMethod().when(mc).getOptionalValue(anyString(), any());
 
-        mc.getOrDefault(null, "z");
+        mc.getOptionalValue(null, String.class);
     }
 
 }
\ No newline at end of file



Mime
View raw message