-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOrderEventStoreTest.java
95 lines (75 loc) · 3.39 KB
/
OrderEventStoreTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.imc.school;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.function.Predicate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
class OrderEventStoreTest {
private OrderEventStore theSubject;
@BeforeEach
void setUp() {
theSubject = new OrderEventStore();
}
@Test
void event1OrderIdsAreAllValid() {
// EXAMPLE: Assertj has some great support for working with collections.
// E.g., you can extract data from each element and apply predicates on them.
// Predicate has good support for composition.
assertThat(theSubject.getEvent(1).orders())
.extracting(OrderInfo::orderId)
.allMatch(Predicate.not(String::isEmpty));
}
@Test
void event1OrdersAreSentOnTheCorrectBook() {
// TODO: Ensure the book is "RDSA" in the following assertion.
// assertThat(theSubject.getEvent(1)).extracting(Orders::book) /* Fill me in */);
fail("This test needs to be implemented.");
}
@Test
void event1ExpectedPrices() {
// The collection based Assertj assertions are better than testing individual elements in a for loop as they
// express the intent of the testing better and produce better error messages that provide context. E.g. Using
// contains...InAnyOrder() vs contains...() informs the developer whether the order matters or not.
// TODO: use assertThat to extract a field and contains...() to ensure
// that the prices are 1.23, 1.24, 1.25 in this order.
// Matching doubles is not as trivial as matching ints. Take that into account.
// Hint: you can specify an element comparator.
fail("This test needs to be implemented.");
}
@Test
void event1AllOrdersAreBuySide() {
// TODO: You should be able to work this one out from the test name.
fail("This test needs to be implemented.");
}
@Test
void event1OrderIdsStartWithEventDash1() {
// TODO: Ensure that all order ids for event 1 start with the text "event1-"
// assertThat(theSubject.getEvent(1).orders()) /* Fill me in */;
fail("This test needs to be implemented.");
}
@Test
void event1ExpectedOrders() {
// TODO: Write a *single* assertThat statement that verifies the following orders.
// The expected orders (the order does not matter):
// Price | Volume
// 1.23 | 100
// 1.24 | 200
// 1.25 | 300
// Note: You are allowed to use only one extracting() and one contains...().
fail("This test needs to be implemented.");
}
@Test
void event2OrdersAreEmpty() {
// TODO: Use the *most* appropriate and readable assertion to ensure the collection is empty.
// Note: Don't use `...size()).isEqualTo(0)`. You can do better than that.
// assertThat(theSubject.getEvent(2).orders()) /* Fill me in */
fail("This test needs to be implemented.");
}
@Test
void unknownEventIdThrows() {
// TODO: Find an appropriate assertion to ensure an exception of type IllegalArgumentException
// with the message "Event not received: 999" is thrown when the event 999 does not exist.
// Use `theSubject.getEvent(999)`
fail("This test needs to be implemented.");
}
}