+ @DisplayName("An empty Optional should be returned, for a non-existing sum")
+ public void testGetSumReturnsEmptyOptionalForNonExistingSum()
+ {
+ AdderBusinessLogic adder = new AdderBusinessLogic();
+ assertThat(adder.getSum("foo")).isEmpty();
+ }
+
+ @Test
+ @DisplayName("A non-empty Optional should be returned, for an existing sum")
+ public void testGetSumReturnsNonEmptyOptionalForExistingSum()
+ {
+ AdderBusinessLogic adder = new AdderBusinessLogic();
+ adder.addToSum("foo", 6);
+ assertThat(adder.getSum("foo")).isNotEmpty();
+ }
+
+ @Test
+ @DisplayName("A sum can be calculated, if it does exist")
+ public void testCalculatePossibleIfSumExists()
+ {
+ AdderBusinessLogic adder = new AdderBusinessLogic();
+ adder.addToSum("foo", 6);
+ assertThatNoException().isThrownBy(() -> adder.calculate("foo"));
+ }
+
+ @Test
+ @DisplayName("An existing sum is removed, if ended")
+ public void testCalculateRemovesSumIfSumExists()
+ {
+ AdderBusinessLogic adder = new AdderBusinessLogic();
+ adder.addToSum("foo", 6);
+ adder.calculate("foo");
+ assertThat(adder.getSum("foo")).isEmpty();
+ }
+
+ @Test
+ @DisplayName("An existing sum returns a non-null value, if calculated")
+ public void testCalculateReturnsNonNullValueIfSumExists()
+ {
+ AdderBusinessLogic adder = new AdderBusinessLogic();
+ adder.addToSum("foo", 6);
+ assertThat(adder.calculate("foo")).isNotNull();
+ }
+
+ @Test
+ @DisplayName("Ending a non-existing sum, causes an IllegalStateException")
+ public void testCalculateCausesExceptionIfNotExists()