import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
public class SumBusinessLogic
state.put(user, 0l);
}
+
+ public synchronized Optional<Long> getSum(String user)
+ {
+ return Optional.empty();
+ }
}
sumBusinessLogic.startSum("foo");
assertThatIllegalStateException().isThrownBy(() -> sumBusinessLogic.startSum("foo"));
}
+
+ @Test
+ @DisplayName("An empty Optional should be returned, for a non-existing sum")
+ public void testEmptyOptionalForNonExistingSum()
+ {
+ SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
+ assertThat(sumBusinessLogic.getSum("foo")).isEmpty();
+ }
+
+ @Test
+ @DisplayName("A non-empty Optional should be returned, for an existing sum")
+ public void testNonEmptyOptionalForExistingSum()
+ {
+ SumBusinessLogic sumBusinessLogic = new SumBusinessLogic();
+ sumBusinessLogic.startSum("foo");
+ assertThat(sumBusinessLogic.getSum("foo")).isNotEmpty();
+ }
}