From f4848341ef2fee62e3c62c63deed277a4f1a2d8a Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 13 Aug 2022 15:34:31 +0200 Subject: [PATCH] ROT: Erwartungen an SumBusinessLogic.endSum(String) --- .../de/juplo/kafka/AdderBusinessLogic.java | 5 +++ .../juplo/kafka/AdderBusinessLogicTest.java | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/main/java/de/juplo/kafka/AdderBusinessLogic.java b/src/main/java/de/juplo/kafka/AdderBusinessLogic.java index 9fd5b0d..549228c 100644 --- a/src/main/java/de/juplo/kafka/AdderBusinessLogic.java +++ b/src/main/java/de/juplo/kafka/AdderBusinessLogic.java @@ -34,4 +34,9 @@ public class AdderBusinessLogic { return Optional.ofNullable(state.get(user)); } + + public synchronized Long endSum(String user) + { + return null; + } } diff --git a/src/test/java/de/juplo/kafka/AdderBusinessLogicTest.java b/src/test/java/de/juplo/kafka/AdderBusinessLogicTest.java index 4c0ed4b..8ae1728 100644 --- a/src/test/java/de/juplo/kafka/AdderBusinessLogicTest.java +++ b/src/test/java/de/juplo/kafka/AdderBusinessLogicTest.java @@ -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")); + } } -- 2.20.1