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 20:07:30 +0000 (22:07 +0200)
src/main/java/de/juplo/kafka/AdderBusinessLogic.java
src/test/java/de/juplo/kafka/AdderBusinessLogicTest.java

index a3848c4..df8c5f9 100644 (file)
@@ -3,6 +3,7 @@ package de.juplo.kafka;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 
 
 public class AdderBusinessLogic
@@ -28,4 +29,9 @@ public class AdderBusinessLogic
 
     state.put(user, 0l);
   }
+
+  public synchronized Optional<Long> getSum(String user)
+  {
+    return Optional.empty();
+  }
 }
index 17fadb1..4c0ed4b 100644 (file)
@@ -24,4 +24,21 @@ public class AdderBusinessLogicTest
     adder.startSum("foo");
     assertThatIllegalStateException().isThrownBy(() -> adder.startSum("foo"));
   }
+
+  @Test
+  @DisplayName("An empty Optional should be returned, for a non-existing sum")
+  public void testEmptyOptionalForNonExistingSum()
+  {
+    AdderBusinessLogic adder = new AdderBusinessLogic();
+    assertThat(adder.getSum("foo")).isEmpty();
+  }
+
+  @Test
+  @DisplayName("A non-empty Optional should be returned, for an existing sum")
+  public void testNonEmptyOptionalForExistingSum()
+  {
+    AdderBusinessLogic adder = new AdderBusinessLogic();
+    adder.startSum("foo");
+    assertThat(adder.getSum("foo")).isNotEmpty();
+  }
 }