ROT: Erwartungen an SumBusinessLogic.endSum(String)
[demos/kafka/training] / src / test / java / de / juplo / kafka / AdderBusinessLogicTest.java
index 17fadb1..8ae1728 100644 (file)
@@ -24,4 +24,56 @@ 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();
+  }
+
+  @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"));
+  }
 }