You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by kh...@apache.org on 2019/06/02 19:50:15 UTC

[commons-statistics] 02/06: Added package-info etc.

This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a commit to branch STATISTICS-14
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git

commit 2077ae438ada5bf28b43c23bdbd51b47d3f560e0
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Sun Jun 2 15:06:48 2019 +0200

    Added package-info etc.
---
 .../descriptive/BigDecimalSummaryStatistics.java   | 11 ++++----
 .../bigdecimal/descriptive/package-info.java       | 20 +++++++++++++
 .../BigDecimalSummaryStatisticsAssert.java         | 16 +++++++++++
 .../BigDecimalSummaryStatisticsTest.java           | 33 ++++++++++++++++++++++
 pom.xml                                            | 18 ++----------
 5 files changed, 77 insertions(+), 21 deletions(-)

diff --git a/commons-statistics-bigdecimal/src/main/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatistics.java b/commons-statistics-bigdecimal/src/main/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatistics.java
index 137c933..a936e63 100644
--- a/commons-statistics-bigdecimal/src/main/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatistics.java
+++ b/commons-statistics-bigdecimal/src/main/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatistics.java
@@ -96,20 +96,19 @@ public class BigDecimalSummaryStatistics implements Consumer<BigDecimal> {
         this.sum = sum;
         this.min = min;
         this.max = max;
-
-        this.count = count;
-        this.sum = sum;
-        this.min = min;
-        this.max = max;
     }
 
     /**
      * Records a new {@code BigDecimal} value into the summary information.
      *
      * @param value the input value
+     * @throws IllegalArgumentException in case of giving {@code null} for {@code value}.
      */
     @Override
     public void accept(BigDecimal value) {
+        if (value == null) {
+            throw new IllegalArgumentException("value is not allowed to be null.");
+        }
         count++;
         sum = sum.add(value);
 
@@ -121,7 +120,7 @@ public class BigDecimalSummaryStatistics implements Consumer<BigDecimal> {
      * Combines the state of another {@code BigDecimalSummaryStatistics} into this one.
      *
      * @param other another {@code BigDecimalSummaryStatistics}
-     * @throws IllegalArgumentException if {@code other} is null
+     * @throws IllegalArgumentException in case of giving {@code null} for {@code value}.
      */
     public void combine(BigDecimalSummaryStatistics other) throws IllegalArgumentException {
         if (other == null) {
diff --git a/commons-statistics-bigdecimal/src/main/java/org/apache/commons/statistics/bigdecimal/descriptive/package-info.java b/commons-statistics-bigdecimal/src/main/java/org/apache/commons/statistics/bigdecimal/descriptive/package-info.java
new file mode 100644
index 0000000..bdb61f5
--- /dev/null
+++ b/commons-statistics-bigdecimal/src/main/java/org/apache/commons/statistics/bigdecimal/descriptive/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+/**
+ * Implementations of common BigDecimal decriptive.
+ */
+package org.apache.commons.statistics.bigdecimal.descriptive;
diff --git a/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsAssert.java b/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsAssert.java
index 947aefc..a71bee4 100644
--- a/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsAssert.java
+++ b/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsAssert.java
@@ -1,3 +1,19 @@
+/*
+ * 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.commons.statistics.bigdecimal.descriptive;
 
 import org.assertj.core.api.AbstractAssert;
diff --git a/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsTest.java b/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsTest.java
index 6f80e4f..eeec30a 100644
--- a/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsTest.java
+++ b/commons-statistics-bigdecimal/src/test/java/org/apache/commons/statistics/bigdecimal/descriptive/BigDecimalSummaryStatisticsTest.java
@@ -22,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
 import java.math.BigDecimal;
 import java.util.stream.LongStream;
 import org.assertj.core.data.Offset;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
@@ -87,6 +88,37 @@ class BigDecimalSummaryStatisticsTest {
     }
 
     @Nested
+    @DisplayName("Parameter test")
+    class ParameterTest {
+
+        private BigDecimalSummaryStatistics bigDecimalSummaryStatistics;
+
+        @BeforeEach
+        void beforeEach() {
+            this.bigDecimalSummaryStatistics = new BigDecimalSummaryStatistics();
+        }
+
+        @Test
+        @DisplayName("accept should fail if given null")
+        void acceptShouldFailWhileGivingNull() {
+            assertThatIllegalArgumentException()
+                .isThrownBy(
+                    () -> this.bigDecimalSummaryStatistics.accept(null))
+                .withMessage("value is not allowed to be null.");
+        }
+
+        @Test
+        @DisplayName("combine should fail if given null")
+        void combineShouldFailWhileGivingNull() {
+            assertThatIllegalArgumentException()
+                .isThrownBy(
+                    () -> this.bigDecimalSummaryStatistics.combine(null))
+                .withMessage("other is not allowed to be null.");
+        }
+
+    }
+
+    @Nested
     @DisplayName("Edge case test")
     class EdgeCaseTest {
 
@@ -99,6 +131,7 @@ class BigDecimalSummaryStatisticsTest {
                     .collect(BigDecimalSummaryStatistics::new,
                         BigDecimalSummaryStatistics::accept,
                         BigDecimalSummaryStatistics::combine);
+
             assertThat(collect.getCount()).isEqualTo(1L);
             assertThat(collect.getAverage()).isEqualTo(BigDecimal.ONE);
             assertThat(collect.getMin()).isEqualTo(BigDecimal.ONE);
diff --git a/pom.xml b/pom.xml
index baffe52..47d5868 100644
--- a/pom.xml
+++ b/pom.xml
@@ -164,26 +164,14 @@
         <artifactId>commons-math3</artifactId>
         <version>${statistics.commons.math3.version}</version>
       </dependency>
-
-      <dependency>
-        <groupId>org.junit</groupId>
-        <artifactId>junit-bom</artifactId>
-        <version>5.4.2</version>
-        <scope>import</scope>
-        <type>pom</type>
-      </dependency>
     </dependencies>
   </dependencyManagement>
 
   <dependencies>
     <dependency>
-      <groupId>org.junit.jupiter</groupId>
-      <artifactId>junit-jupiter-engine</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.junit.vintage</groupId>
-      <artifactId>junit-vintage-engine</artifactId>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.12</version>
       <scope>test</scope>
     </dependency>
   </dependencies>