Skip to content

Commit

Permalink
Add more tests to MinMaxGatherer as highlighted by coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
tginsberg committed Nov 29, 2024
1 parent fbe22f5 commit 44781d5
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/test/java/com/ginsberg/gatherers4j/MinMaxGathererTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String> input = Stream.of(null, null, null);

// Act
final List<String> output = input.gather(Gatherers4j.maxBy(String::length)).toList();

// Assert
assertThat(output).isEmpty();
}

@Test
void canHandleNullValues() {
// Arrange
final Stream<TestObject> input = Stream.of(
new TestObject("A", 1),
null,
new TestObject("C", 3)
);

// Act
final List<TestObject> output = input.gather(Gatherers4j.maxBy(TestObject::b)).toList();

// Assert
assertThat(output).containsExactly(new TestObject("C", 3));
}

@Test
void doesNotTestNullMappings() {
// Arrange
Expand Down Expand Up @@ -100,6 +129,33 @@ void maxValue() {

@Nested
class Min {
@Test
void allNullHasNoMin() {
// Arrange
final Stream<String> input = Stream.of(null, null, null);

// Act
final List<String> output = input.skip(1).gather(Gatherers4j.minBy(String::length)).toList();

// Assert
assertThat(output).isEmpty();
}

@Test
void canHandleNullValues() {
// Arrange
final Stream<TestObject> input = Stream.of(
new TestObject("A", 1),
null,
new TestObject("C", 3)
);

// Act
final List<TestObject> output = input.gather(Gatherers4j.minBy(TestObject::b)).toList();

// Assert
assertThat(output).containsExactly(new TestObject("A", 1));
}

@Test
void doesNotTestNullMappings() {
Expand Down

0 comments on commit 44781d5

Please sign in to comment.