From: Kai Moritz Date: Sat, 13 Aug 2022 13:34:31 +0000 (+0200) Subject: ROT: Erwartungen an SumBusinessLogic.endSum(String) X-Git-Tag: sumup-adder---lvm-2-tage~30 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=f4848341ef2fee62e3c62c63deed277a4f1a2d8a;p=demos%2Fkafka%2Ftraining ROT: Erwartungen an SumBusinessLogic.endSum(String) --- 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")); + } }