ROT: Erwartungen an SumBusinessLogic.endSum(String)
[demos/kafka/training] / src / test / java / de / juplo / kafka / SumBusinessLogicTest.java
1 package de.juplo.kafka;
2
3 import org.junit.jupiter.api.DisplayName;
4 import org.junit.jupiter.api.Test;
5
6 import static org.assertj.core.api.Assertions.*;
7
8
9 public class SumBusinessLogicTest
10 {
11   @Test
12   @DisplayName("A new sum can be started, if it does not exist")
13   public void testCanStartSumIfNotExists()
14   {
15     SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
16     assertThatNoException().isThrownBy(() -> sumBusinessLogic.startSum("foo"));
17   }
18
19   @Test
20   @DisplayName("Starting an already existing sum again, causes an IllegalStateException")
21   public void testStartSumCausesExceptionIfExists()
22   {
23     SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
24     sumBusinessLogic.startSum("foo");
25     assertThatIllegalStateException().isThrownBy(() -> sumBusinessLogic.startSum("foo"));
26   }
27
28   @Test
29   @DisplayName("An empty Optional should be returned, for a non-existing sum")
30   public void testEmptyOptionalForNonExistingSum()
31   {
32     SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
33     assertThat(sumBusinessLogic.getSum("foo")).isEmpty();
34   }
35
36   @Test
37   @DisplayName("A non-empty Optional should be returned, for an existing sum")
38   public void testNonEmptyOptionalForExistingSum()
39   {
40     SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
41     sumBusinessLogic.startSum("foo");
42     assertThat(sumBusinessLogic.getSum("foo")).isNotEmpty();
43   }
44
45   @Test
46   @DisplayName("A sum can be ended, if it does exist")
47   public void testCanEndIfSumExists()
48   {
49     SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
50     sumBusinessLogic.startSum("foo");
51     assertThatNoException().isThrownBy(() -> sumBusinessLogic.endSum("foo"));
52   }
53
54   @Test
55   @DisplayName("An existing Sum returns a non-null value, if ended")
56   public void testEndSumReturnsNonNullValueIfSumExists()
57   {
58     SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
59     sumBusinessLogic.startSum("foo");
60     assertThat(sumBusinessLogic.endSum("foo")).isNotNull();
61   }
62
63   @Test
64   @DisplayName("An existing Sum returns a non-negative value, if ended")
65   public void testEndSumReturnsNonNegativeValueIfSumExists()
66   {
67     SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
68     sumBusinessLogic.startSum("foo");
69     assertThat(sumBusinessLogic.endSum("foo")).isNotNegative();
70   }
71
72   @Test
73   @DisplayName("Ending a non-existing sum, causes an IllegalStateException")
74   public void testEndSumCausesExceptionIfNotExists()
75   {
76     SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
77     assertThatIllegalStateException().isThrownBy(() -> sumBusinessLogic.endSum("foo"));
78   }
79 }