This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-statistics.git
commit fdad1f807822ce81a6d95d881bae62cc3629861f Author: Alex Herbert <aherb...@apache.org> AuthorDate: Mon Mar 24 15:32:36 2025 +0000 Sonar fix: assert throws lambda to have one invocation under test --- .../org/apache/commons/statistics/descriptive/MedianTest.java | 6 ++++-- .../apache/commons/statistics/descriptive/QuantileTest.java | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java index dfc4423..68f5204 100644 --- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java +++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java @@ -191,8 +191,9 @@ class MedianTest { @MethodSource(value = {"org.apache.commons.statistics.descriptive.TestData#arrayRangeTestData"}) final void testDoubleMedianRangeThrows(int from, int to, int length) { final double[] values = new double[length]; + final Median m = Median.withDefaults(); Assertions.assertThrows(IndexOutOfBoundsException.class, - () -> Median.withDefaults().evaluateRange(values, from, to), + () -> m.evaluateRange(values, from, to), () -> String.format("range [%d, %d) in length %d", from, to, length)); } @@ -339,8 +340,9 @@ class MedianTest { @MethodSource(value = {"org.apache.commons.statistics.descriptive.TestData#arrayRangeTestData"}) final void testIntMedianRangeThrows(int from, int to, int length) { final int[] values = new int[length]; + final Median m = Median.withDefaults(); Assertions.assertThrows(IndexOutOfBoundsException.class, - () -> Median.withDefaults().evaluateRange(values, from, to), + () -> m.evaluateRange(values, from, to), () -> String.format("range [%d, %d) in length %d", from, to, length)); } diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java index ebd8faf..06ea4cf 100644 --- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java +++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/QuantileTest.java @@ -430,10 +430,11 @@ class QuantileTest { final void testDoubleQuantileRangeThrows(int from, int to, int length) { final double[] values = new double[length]; final Supplier<String> msg = () -> String.format("range [%d, %d) in length %d", from, to, length); + final Quantile q = Quantile.withDefaults(); Assertions.assertThrows(IndexOutOfBoundsException.class, - () -> Quantile.withDefaults().evaluateRange(values, from, to, 0.5), msg); + () -> q.evaluateRange(values, from, to, 0.5), msg); Assertions.assertThrows(IndexOutOfBoundsException.class, - () -> Quantile.withDefaults().evaluateRange(values, from, to, 0.25, 0.5), msg); + () -> q.evaluateRange(values, from, to, 0.25, 0.5), msg); } /** @@ -718,10 +719,11 @@ class QuantileTest { final void testIntQuantileRangeThrows(int from, int to, int length) { final int[] values = new int[length]; final Supplier<String> msg = () -> String.format("range [%d, %d) in length %d", from, to, length); + final Quantile q = Quantile.withDefaults(); Assertions.assertThrows(IndexOutOfBoundsException.class, - () -> Quantile.withDefaults().evaluateRange(values, from, to, 0.5), msg); + () -> q.evaluateRange(values, from, to, 0.5), msg); Assertions.assertThrows(IndexOutOfBoundsException.class, - () -> Quantile.withDefaults().evaluateRange(values, from, to, 0.25, 0.5), msg); + () -> q.evaluateRange(values, from, to, 0.25, 0.5), msg); } /**