From 44781d5c1dd88eb9138d3139e1a96a7404a5d211 Mon Sep 17 00:00:00 2001 From: Todd Date: Fri, 29 Nov 2024 17:53:50 -0500 Subject: [PATCH] Add more tests to MinMaxGatherer as highlighted by coverage report --- .../gatherers4j/MinMaxGathererTest.java | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/ginsberg/gatherers4j/MinMaxGathererTest.java b/src/test/java/com/ginsberg/gatherers4j/MinMaxGathererTest.java index ab92eb3..99f36fd 100644 --- a/src/test/java/com/ginsberg/gatherers4j/MinMaxGathererTest.java +++ b/src/test/java/com/ginsberg/gatherers4j/MinMaxGathererTest.java @@ -16,6 +16,7 @@ package com.ginsberg.gatherers4j; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -27,12 +28,40 @@ class MinMaxGathererTest { - private record TestObject(String a, int b) { + private record TestObject(@Nullable String a, int b) { } @Nested class Max { + @Test + void allNullHasNoMax() { + // Arrange + final Stream input = Stream.of(null, null, null); + + // Act + final List output = input.gather(Gatherers4j.maxBy(String::length)).toList(); + + // Assert + assertThat(output).isEmpty(); + } + + @Test + void canHandleNullValues() { + // Arrange + final Stream input = Stream.of( + new TestObject("A", 1), + null, + new TestObject("C", 3) + ); + + // Act + final List output = input.gather(Gatherers4j.maxBy(TestObject::b)).toList(); + + // Assert + assertThat(output).containsExactly(new TestObject("C", 3)); + } + @Test void doesNotTestNullMappings() { // Arrange @@ -100,6 +129,33 @@ void maxValue() { @Nested class Min { + @Test + void allNullHasNoMin() { + // Arrange + final Stream input = Stream.of(null, null, null); + + // Act + final List output = input.skip(1).gather(Gatherers4j.minBy(String::length)).toList(); + + // Assert + assertThat(output).isEmpty(); + } + + @Test + void canHandleNullValues() { + // Arrange + final Stream input = Stream.of( + new TestObject("A", 1), + null, + new TestObject("C", 3) + ); + + // Act + final List output = input.gather(Gatherers4j.minBy(TestObject::b)).toList(); + + // Assert + assertThat(output).containsExactly(new TestObject("A", 1)); + } @Test void doesNotTestNullMappings() {