diff --git a/src/test/java/com/pivovarit/gatherers/LastTest.java b/src/test/java/com/pivovarit/gatherers/LastTest.java index 7741cc5..4c6252f 100644 --- a/src/test/java/com/pivovarit/gatherers/LastTest.java +++ b/src/test/java/com/pivovarit/gatherers/LastTest.java @@ -4,27 +4,36 @@ import java.util.stream.Stream; +import static com.pivovarit.gatherers.MoreGatherers.last; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class LastTest { + @Test + void shouldRejectInvalidSize() { + assertThatThrownBy(() -> last(0)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("number of elements can't be lower than one"); + } + @Test void shouldLastEmpty() { - assertThat(Stream.of().gather(MoreGatherers.last(42))).isEmpty(); + assertThat(Stream.of().gather(last(42))).isEmpty(); } @Test void shouldTakeLastElement() { - assertThat(Stream.of(1, 2, 3).gather(MoreGatherers.last(1))).containsExactly(3); + assertThat(Stream.of(1, 2, 3).gather(last(1))).containsExactly(3); } @Test void shouldTakeLastNElements() { - assertThat(Stream.of(1, 2, 3).gather(MoreGatherers.last(2))).containsExactly(2, 3); + assertThat(Stream.of(1, 2, 3).gather(last(2))).containsExactly(2, 3); } @Test void shouldTakeLastAllElements() { - assertThat(Stream.of(1, 2, 3).gather(MoreGatherers.last(42))).containsExactly(1, 2, 3); + assertThat(Stream.of(1, 2, 3).gather(last(42))).containsExactly(1, 2, 3); } }