From 0aa4a1863bf9ee5d345c652f47f350f82d73e4aa Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 13 Aug 2022 15:17:01 +0200 Subject: [PATCH] ROT: Erwartungen an SumBusinessLogic.startSum(String) --- pom.xml | 11 +++++--- .../de/juplo/kafka/AdderBusinessLogic.java | 13 +++++++++ .../juplo/kafka/AdderBusinessLogicTest.java | 27 +++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/juplo/kafka/AdderBusinessLogic.java create mode 100644 src/test/java/de/juplo/kafka/AdderBusinessLogicTest.java diff --git a/pom.xml b/pom.xml index fe06959..dd282c5 100644 --- a/pom.xml +++ b/pom.xml @@ -12,10 +12,10 @@ de.juplo.kafka - wordcount + sum 1.0-SNAPSHOT - Wordcount - Splits the incomming sentences into words and counts the words per user. + Sum + Calculates the sum of all natuarl numbers up to the given natural number @@ -67,6 +67,11 @@ de.flapdoodle.embed.mongo test + + org.assertj + assertj-core + test + diff --git a/src/main/java/de/juplo/kafka/AdderBusinessLogic.java b/src/main/java/de/juplo/kafka/AdderBusinessLogic.java new file mode 100644 index 0000000..2e3d126 --- /dev/null +++ b/src/main/java/de/juplo/kafka/AdderBusinessLogic.java @@ -0,0 +1,13 @@ +package de.juplo.kafka; + + +public class AdderBusinessLogic +{ + public AdderBusinessLogic() + { + } + + public synchronized void startSum(String user) + { + } +} diff --git a/src/test/java/de/juplo/kafka/AdderBusinessLogicTest.java b/src/test/java/de/juplo/kafka/AdderBusinessLogicTest.java new file mode 100644 index 0000000..17fadb1 --- /dev/null +++ b/src/test/java/de/juplo/kafka/AdderBusinessLogicTest.java @@ -0,0 +1,27 @@ +package de.juplo.kafka; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; + + +public class AdderBusinessLogicTest +{ + @Test + @DisplayName("A new sum can be started, if it does not exist") + public void testCanStartSumIfNotExists() + { + AdderBusinessLogic adder = new AdderBusinessLogic(); + assertThatNoException().isThrownBy(() -> adder.startSum("foo")); + } + + @Test + @DisplayName("Starting an already existing sum again, causes an IllegalStateException") + public void testStartSumCausesExceptionIfExists() + { + AdderBusinessLogic adder = new AdderBusinessLogic(); + adder.startSum("foo"); + assertThatIllegalStateException().isThrownBy(() -> adder.startSum("foo")); + } +} -- 2.20.1