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 20:06:54 +0000 (22:06 +0200)
pom.xml
src/main/java/de/juplo/kafka/AdderBusinessLogic.java [new file with mode: 0644]
src/test/java/de/juplo/kafka/AdderBusinessLogicTest.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/AdderBusinessLogic.java b/src/main/java/de/juplo/kafka/AdderBusinessLogic.java
new file mode 100644 (file)
index 0000000..2e3d126
--- /dev/null
@@ -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 (file)
index 0000000..17fadb1
--- /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 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"));
+  }
+}