ROT: Erwartungen an SumBusinessLogic.endSum(String)
authorKai Moritz <kai@juplo.de>
Sat, 13 Aug 2022 13:34:31 +0000 (15:34 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 13 Aug 2022 20:08:20 +0000 (22:08 +0200)
src/main/java/de/juplo/kafka/AdderBusinessLogic.java
src/test/java/de/juplo/kafka/AdderBusinessLogicTest.java

index 9fd5b0d..549228c 100644 (file)
@@ -34,4 +34,9 @@ public class AdderBusinessLogic
   {
     return Optional.ofNullable(state.get(user));
   }
+
+  public synchronized Long endSum(String user)
+  {
+    return null;
+  }
 }
index 4c0ed4b..8ae1728 100644 (file)
@@ -41,4 +41,39 @@ public class AdderBusinessLogicTest
     adder.startSum("foo");
     assertThat(adder.getSum("foo")).isNotEmpty();
   }
+
+  @Test
+  @DisplayName("A sum can be ended, if it does exist")
+  public void testCanEndIfSumExists()
+  {
+    AdderBusinessLogic adder = new AdderBusinessLogic();
+    adder.startSum("foo");
+    assertThatNoException().isThrownBy(() -> adder.endSum("foo"));
+  }
+
+  @Test
+  @DisplayName("An existing Sum returns a non-null value, if ended")
+  public void testEndSumReturnsNonNullValueIfSumExists()
+  {
+    AdderBusinessLogic adder = new AdderBusinessLogic();
+    adder.startSum("foo");
+    assertThat(adder.endSum("foo")).isNotNull();
+  }
+
+  @Test
+  @DisplayName("An existing Sum returns a non-negative value, if ended")
+  public void testEndSumReturnsNonNegativeValueIfSumExists()
+  {
+    AdderBusinessLogic adder = new AdderBusinessLogic();
+    adder.startSum("foo");
+    assertThat(adder.endSum("foo")).isNotNegative();
+  }
+
+  @Test
+  @DisplayName("Ending a non-existing sum, causes an IllegalStateException")
+  public void testEndSumCausesExceptionIfNotExists()
+  {
+    AdderBusinessLogic adder = new AdderBusinessLogic();
+    assertThatIllegalStateException().isThrownBy(() -> adder.endSum("foo"));
+  }
 }