ROT: Erwartungen an SumBusinessLogic.getSum(String)
authorKai Moritz <kai@juplo.de>
Sat, 13 Aug 2022 13:24:16 +0000 (15:24 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 13 Aug 2022 13:24:16 +0000 (15:24 +0200)
src/main/java/de/juplo/kafka/SumBusinessLogic.java
src/test/java/de/juplo/kafka/SumBusinessLogicTest.java

index e662606..5cb906a 100644 (file)
@@ -2,6 +2,7 @@ package de.juplo.kafka;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 
 
 public class SumBusinessLogic
@@ -27,4 +28,9 @@ public class SumBusinessLogic
 
     state.put(user, 0l);
   }
+
+  public synchronized Optional<Long> getSum(String user)
+  {
+    return Optional.empty();
+  }
 }
index 27c317a..ff9fdd0 100644 (file)
@@ -24,4 +24,21 @@ public class SumBusinessLogicTest
     sumBusinessLogic.startSum("foo");
     assertThatIllegalStateException().isThrownBy(() -> sumBusinessLogic.startSum("foo"));
   }
+
+  @Test
+  @DisplayName("An empty Optional should be returned, for a non-existing sum")
+  public void testEmptyOptionalForNonExistingSum()
+  {
+    SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
+    assertThat(sumBusinessLogic.getSum("foo")).isEmpty();
+  }
+
+  @Test
+  @DisplayName("A non-empty Optional should be returned, for an existing sum")
+  public void testNonEmptyOptionalForExistingSum()
+  {
+    SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
+    sumBusinessLogic.startSum("foo");
+    assertThat(sumBusinessLogic.getSum("foo")).isNotEmpty();
+  }
 }