From 011347e4a951c7ec1d8cd91e8c0045a3f55d0dcd Mon Sep 17 00:00:00 2001 From: Jakob Edding <15202881+JakobEdding@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:08:41 +0200 Subject: [PATCH] Add tests --- .../junit4/WordCountTest.java | 60 +++++++++++++++++++ .../junit5/WordCountTest.java | 60 +++++++++++++++++++ .../WordCountTest.java | 60 +++++++++++++++++++ 3 files changed, 180 insertions(+) diff --git a/fluent-kafka-streams-tests-junit4/src/test/java/com/bakdata/fluent_kafka_streams_tests/junit4/WordCountTest.java b/fluent-kafka-streams-tests-junit4/src/test/java/com/bakdata/fluent_kafka_streams_tests/junit4/WordCountTest.java index e14eab6..ff68de5 100644 --- a/fluent-kafka-streams-tests-junit4/src/test/java/com/bakdata/fluent_kafka_streams_tests/junit4/WordCountTest.java +++ b/fluent-kafka-streams-tests-junit4/src/test/java/com/bakdata/fluent_kafka_streams_tests/junit4/WordCountTest.java @@ -244,4 +244,64 @@ public void shouldBeDoneAfterSingleWord() { public void shouldDoNothingOnEmptyInput() { this.testTopology.streamOutput().expectNoMoreRecord().and().expectNoMoreRecord().toBeEmpty(); } + + @Test + public void shouldConvertStreamOutputToList() { + this.testTopology.input() + .add("bla") + .add("blub") + .add("bla"); + + final List> outputs = this.testTopology.streamOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .extracting(ProducerRecord::key) + .containsExactly("bla", "blub", "bla"); + assertThat(outputs) + .extracting(ProducerRecord::value) + .containsExactly(1L, 1L, 2L); + } + + @Test + public void shouldConvertTableOutputToList() { + this.testTopology.input() + .add("bla") + .add("blub") + .add("bla"); + + final List> outputs = this.testTopology.tableOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .extracting(ProducerRecord::key) + .containsExactly("bla", "blub"); + assertThat(outputs) + .extracting(ProducerRecord::value) + .containsExactly(2L, 1L); + } + + @Test + public void shouldConvertEmptyStreamOutputToEmptyList() { + final List> outputs = this.testTopology.streamOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .isInstanceOf(List.class) + .isEmpty(); + } + + @Test + public void shouldConvertEmptyTableOutputToEmptyList() { + final List> outputs = this.testTopology.tableOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .isInstanceOf(List.class) + .isEmpty(); + } } diff --git a/fluent-kafka-streams-tests-junit5/src/test/java/com/bakdata/fluent_kafka_streams_tests/junit5/WordCountTest.java b/fluent-kafka-streams-tests-junit5/src/test/java/com/bakdata/fluent_kafka_streams_tests/junit5/WordCountTest.java index 4fa9d1b..dbe5a67 100644 --- a/fluent-kafka-streams-tests-junit5/src/test/java/com/bakdata/fluent_kafka_streams_tests/junit5/WordCountTest.java +++ b/fluent-kafka-streams-tests-junit5/src/test/java/com/bakdata/fluent_kafka_streams_tests/junit5/WordCountTest.java @@ -244,4 +244,64 @@ void shouldBeDoneAfterSingleWord() { void shouldDoNothingOnEmptyInput() { this.testTopology.streamOutput().expectNoMoreRecord().and().expectNoMoreRecord().toBeEmpty(); } + + @Test + void shouldConvertStreamOutputToList() { + this.testTopology.input() + .add("bla") + .add("blub") + .add("bla"); + + final List> outputs = this.testTopology.streamOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .extracting(ProducerRecord::key) + .containsExactly("bla", "blub", "bla"); + assertThat(outputs) + .extracting(ProducerRecord::value) + .containsExactly(1L, 1L, 2L); + } + + @Test + void shouldConvertTableOutputToList() { + this.testTopology.input() + .add("bla") + .add("blub") + .add("bla"); + + final List> outputs = this.testTopology.tableOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .extracting(ProducerRecord::key) + .containsExactly("bla", "blub"); + assertThat(outputs) + .extracting(ProducerRecord::value) + .containsExactly(2L, 1L); + } + + @Test + void shouldConvertEmptyStreamOutputToEmptyList() { + final List> outputs = this.testTopology.streamOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .isInstanceOf(List.class) + .isEmpty(); + } + + @Test + void shouldConvertEmptyTableOutputToEmptyList() { + final List> outputs = this.testTopology.tableOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .isInstanceOf(List.class) + .isEmpty(); + } } diff --git a/fluent-kafka-streams-tests/src/test/java/com/bakdata/fluent_kafka_streams_tests/WordCountTest.java b/fluent-kafka-streams-tests/src/test/java/com/bakdata/fluent_kafka_streams_tests/WordCountTest.java index 1b35b18..a5ce430 100644 --- a/fluent-kafka-streams-tests/src/test/java/com/bakdata/fluent_kafka_streams_tests/WordCountTest.java +++ b/fluent-kafka-streams-tests/src/test/java/com/bakdata/fluent_kafka_streams_tests/WordCountTest.java @@ -387,4 +387,64 @@ void shouldBeDoneAfterSingleWord() { void shouldDoNothingOnEmptyInput() { this.testTopology.streamOutput().expectNoMoreRecord().and().expectNoMoreRecord().toBeEmpty(); } + + @Test + void shouldConvertStreamOutputToList() { + this.testTopology.input() + .add("bla") + .add("blub") + .add("bla"); + + final List> outputs = this.testTopology.streamOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .extracting(ProducerRecord::key) + .containsExactly("bla", "blub", "bla"); + assertThat(outputs) + .extracting(ProducerRecord::value) + .containsExactly(1L, 1L, 2L); + } + + @Test + void shouldConvertTableOutputToList() { + this.testTopology.input() + .add("bla") + .add("blub") + .add("bla"); + + final List> outputs = this.testTopology.tableOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .extracting(ProducerRecord::key) + .containsExactly("bla", "blub"); + assertThat(outputs) + .extracting(ProducerRecord::value) + .containsExactly(2L, 1L); + } + + @Test + void shouldConvertEmptyStreamOutputToEmptyList() { + final List> outputs = this.testTopology.streamOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .isInstanceOf(List.class) + .isEmpty(); + } + + @Test + void shouldConvertEmptyTableOutputToEmptyList() { + final List> outputs = this.testTopology.tableOutput() + .withSerde(Serdes.String(), Serdes.Long()) + .toList(); + + assertThat(outputs) + .isInstanceOf(List.class) + .isEmpty(); + } }