ROT: Erwartungen an SumBusinessLogic.startSum(String)
authorKai Moritz <kai@juplo.de>
Sat, 13 Aug 2022 13:17:01 +0000 (15:17 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 13 Aug 2022 13:17:45 +0000 (15:17 +0200)
pom.xml
src/main/java/de/juplo/kafka/SumBusinessLogic.java [new file with mode: 0644]
src/test/java/de/juplo/kafka/SumBusinessLogicTest.java [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index fe06959..dd282c5 100644 (file)
--- a/pom.xml
+++ b/pom.xml
   </parent>
 
   <groupId>de.juplo.kafka</groupId>
-  <artifactId>wordcount</artifactId>
+  <artifactId>sum</artifactId>
   <version>1.0-SNAPSHOT</version>
-  <name>Wordcount</name>
-  <description>Splits the incomming sentences into words and counts the words per user.</description>
+  <name>Sum</name>
+  <description>Calculates the sum of all natuarl numbers up to the given natural number</description>
 
   <dependencies>
     <dependency>
       <artifactId>de.flapdoodle.embed.mongo</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
diff --git a/src/main/java/de/juplo/kafka/SumBusinessLogic.java b/src/main/java/de/juplo/kafka/SumBusinessLogic.java
new file mode 100644 (file)
index 0000000..cea533f
--- /dev/null
@@ -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 (file)
index 0000000..27c317a
--- /dev/null
@@ -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"));
+  }
+}