You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2017/09/17 19:25:16 UTC

[2/2] incubator-tamaya git commit: [TAMAYA-289] Wrote tests to raise the coverage.

[TAMAYA-289] Wrote tests to raise the coverage.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/de5188fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/de5188fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/de5188fb

Branch: refs/heads/master
Commit: de5188fb8368b303d43232d47c9371e45a6fbc7e
Parents: b331267
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Sun Sep 17 20:54:47 2017 +0200
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Sun Sep 17 21:20:37 2017 +0200

----------------------------------------------------------------------
 code/core/pom.xml                               |  4 ++
 .../converters/BigDecimalConverter.java         |  2 +-
 .../core/propertysource/CLIPropertySource.java  |  2 +-
 .../internal/PropertyFilterComparatorTest.java  | 75 ++++++++++++++++++++
 .../converters/BigDecimalConverterTest.java     | 31 +++++++-
 .../propertysource/BasePropertySourceTest.java  | 33 +++++++++
 pom.xml                                         |  6 ++
 7 files changed, 150 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/de5188fb/code/core/pom.xml
----------------------------------------------------------------------
diff --git a/code/core/pom.xml b/code/core/pom.xml
index 295b521..a608882 100644
--- a/code/core/pom.xml
+++ b/code/core/pom.xml
@@ -31,6 +31,10 @@ under the License.
 
     <dependencies>
         <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.apache.tamaya</groupId>
             <artifactId>tamaya-api</artifactId>
             <version>${project.version}</version>

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/de5188fb/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
index 6779809..a0d9c5f 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
@@ -37,7 +37,7 @@ import java.util.logging.Logger;
  *     <li>0XFFFFAC (integral numbers only)</li>
  * </ul>
  */
-public class BigDecimalConverter implements PropertyConverter<BigDecimal>{
+public class BigDecimalConverter implements PropertyConverter<BigDecimal> {
     /** The logger. */
     private static final Logger LOG = Logger.getLogger(BigDecimalConverter.class.getName());
     /** Converter to be used if the format is not directly supported by BigDecimal, e.g. for integral hex values. */

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/de5188fb/code/core/src/main/java/org/apache/tamaya/core/propertysource/CLIPropertySource.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/propertysource/CLIPropertySource.java b/code/core/src/main/java/org/apache/tamaya/core/propertysource/CLIPropertySource.java
index 5f25f14..40e39e0 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/propertysource/CLIPropertySource.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/propertysource/CLIPropertySource.java
@@ -29,7 +29,7 @@ import java.util.Objects;
  * PropertySource that allows to add the programs main arguments as configuration entries. Unix syntax using '--' and
  * '-' params is supported.
  */
-public class CLIPropertySource extends BasePropertySource{
+public class CLIPropertySource extends BasePropertySource {
 
     /** The original main arguments. */
     private static String[] args = new String[0];

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/de5188fb/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
new file mode 100644
index 0000000..322e7a2
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyFilterComparatorTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
+import org.junit.Test;
+
+import javax.annotation.Priority;
+
+import java.util.Comparator;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PropertyFilterComparatorTest {
+
+    @Test
+    public void comparationOfFiltersWithSamePriorityIsCorrect() {
+        Comparator<PropertyFilter> comparator = PropertyFilterComparator.getInstance();
+
+        int result = comparator.compare(new PropertyFilterA(), new PropertyFilterA());
+
+        assertThat(result).isEqualTo(0);
+    }
+
+    @Test
+    public void comparationOfFiltersFirstHigherThenSecondWorksCorrectly() {
+        Comparator<PropertyFilter> comparator = PropertyFilterComparator.getInstance();
+
+        int result = comparator.compare(new PropertyFilterB(), new PropertyFilterA());
+
+        assertThat(result).isGreaterThan(0);
+    }
+
+    @Test
+    public void comparationOfFiltersSecondHigherThenFirstWorksCorrectly() {
+        Comparator<PropertyFilter> comparator = PropertyFilterComparator.getInstance();
+
+        int result = comparator.compare(new PropertyFilterA(), new PropertyFilterB());
+
+        assertThat(result).isLessThan(0);
+    }
+
+
+    @Priority(1)
+    private static class PropertyFilterA  implements PropertyFilter {
+        public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+            throw new RuntimeException("Not implement 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!");
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/de5188fb/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java
index 9c71688..5e424e9 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java
@@ -20,11 +20,18 @@ package org.apache.tamaya.core.internal.converters;
 
 import org.apache.tamaya.Configuration;
 import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.ConversionContext;
 import org.junit.Test;
+import org.mockito.Mockito;
 
 import java.math.BigDecimal;
 
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
 
 /**
  * Tests the default converter for bytes.
@@ -45,6 +52,7 @@ public class BigDecimalConverterTest {
     }
 
 
+
     /**
      * Test conversion. The value are provided by
      * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
@@ -100,4 +108,25 @@ public class BigDecimalConverterTest {
         assertEquals(new BigDecimal("1016666666666666623333372637236287638216389293628763.1016666666666666623333372" +
                 "63723628763821638923628193612983618293628763"), valueRead);
     }
+
+    @Test
+    public void converterHandlesNullValueCorrectly() throws Exception {
+        ConversionContext context = mock(ConversionContext.class);
+
+        BigDecimalConverter converter = new BigDecimalConverter();
+        BigDecimal value = converter.convert("", context);
+
+        assertThat(value).isNull();
+    }
+
+    @Test
+    public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception {
+        ConversionContext context = mock(ConversionContext.class);
+
+        BigDecimalConverter converter = new BigDecimalConverter();
+        BigDecimal value = converter.convert("", context);
+
+        assertThat(value).isNull();
+        verify(context).addSupportedFormats(BigDecimalConverter.class, "<bigDecimal> -> new BigDecimal(String)");
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/de5188fb/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java b/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
index 9c2fc60..54f3113 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
@@ -26,9 +26,42 @@ import org.junit.Test;
 
 import java.util.*;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 public class BasePropertySourceTest {
 
     @Test
+    public void isAlwaysScanable() {
+        BasePropertySource bs = new BasePropertySource() {
+            @Override
+            public Map<String, PropertyValue> getProperties() {
+                return Collections.emptyMap();
+            }
+        };
+
+        assertThat(bs.isScannable()).isTrue();
+    }
+
+    @Test
+    public void givenOrdinalOverwritesGivenDefaulOrdinal() {
+        BasePropertySource bs = new BasePropertySource() {
+            @Override
+            public Map<String, PropertyValue> getProperties() {
+                return Collections.emptyMap();
+            }
+        };
+
+        bs.setDefaultOrdinal(10);
+
+        assertThat(bs.getDefaultOrdinal()).isEqualTo(10);
+        assertThat(bs.getOrdinal()).isEqualTo(10);
+
+        bs.setOrdinal(20);
+
+        assertThat(bs.getOrdinal()).isEqualTo(20);
+    }
+
+    @Test
     public void testGetOrdinal() {
 
         PropertySource defaultPropertySource = new BasePropertySource(56) {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/de5188fb/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 8012621..0a381c7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -208,6 +208,12 @@
     <dependencyManagement>
         <dependencies>
             <dependency>
+                <groupId>org.assertj</groupId>
+                <artifactId>assertj-core</artifactId>
+                <version>2.6.0</version>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
                 <groupId>org.mockito</groupId>
                 <artifactId>mockito-core</artifactId>
                 <version>${mockito.version}</version>