From e9f30aead5b4456b51944436961891d9a4962612 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 +++++--- .../java/de/juplo/kafka/SumBusinessLogic.java | 16 +++++++++++ .../de/juplo/kafka/SumBusinessLogicTest.java | 27 +++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/juplo/kafka/SumBusinessLogic.java create mode 100644 src/test/java/de/juplo/kafka/SumBusinessLogicTest.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/SumBusinessLogic.java b/src/main/java/de/juplo/kafka/SumBusinessLogic.java new file mode 100644 index 0000000..cea533f --- /dev/null +++ b/src/main/java/de/juplo/kafka/SumBusinessLogic.java @@ -0,0 +1,16 @@ +package de.juplo.kafka; + +import java.util.HashMap; +import java.util.Map; + + +public class SumBusinessLogic +{ + public SumBusinessLogic() + { + } + + public synchronized void startSum(String user) + { + } +} diff --git a/src/test/java/de/juplo/kafka/SumBusinessLogicTest.java b/src/test/java/de/juplo/kafka/SumBusinessLogicTest.java new file mode 100644 index 0000000..27c317a --- /dev/null +++ b/src/test/java/de/juplo/kafka/SumBusinessLogicTest.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 SumBusinessLogicTest +{ + @Test + @DisplayName("A new sum can be started, if it does not exist") + public void testCanStartSumIfNotExists() + { + SumBusinessLogic sumBusinessLogic = new SumBusinessLogic(); + assertThatNoException().isThrownBy(() -> sumBusinessLogic.startSum("foo")); + } + + @Test + @DisplayName("Starting an already existing sum again, causes an IllegalStateException") + public void testStartSumCausesExceptionIfExists() + { + SumBusinessLogic sumBusinessLogic = new SumBusinessLogic(); + sumBusinessLogic.startSum("foo"); + assertThatIllegalStateException().isThrownBy(() -> sumBusinessLogic.startSum("foo")); + } +} -- 2.20.1