From 5592437b9ad0caa7c9dd28b6248cc786fae625d3 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) --- .../java/de/juplo/kafka/SumBusinessLogic.java | 5 +++ .../de/juplo/kafka/SumBusinessLogicTest.java | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/main/java/de/juplo/kafka/SumBusinessLogic.java b/src/main/java/de/juplo/kafka/SumBusinessLogic.java index 605e55c..73db4cf 100644 --- a/src/main/java/de/juplo/kafka/SumBusinessLogic.java +++ b/src/main/java/de/juplo/kafka/SumBusinessLogic.java @@ -33,4 +33,9 @@ public class SumBusinessLogic { return Optional.ofNullable(state.get(user)); } + + public synchronized Long endSum(String user) + { + return null; + } } diff --git a/src/test/java/de/juplo/kafka/SumBusinessLogicTest.java b/src/test/java/de/juplo/kafka/SumBusinessLogicTest.java index ff9fdd0..e65ee83 100644 --- a/src/test/java/de/juplo/kafka/SumBusinessLogicTest.java +++ b/src/test/java/de/juplo/kafka/SumBusinessLogicTest.java @@ -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")); + } } -- 2.20.1