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 13:36:35 +0000 (15:36 +0200)
src/main/java/de/juplo/kafka/SumBusinessLogic.java
src/test/java/de/juplo/kafka/SumBusinessLogicTest.java

index 605e55c..73db4cf 100644 (file)
@@ -33,4 +33,9 @@ public class SumBusinessLogic
   {
     return Optional.ofNullable(state.get(user));
   }
+
+  public synchronized Long endSum(String user)
+  {
+    return null;
+  }
 }
index ff9fdd0..e65ee83 100644 (file)
@@ -41,4 +41,39 @@ public class SumBusinessLogicTest
     sumBusinessLogic.startSum("foo");
     assertThat(sumBusinessLogic.getSum("foo")).isNotEmpty();
   }
+
+  @Test
+  @DisplayName("A sum can be ended, if it does exist")
+  public void testCanEndIfSumExists()
+  {
+    SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
+    sumBusinessLogic.startSum("foo");
+    assertThatNoException().isThrownBy(() -> sumBusinessLogic.endSum("foo"));
+  }
+
+  @Test
+  @DisplayName("An existing Sum returns a non-null value, if ended")
+  public void testEndSumReturnsNonNullValueIfSumExists()
+  {
+    SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
+    sumBusinessLogic.startSum("foo");
+    assertThat(sumBusinessLogic.endSum("foo")).isNotNull();
+  }
+
+  @Test
+  @DisplayName("An existing Sum returns a non-negative value, if ended")
+  public void testEndSumReturnsNonNegativeValueIfSumExists()
+  {
+    SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
+    sumBusinessLogic.startSum("foo");
+    assertThat(sumBusinessLogic.endSum("foo")).isNotNegative();
+  }
+
+  @Test
+  @DisplayName("Ending a non-existing sum, causes an IllegalStateException")
+  public void testEndSumCausesExceptionIfNotExists()
+  {
+    SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
+    assertThatIllegalStateException().isThrownBy(() -> sumBusinessLogic.endSum("foo"));
+  }
 }