You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by po...@apache.org on 2017/10/24 22:08:28 UTC
incubator-tamaya git commit: TAMAYA-289: Fix test errors
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 9f0e1ddc4 -> 6813c93e3
TAMAYA-289: Fix test errors
eliminate warnings, Java8ify code.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/6813c93e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/6813c93e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/6813c93e
Branch: refs/heads/master
Commit: 6813c93e34f82f0cfb01eca03471c1cda561dcf3
Parents: 9f0e1dd
Author: Phil Ottlinger <po...@apache.org>
Authored: Wed Oct 25 00:08:15 2017 +0200
Committer: Phil Ottlinger <po...@apache.org>
Committed: Wed Oct 25 00:08:15 2017 +0200
----------------------------------------------------------------------
.../java/org/apache/tamaya/Configuration.java | 2 +-
.../internal/DefaultConfigurationProvider.java | 6 +
.../core/ConfigurationContextBuilderTest.java | 178 +++++--------------
.../apache/tamaya/core/ConfigurationTest.java | 13 +-
.../apache/tamaya/core/TestPropertySource.java | 1 -
.../tamaya/core/internal/BannerManagerTest.java | 3 +-
.../DefaultConfigurationContextBuilderTest.java | 84 +++------
.../DefaultConfigurationProviderTest.java | 10 +-
.../core/internal/DefaultConfigurationTest.java | 47 ++---
.../internal/PropertyConverterManagerTest.java | 18 +-
.../internal/PropertyFilterComparatorTest.java | 4 +-
11 files changed, 106 insertions(+), 260 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6813c93e/code/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/Configuration.java b/code/api/src/main/java/org/apache/tamaya/Configuration.java
index 6683c3b..76fa632 100644
--- a/code/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/code/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -40,7 +40,7 @@ import java.util.Map;
* <li>Immutable</li>
* </ul>
*
- * <p>It is not recommended that implementations also are serializable, since the any configuration can be <i>freezed</i>
+ * <p>It is not recommended that implementations also are serializable, since the any configuration can be <i>frozen</i>
* by reading out its complete configuration map into a serializable and remotable structure. This helps significantly
* simplifying the development current this interface, e.g. for being backed up by systems and stores that are not part current
* this library at all.</p>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6813c93e/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
index a7f0a6f..d7abf8b 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
@@ -76,12 +76,18 @@ public class DefaultConfigurationProvider implements ConfigurationProviderSpi {
return true;
}
+ /**
+ * @deprecated use {@link Configuration#getContext()} instead.
+ */
@Deprecated
@Override
public ConfigurationContext getConfigurationContext() {
return context;
}
+ /**
+ * @deprecated the context should be given upon creation of the {@link Configuration}
+ */
@Deprecated
@Override
public void setConfigurationContext(ConfigurationContext context){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6813c93e/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
index f1e8ea4..ddb36e2 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
@@ -25,9 +25,7 @@ import org.apache.tamaya.spi.*;
import org.junit.Test;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Comparator;
-import java.util.Map;
import static org.junit.Assert.*;
@@ -52,7 +50,7 @@ public class ConfigurationContextBuilderTest {
ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
.addPropertySources(testPropertySource, testPS2);
ConfigurationContext ctx = b.build();
- assertTrue(ctx.getPropertySources().size()==2);
+ assertEquals(2, ctx.getPropertySources().size());
assertTrue(ctx.getPropertySources().contains(testPropertySource));
assertTrue(ctx.getPropertySources().contains(testPS2));
// Ensure no sorting happens during add, so switch ordinals!
@@ -60,7 +58,7 @@ public class ConfigurationContextBuilderTest {
b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertySources(testPS2, testPropertySource);
ctx = b.build();
- assertTrue(ctx.getPropertySources().size()==2);
+ assertEquals(2, ctx.getPropertySources().size());
assertTrue(ctx.getPropertySources().contains(testPropertySource));
assertTrue(ctx.getPropertySources().contains(testPS2));
assertEquals(ctx.getPropertySources().get(1).getName(), "TestPropertySource");
@@ -73,7 +71,7 @@ public class ConfigurationContextBuilderTest {
ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
.addPropertySources(Arrays.asList(new PropertySource[]{testPropertySource, testPS2}));
ConfigurationContext ctx = b.build();
- assertTrue(ctx.getPropertySources().size()==2);
+ assertEquals(2, ctx.getPropertySources().size());
assertTrue(ctx.getPropertySources().contains(testPropertySource));
assertTrue(ctx.getPropertySources().contains(testPS2));
assertEquals(ctx.getPropertySources().get(0).getName(), "TestPropertySource");
@@ -83,7 +81,7 @@ public class ConfigurationContextBuilderTest {
b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertySources(Arrays.asList(new PropertySource[]{testPS2, testPropertySource}));
ctx = b.build();
- assertTrue(ctx.getPropertySources().size()==2);
+ assertEquals(2, ctx.getPropertySources().size());
assertTrue(ctx.getPropertySources().contains(testPropertySource));
assertTrue(ctx.getPropertySources().contains(testPS2));
assertEquals(ctx.getPropertySources().get(1).getName(), "TestPropertySource");
@@ -96,7 +94,7 @@ public class ConfigurationContextBuilderTest {
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertySources(testPropertySource, testPS2);
ConfigurationContext ctx = b.build();
- assertTrue(ctx.getPropertySources().size()==2);
+ assertEquals(2, ctx.getPropertySources().size());
assertTrue(ctx.getPropertySources().contains(testPropertySource));
assertTrue(ctx.getPropertySources().contains(testPS2));
b = ConfigurationProvider.getConfigurationContextBuilder()
@@ -105,7 +103,7 @@ public class ConfigurationContextBuilderTest {
ctx = b.build();
assertFalse(ctx.getPropertySources().contains(testPropertySource));
assertTrue(ctx.getPropertySources().contains(testPS2));
- assertTrue(ctx.getPropertySources().size()==1);
+ assertEquals(1, ctx.getPropertySources().size());
}
@Test
@@ -114,158 +112,107 @@ public class ConfigurationContextBuilderTest {
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertySources(testPropertySource, testPS2);
ConfigurationContext ctx = b.build();
- assertTrue(ctx.getPropertySources().size()==2);
+ assertEquals(2, ctx.getPropertySources().size());
assertTrue(ctx.getPropertySources().contains(testPropertySource));
assertTrue(ctx.getPropertySources().contains(testPS2));
b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertySources(testPropertySource, testPS2);
b.removePropertySources(testPropertySource);
ctx = b.build();
- assertTrue(ctx.getPropertySources().size()==1);
+ assertEquals(1, ctx.getPropertySources().size());
assertFalse(ctx.getPropertySources().contains(testPropertySource));
assertTrue(ctx.getPropertySources().contains(testPS2));
}
@Test
public void addPropertyFilters_Array() throws Exception {
- PropertyFilter filter1 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
- PropertyFilter filter2 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder();
b.addPropertyFilters(filter1, filter2);
ConfigurationContext ctx = b.build();
assertTrue(ctx.getPropertyFilters().contains(filter1));
assertTrue(ctx.getPropertyFilters().contains(filter2));
- assertTrue(ctx.getPropertyFilters().size()==2);
+ assertEquals(2, ctx.getPropertyFilters().size());
b = ConfigurationProvider.getConfigurationContextBuilder();
b.addPropertyFilters(filter1, filter2);
b.addPropertyFilters(filter1, filter2);
- assertTrue(ctx.getPropertyFilters().size()==2);
+ assertEquals(2, ctx.getPropertyFilters().size());
}
@Test
public void addPropertyFilters_Collection() throws Exception {
- PropertyFilter filter1 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
- PropertyFilter filter2 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder();
b.addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2}));
ConfigurationContext ctx = b.build();
assertTrue(ctx.getPropertyFilters().contains(filter1));
assertTrue(ctx.getPropertyFilters().contains(filter2));
- assertTrue(ctx.getPropertyFilters().size()==2);
+ assertEquals(2, ctx.getPropertyFilters().size());
b = ConfigurationProvider.getConfigurationContextBuilder();
b.addPropertyFilters(filter1, filter2);
b.addPropertyFilters(filter1, filter2);
- assertTrue(ctx.getPropertyFilters().size()==2);
+ assertEquals(2, ctx.getPropertyFilters().size());
}
@Test
public void removePropertyFilters_Array() throws Exception {
- PropertyFilter filter1 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
- PropertyFilter filter2 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertyFilters(filter1, filter2);
ConfigurationContext ctx = b.build();
assertTrue(ctx.getPropertyFilters().contains(filter1));
assertTrue(ctx.getPropertyFilters().contains(filter2));
- assertTrue(ctx.getPropertyFilters().size()==2);
+ assertEquals(2, ctx.getPropertyFilters().size());
b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertyFilters(filter1, filter2);
b.removePropertyFilters(filter1);
ctx = b.build();
- assertTrue(ctx.getPropertyFilters().size()==1);
+ assertEquals(1, ctx.getPropertyFilters().size());
assertFalse(ctx.getPropertyFilters().contains(filter1));
assertTrue(ctx.getPropertyFilters().contains(filter2));
}
@Test
public void removePropertyFilters_Collection() throws Exception {
- PropertyFilter filter1 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
- PropertyFilter filter2 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2}));
ConfigurationContext ctx = b.build();
assertTrue(ctx.getPropertyFilters().contains(filter1));
assertTrue(ctx.getPropertyFilters().contains(filter2));
- assertTrue(ctx.getPropertyFilters().size()==2);
+ assertEquals(2, ctx.getPropertyFilters().size());
b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2}));
b.removePropertyFilters(filter1);
ctx = b.build();
- assertTrue(ctx.getPropertyFilters().size()==1);
+ assertEquals(1, ctx.getPropertyFilters().size());
assertFalse(ctx.getPropertyFilters().contains(filter1));
assertTrue(ctx.getPropertyFilters().contains(filter2));
}
-
@Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public void addPropertyConverters_Array() throws Exception {
- PropertyConverter converter = new PropertyConverter(){
-
- @Override
- public Object convert(String value, ConversionContext context) {
- return value.toLowerCase();
- }
- };
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertyConverters(TypeLiteral.of(String.class), converter);
ConfigurationContext ctx = b.build();
assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
- assertEquals(ctx.getPropertyConverters().size(), 1);
+ assertEquals(1, ctx.getPropertyConverters().size());
b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertyConverters(TypeLiteral.of(String.class), converter);
b.addPropertyConverters(TypeLiteral.of(String.class), converter);
- assertEquals(ctx.getPropertyConverters().size(), 1);
+ assertEquals(1, ctx.getPropertyConverters().size());
}
@Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public void addPropertyConverters_Collection() throws Exception {
- PropertyConverter converter = new PropertyConverter(){
-
- @Override
- public Object convert(String value, ConversionContext context) {
- return value.toLowerCase();
- }
- };
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertyConverters(TypeLiteral.of(String.class),
Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter}));
@@ -280,57 +227,42 @@ public class ConfigurationContextBuilderTest {
}
@Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public void removePropertyConverters_Array() throws Exception {
- PropertyConverter converter = new PropertyConverter(){
-
- @Override
- public Object convert(String value, ConversionContext context) {
- return value.toLowerCase();
- }
- };
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertyConverters(TypeLiteral.of(String.class), converter);
ConfigurationContext ctx = b.build();
assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
- assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(), 1);
+ assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size());
b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertyConverters(TypeLiteral.of(String.class), converter);
b.removePropertyConverters(TypeLiteral.of(String.class), converter);
ctx = b.build();
assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
- assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(), 0);
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty());
}
- @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Test
public void removePropertyConverters_Collection() throws Exception {
- PropertyConverter converter = new PropertyConverter(){
-
- @Override
- public Object convert(String value, ConversionContext context) {
- return value.toLowerCase();
- }
- };
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter}));
ConfigurationContext ctx = b.build();
assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
- assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(), 1);
+ assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size());
b = ConfigurationProvider.getConfigurationContextBuilder()
.addPropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter}));
b.removePropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter}));
ctx = b.build();
assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
- assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(), 0);
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty());
}
@Test
public void setPropertyValueCombinationPolicy() throws Exception {
- PropertyValueCombinationPolicy combPol = new PropertyValueCombinationPolicy(){
- @Override
- public PropertyValue collect(PropertyValue currentValue, String key, PropertySource propertySource) {
- return currentValue;
- }
- };
+ PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue;
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder()
.setPropertyValueCombinationPolicy(combPol);
ConfigurationContext ctx = b.build();
@@ -434,12 +366,7 @@ public class ConfigurationContextBuilderTest {
propertySources[i] = new TestPropertySource("ps"+i,i);
}
b.addPropertySources(propertySources);
- Comparator<PropertySource> psComp = new Comparator<PropertySource>() {
- @Override
- public int compare(PropertySource o1, PropertySource o2) {
- return o1.toString().compareTo(o2.toString());
- }
- };
+ Comparator<PropertySource> psComp = (o1, o2) -> o1.toString().compareTo(o2.toString());
// test
b.sortPropertySources(psComp);
Arrays.sort(propertySources, psComp);
@@ -454,20 +381,10 @@ public class ConfigurationContextBuilderTest {
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder();
PropertyFilter[] propertyFilters = new PropertyFilter[10];
for(int i=0;i<propertyFilters.length;i++){
- propertyFilters[i] = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value.toBuilder().setValue(toString() + " - ").build();
- }
- };
+ propertyFilters[i] = (value, context) -> value.toBuilder().setValue(toString() + " - ").build();
}
b.addPropertyFilters(propertyFilters);
- Comparator<PropertyFilter> pfComp = new Comparator<PropertyFilter>() {
- @Override
- public int compare(PropertyFilter o1, PropertyFilter o2) {
- return o1.toString().compareTo(o2.toString());
- }
- };
+ Comparator<PropertyFilter> pfComp = (o1, o2) -> o1.toString().compareTo(o2.toString());
// test
b.sortPropertyFilter(pfComp);
Arrays.sort(propertyFilters, pfComp);
@@ -488,12 +405,7 @@ public class ConfigurationContextBuilderTest {
@Test
public void testRemoveAllFilters() throws Exception {
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder();
- b.addPropertyFilters(new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value.toBuilder().setValue(toString() + " - ").build();
- }
- });
+ b.addPropertyFilters((value, context) -> value.toBuilder().setValue(toString() + " - ").build());
assertFalse(b.getPropertyFilters().isEmpty());
b.removePropertyFilters(b.getPropertyFilters());
assertTrue(b.getPropertyFilters().isEmpty());
@@ -507,6 +419,4 @@ public class ConfigurationContextBuilderTest {
b.removePropertySources(b.getPropertySources());
assertTrue(b.getPropertyFilters().isEmpty());
}
-
-
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6813c93e/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
index 6b480e8..0fad63c 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
@@ -26,11 +26,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import java.util.Map;
-import java.util.Set;
-
/**
- * This tests checks if the combination of 2 prioritized PropertySource return valid results on the final Configuration.
+ * This tests checks if the combination of 2 prioritized PropertySource return valid results of the final configuration.
*/
public class ConfigurationTest {
@@ -53,14 +50,8 @@ public class ConfigurationTest {
assertEquals("Robin", current().get("name"));
assertEquals("Sabine", current().get("name2")); // from default
- assertEquals("Mapped to name: Robin", current().get("name3")); // oderridden default, mapped by filter to name property
+ assertEquals("Mapped to name: Robin", current().get("name3")); // overridden default, mapped by filter to name property
assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", current().get("name4")); // final only
assertNull(current().get("name5")); // final only, but removed from filter
-
- System.out.println("name : " + current().get("name"));
- System.out.println("name2: " + current().get("name2"));
- System.out.println("name3: " + current().get("name3"));
- System.out.println("name4: " + current().get("name4"));
- System.out.println("name5: " + current().get("name5"));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6813c93e/code/core/src/test/java/org/apache/tamaya/core/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/TestPropertySource.java b/code/core/src/test/java/org/apache/tamaya/core/TestPropertySource.java
index 91d83d2..7ec4458 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/TestPropertySource.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/TestPropertySource.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.core;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueBuilder;
import java.util.Collections;
import java.util.Date;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6813c93e/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java
index 9d2156b..9fc4433 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java
@@ -18,7 +18,6 @@
*/
package org.apache.tamaya.core.internal;
-import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
@@ -46,7 +45,7 @@ public class BannerManagerTest {
/*
* Here we check the precondition for this unit test
- * and the correct setup of the test enviroment
+ * and the correct setup of the test environment
* The JVM must have been started with
* -Djava.security.policy=<path_to_core_module</src/test/resources/java-security.policy
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6813c93e/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
index 83a15a7..dc301ff 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
@@ -21,10 +21,8 @@ package org.apache.tamaya.core.internal;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.*;
-import org.junit.Ignore;
import org.junit.Test;
-import javax.annotation.Priority;
import java.util.Collections;
import java.util.Map;
@@ -51,7 +49,7 @@ public class DefaultConfigurationContextBuilderTest {
ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
.addPropertySources(testPropertySource, testPS2);
ConfigurationContext ctx = b.build();
- assertTrue(ctx.getPropertySources().size()==2);
+ assertEquals(2, ctx.getPropertySources().size());
assertTrue(ctx.getPropertySources().contains(testPropertySource));
assertTrue(ctx.getPropertySources().contains(testPS2));
}
@@ -62,125 +60,88 @@ public class DefaultConfigurationContextBuilderTest {
ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
.addPropertySources(testPropertySource, testPS2);
ConfigurationContext ctx = b.build();
- assertTrue(ctx.getPropertySources().size()==2);
+ assertEquals(2, ctx.getPropertySources().size());
assertTrue(ctx.getPropertySources().contains(testPropertySource));
assertTrue(ctx.getPropertySources().contains(testPS2));
b = new DefaultConfigurationContextBuilder()
.addPropertySources(testPropertySource, testPS2);
b.removePropertySources(testPropertySource);
ctx = b.build();
- assertTrue(ctx.getPropertySources().size()==1);
+ assertEquals(1, ctx.getPropertySources().size());
assertFalse(ctx.getPropertySources().contains(testPropertySource));
assertTrue(ctx.getPropertySources().contains(testPS2));
}
@Test
public void addPropertyFilters_Array() throws Exception {
- PropertyFilter filter1 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
- PropertyFilter filter2 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
DefaultConfigurationContextBuilder b = new DefaultConfigurationContextBuilder();
b.addPropertyFilters(filter1, filter2);
ConfigurationContext ctx = b.build();
assertTrue(ctx.getPropertyFilters().contains(filter1));
assertTrue(ctx.getPropertyFilters().contains(filter2));
- assertTrue(ctx.getPropertyFilters().size()==2);
+ assertEquals(2, ctx.getPropertyFilters().size());
b = new DefaultConfigurationContextBuilder();
b.addPropertyFilters(filter1, filter2);
b.addPropertyFilters(filter1, filter2);
- assertTrue(ctx.getPropertyFilters().size()==2);
+ assertEquals(2, ctx.getPropertyFilters().size());
}
@Test
public void removePropertyFilters_Array() throws Exception {
- PropertyFilter filter1 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
- PropertyFilter filter2 = new PropertyFilter(){
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
.addPropertyFilters(filter1, filter2);
ConfigurationContext ctx = b.build();
assertTrue(ctx.getPropertyFilters().contains(filter1));
assertTrue(ctx.getPropertyFilters().contains(filter2));
- assertTrue(ctx.getPropertyFilters().size()==2);
+ assertEquals(2, ctx.getPropertyFilters().size());
b = new DefaultConfigurationContextBuilder()
.addPropertyFilters(filter1, filter2);
b.removePropertyFilters(filter1);
ctx = b.build();
- assertTrue(ctx.getPropertyFilters().size()==1);
+ assertEquals(1, ctx.getPropertyFilters().size());
assertFalse(ctx.getPropertyFilters().contains(filter1));
assertTrue(ctx.getPropertyFilters().contains(filter2));
}
@Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public void addPropertyConverter() throws Exception {
- PropertyConverter converter = new PropertyConverter(){
-
- @Override
- public Object convert(String value, ConversionContext context) {
- return value.toLowerCase();
- }
- };
- ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
+ ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
.addPropertyConverters(TypeLiteral.of(String.class), converter);
ConfigurationContext ctx = b.build();
assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
- assertEquals(ctx.getPropertyConverters().size(), 1);
+ assertEquals(1, ctx.getPropertyConverters().size());
b = new DefaultConfigurationContextBuilder()
.addPropertyConverters(TypeLiteral.of(String.class), converter);
b.addPropertyConverters(TypeLiteral.of(String.class), converter);
- assertEquals(ctx.getPropertyConverters().size(), 1);
+ assertEquals(1, ctx.getPropertyConverters().size());
}
@Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public void removePropertyConverters_Array() throws Exception {
- PropertyConverter converter = new PropertyConverter(){
-
- @Override
- public Object convert(String value, ConversionContext context) {
- return value.toLowerCase();
- }
- };
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
.addPropertyConverters(TypeLiteral.of(String.class), converter);
ConfigurationContext ctx = b.build();
assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
- assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(), 1);
+ assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size());
b = new DefaultConfigurationContextBuilder()
.addPropertyConverters(TypeLiteral.of(String.class), converter);
b.removePropertyConverters(TypeLiteral.of(String.class), converter);
ctx = b.build();
assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
- assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(), 0);
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty());
}
@Test
public void setPropertyValueCombinationPolicy() throws Exception {
- PropertyValueCombinationPolicy combPol = new PropertyValueCombinationPolicy(){
-
- @Override
- public PropertyValue collect(PropertyValue currentValue, String key, PropertySource propertySource) {
- return currentValue;
- }
-
- };
+ PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue;
ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
.setPropertyValueCombinationPolicy(combPol);
ConfigurationContext ctx = b.build();
@@ -189,8 +150,7 @@ public class DefaultConfigurationContextBuilderTest {
@Test
public void build() throws Exception {
- ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder();
- assertNotNull(b.build());
+ assertNotNull(new DefaultConfigurationContextBuilder().build());
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6813c93e/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationProviderTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationProviderTest.java
index 2f45896..ce5d046 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationProviderTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationProviderTest.java
@@ -48,7 +48,7 @@ public class DefaultConfigurationProviderTest {
@Test
public void getConfigurationContext() throws Exception {
- assertNotNull(new DefaultConfigurationProvider().getConfigurationContext());
+ assertNotNull(new DefaultConfigurationProvider().getConfiguration().getContext());
}
@Test
@@ -56,13 +56,15 @@ public class DefaultConfigurationProviderTest {
assertNotNull(new DefaultConfigurationProvider().getConfigurationContextBuilder());
}
- @Test
+ @SuppressWarnings("deprecation")
+ @Test
public void setConfigurationContext() throws Exception {
new DefaultConfigurationProvider()
- .setConfigurationContext(new DefaultConfigurationProvider().getConfigurationContext());
+ .setConfigurationContext(new DefaultConfigurationProvider().getConfiguration().getContext());
}
- @Test
+ @SuppressWarnings("deprecation")
+ @Test
public void isConfigurationContextSettable() throws Exception {
assertTrue(new DefaultConfigurationProvider().isConfigurationContextSettable());
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6813c93e/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationTest.java
index c12d157..d45dbbd 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationTest.java
@@ -18,13 +18,9 @@
*/
package org.apache.tamaya.core.internal;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.ConfigQuery;
-import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.*;
import org.junit.Test;
-import org.mockito.internal.matchers.Null;
import java.util.List;
import java.util.Map;
@@ -33,10 +29,9 @@ import static org.junit.Assert.assertEquals;
public class DefaultConfigurationTest {
- /*
- ** Tests for get(String)
+ /**
+ * Tests for get(String)
*/
-
@Test(expected = NullPointerException.class)
public void getDoesNotAcceptNull() {
DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
@@ -44,21 +39,20 @@ public class DefaultConfigurationTest {
c.get(null);
}
- /*
+ /**
* Tests for get(String, Class)
*/
-
- @Test(expected = NullPointerException.class)
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Test(expected = NullPointerException.class)
public void getDoesNotAcceptNullForClassTargetType() {
DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
c.get("a", (Class) null);
}
- /*
+ /**
* Tests for get(String, TypeLiteral)
*/
-
@Test(expected = NullPointerException.class)
public void getDoesNotAcceptNullForTypeLiteralTargetType() {
DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
@@ -66,10 +60,9 @@ public class DefaultConfigurationTest {
c.get("a", (TypeLiteral<?>)null);
}
- /*
+ /**
* Tests for getOrDefault(String, Class, String)
*/
-
@Test(expected = NullPointerException.class)
public void getOrDefaultDoesNotAcceptNullAsKeyForThreeParameterVariant() {
DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
@@ -84,17 +77,17 @@ public class DefaultConfigurationTest {
c.getOrDefault("a", String.class, null);
}
- @Test(expected = NullPointerException.class)
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test(expected = NullPointerException.class)
public void getOrDefaultDoesNotAcceptNullAsTargetTypeForThreeParameterVariant() {
DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
c.getOrDefault("a", (Class)null, "b");
}
- /*
+ /**
* Tests for getOrDefault(String, TypeLiteral, String)
*/
-
@Test(expected = NullPointerException.class)
public void getOrDefaultDoesNotAcceptNullAsKeyForThreeParameterVariantSecondIsTypeLiteral() {
DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
@@ -116,10 +109,9 @@ public class DefaultConfigurationTest {
c.getOrDefault("a", (TypeLiteral<String>) null, "b");
}
- /*
+ /**
* Tests for getOrDefault(String, String)
*/
-
@Test(expected = NullPointerException.class)
public void getOrDefaultDoesNotAcceptNullAsKeyForTwoParameterVariantDefaultValueIsSecond() {
DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
@@ -148,31 +140,18 @@ public class DefaultConfigurationTest {
c.query(null);
}
-
@Test
public void with() {
DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
- assertEquals(c.with(new ConfigOperator() {
- @Override
- public Configuration operate(Configuration config) {
- return config;
- }
- }), c);
+ assertEquals(c.with(config -> config), c);
}
@Test
public void query() {
DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
- assertEquals(c.query(new ConfigQuery<String>() {
- @Override
- public String query(Configuration config) {
- return "testQ";
- }
- }), "testQ");
+ assertEquals(c.query(config -> "testQ"), "testQ");
}
-
-
public static class DummyConfigurationContext implements ConfigurationContext {
@Override
public void addPropertySources(PropertySource... propertySources) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6813c93e/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
index 09701fb..fd9c766 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
@@ -18,8 +18,6 @@
*/
package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.spi.ConversionContext;
import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.TypeLiteral;
@@ -32,6 +30,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
+@SuppressWarnings("unchecked")
public class PropertyConverterManagerTest {
private final ConversionContext DUMMY_CONTEXT = new ConversionContext.Builder(
@@ -45,11 +44,12 @@ public class PropertyConverterManagerTest {
is(true));
}
- @Test
+ @SuppressWarnings({ "rawtypes" })
+ @Test
public void factoryMethodOfIsUsedAsConverter() {
PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<MyType>> converters = manager.getPropertyConverters(
+ List<PropertyConverter<MyType>> converters = manager.getPropertyConverters(
(TypeLiteral)TypeLiteral.of(MyType.class));
assertThat(converters, hasSize(1));
@@ -63,7 +63,7 @@ public class PropertyConverterManagerTest {
assertThat(((MyType)result).getValue(), equalTo("IN"));
}
- @Test
+ @Test
public void testDirectConverterMapping(){
PropertyConverterManager manager = new PropertyConverterManager();
List<PropertyConverter<C>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(C.class)));
@@ -77,7 +77,7 @@ public class PropertyConverterManagerTest {
assertThat((result).getInValue(), equalTo("testDirectConverterMapping"));
}
- @Test
+ @Test
public void testDirectSuperclassConverterMapping(){
PropertyConverterManager manager = new PropertyConverterManager(true);
List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
@@ -93,7 +93,7 @@ public class PropertyConverterManagerTest {
assertThat(((C)result).getInValue(), equalTo("testDirectSuperclassConverterMapping"));
}
- @Test
+ @Test
public void testMultipleConverterLoad(){
PropertyConverterManager manager = new PropertyConverterManager();
List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
@@ -106,7 +106,7 @@ public class PropertyConverterManagerTest {
assertThat(converters, hasSize(1));
}
- @Test
+ @Test
public void testTransitiveSuperclassConverterMapping(){
PropertyConverterManager manager = new PropertyConverterManager(true);
List<PropertyConverter<A>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(A.class)));
@@ -120,7 +120,7 @@ public class PropertyConverterManagerTest {
assertThat(((C)result).getInValue(), equalTo("testTransitiveSuperclassConverterMapping"));
}
- @Test
+ @Test
public void testDirectInterfaceMapping(){
PropertyConverterManager manager = new PropertyConverterManager(true);
List<PropertyConverter<Readable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Readable.class)));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6813c93e/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyFilterComparatorTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyFilterComparatorTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyFilterComparatorTest.java
index 322e7a2..0ad4c8a 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyFilterComparatorTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyFilterComparatorTest.java
@@ -62,14 +62,14 @@ public class PropertyFilterComparatorTest {
@Priority(1)
private static class PropertyFilterA implements PropertyFilter {
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- throw new RuntimeException("Not implement or look at me!");
+ throw new RuntimeException("Not implemented or look at me!");
}
}
@Priority(2)
private static class PropertyFilterB implements PropertyFilter {
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- throw new RuntimeException("Not implement or look at me!");
+ throw new RuntimeException("Not implemented or look at me!");
}
}
}
\ No newline at end of file