1 package de.juplo.kafka;
3 import org.junit.jupiter.api.DisplayName;
4 import org.junit.jupiter.api.Test;
6 import static org.assertj.core.api.Assertions.*;
9 public class AdderBusinessLogicTest
12 @DisplayName("A new sum can be started, if it does not exist")
13 public void testCanStartSumIfNotExists()
15 AdderBusinessLogic adder = new AdderBusinessLogic();
16 assertThatNoException().isThrownBy(() -> adder.startSum("foo"));
20 @DisplayName("Starting an already existing sum again, causes an IllegalStateException")
21 public void testStartSumCausesExceptionIfExists()
23 AdderBusinessLogic adder = new AdderBusinessLogic();
24 adder.startSum("foo");
25 assertThatIllegalStateException().isThrownBy(() -> adder.startSum("foo"));
29 @DisplayName("An empty Optional should be returned, for a non-existing sum")
30 public void testEmptyOptionalForNonExistingSum()
32 AdderBusinessLogic adder = new AdderBusinessLogic();
33 assertThat(adder.getSum("foo")).isEmpty();
37 @DisplayName("A non-empty Optional should be returned, for an existing sum")
38 public void testNonEmptyOptionalForExistingSum()
40 AdderBusinessLogic adder = new AdderBusinessLogic();
41 adder.startSum("foo");
42 assertThat(adder.getSum("foo")).isNotEmpty();
46 @DisplayName("A sum can be ended, if it does exist")
47 public void testCanEndIfSumExists()
49 AdderBusinessLogic adder = new AdderBusinessLogic();
50 adder.startSum("foo");
51 assertThatNoException().isThrownBy(() -> adder.endSum("foo"));
55 @DisplayName("An existing Sum returns a non-null value, if ended")
56 public void testEndSumReturnsNonNullValueIfSumExists()
58 AdderBusinessLogic adder = new AdderBusinessLogic();
59 adder.startSum("foo");
60 assertThat(adder.endSum("foo")).isNotNull();
64 @DisplayName("An existing Sum returns a non-negative value, if ended")
65 public void testEndSumReturnsNonNegativeValueIfSumExists()
67 AdderBusinessLogic adder = new AdderBusinessLogic();
68 adder.startSum("foo");
69 assertThat(adder.endSum("foo")).isNotNegative();
73 @DisplayName("Ending a non-existing sum, causes an IllegalStateException")
74 public void testEndSumCausesExceptionIfNotExists()
76 AdderBusinessLogic adder = new AdderBusinessLogic();
77 assertThatIllegalStateException().isThrownBy(() -> adder.endSum("foo"));