1 | package fr.sii.ogham.testing.assertion.sms; | |
2 | ||
3 | import static fr.sii.ogham.testing.assertion.util.AssertionHelper.assertThat; | |
4 | import static fr.sii.ogham.testing.assertion.util.AssertionHelper.overrideDescription; | |
5 | import static org.hamcrest.Matchers.lessThan; | |
6 | ||
7 | import java.util.Collection; | |
8 | import java.util.List; | |
9 | ||
10 | import org.hamcrest.Matcher; | |
11 | ||
12 | import fr.sii.ogham.testing.assertion.util.AssertionRegistry; | |
13 | import fr.sii.ogham.testing.sms.simulator.bean.SubmitSm; | |
14 | ||
15 | /** | |
16 | * Make assertions on received messages | |
17 | * | |
18 | * @author Aurélien Baudet | |
19 | * | |
20 | * @param <S> | |
21 | * the type of the {@link SubmitSm} to make assertions on | |
22 | */ | |
23 | public class FluentReceivedSmsAssert<S extends SubmitSm> { | |
24 | /** | |
25 | * List of received messages | |
26 | */ | |
27 | private final List<S> actual; | |
28 | /** | |
29 | * the registry for assertions | |
30 | */ | |
31 | private final AssertionRegistry registry; | |
32 | ||
33 | /** | |
34 | * Initializes with the list of received messages | |
35 | * | |
36 | * @param actual | |
37 | * received messages | |
38 | * @param registry | |
39 | * used to register assertions | |
40 | */ | |
41 | public FluentReceivedSmsAssert(List<S> actual, AssertionRegistry registry) { | |
42 | this.actual = actual; | |
43 | this.registry = registry; | |
44 | } | |
45 | ||
46 | /** | |
47 | * Access fluent API to write assertions on a particular received message. | |
48 | * | |
49 | * If you want to make assertions on several messages, you may prefer using: | |
50 | * | |
51 | * <pre> | |
52 | * .receivedMessages().message(0) | |
53 | * .content(is("foobar")) | |
54 | * .and() | |
55 | * .message(1) | |
56 | * .content(is("bar")) | |
57 | * </pre> | |
58 | * | |
59 | * @param index | |
60 | * the index of the received message | |
61 | * @return the fluent API for assertions on the particular message | |
62 | */ | |
63 | public FluentSmsAssert<FluentReceivedSmsAssert<S>, S> receivedMessage(int index) { | |
64 |
4
1. lambda$receivedMessage$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE 2. receivedMessage : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 3. lambda$receivedMessage$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED 4. receivedMessage : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED |
registry.register(() -> assertThat(index, overrideDescription("Assertions on message "+index+" can't be executed because "+actual.size()+" messages were received", lessThan(actual.size())))); |
65 |
6
1. receivedMessage : changed conditional boundary → NO_COVERAGE 2. receivedMessage : negated conditional → NO_COVERAGE 3. receivedMessage : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentReceivedSmsAssert::receivedMessage → NO_COVERAGE 4. receivedMessage : changed conditional boundary → KILLED 5. receivedMessage : negated conditional → KILLED 6. receivedMessage : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentReceivedSmsAssert::receivedMessage → KILLED |
return new FluentSmsAssert<>(index<actual.size() ? actual.get(index) : null, index, this, registry); |
66 | } | |
67 | ||
68 | /** | |
69 | * Fluent API to write assertions on received messages. | |
70 | * | |
71 | * You can write assertions for all messages or a particular message. | |
72 | * | |
73 | * For example, for writing assertion on a single message, you can write: | |
74 | * | |
75 | * <pre> | |
76 | * .receivedMessages().message(0) | |
77 | * .content(is("foobar")) | |
78 | * </pre> | |
79 | * | |
80 | * For writing assertions that are applied on every received message, you | |
81 | * can write: | |
82 | * | |
83 | * <pre> | |
84 | * .receivedMessages().every() | |
85 | * .content(is("foobar")) | |
86 | * </pre> | |
87 | * | |
88 | * Will check that content of every message is "foobar". | |
89 | * | |
90 | * <p> | |
91 | * You can use this method to factorize several assertions on a message and | |
92 | * then make dedicated assertions on some messages: | |
93 | * | |
94 | * <pre> | |
95 | * .receivedMessages().every() | |
96 | * .content(is("foobar")) | |
97 | * .and() | |
98 | * .message(0) | |
99 | * .from().number(is("+33102030405")) | |
100 | * </pre> | |
101 | * | |
102 | * Will check that content of every message is "foobar" and that phone | |
103 | * nuumber of sender of first received message is "+33102030405". | |
104 | * | |
105 | * @return the fluent API for assertions on messages | |
106 | */ | |
107 | public FluentSmsListAssert<FluentReceivedSmsAssert<S>, S> receivedMessages() { | |
108 |
5
1. receivedMessages : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentReceivedSmsAssert::receivedMessages → NO_COVERAGE 2. receivedMessages : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentReceivedSmsAssert::receivedMessages → TIMED_OUT 3. receivedMessages : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentReceivedSmsAssert::receivedMessages → KILLED 4. receivedMessages : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentReceivedSmsAssert::receivedMessages → KILLED 5. receivedMessages : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentReceivedSmsAssert::receivedMessages → KILLED |
return new FluentSmsListAssert<>(actual, this, registry); |
109 | } | |
110 | ||
111 | /** | |
112 | * Fluent API to write assertions on received messages. | |
113 | * | |
114 | * Make an assertion on received messages list (JavaMail message). | |
115 | * | |
116 | * For example, for writing assertion on a single message, you can write: | |
117 | * | |
118 | * <pre> | |
119 | * .receivedMessages(is(Matchers.<Message>empty())) | |
120 | * </pre> | |
121 | * | |
122 | * @param matcher | |
123 | * the assertion to apply on message list | |
124 | * @return the fluent API for assertions on messages | |
125 | */ | |
126 | public FluentSmsListAssert<FluentReceivedSmsAssert<S>, S> receivedMessages(Matcher<Collection<? extends S>> matcher) { | |
127 |
4
1. lambda$receivedMessages$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE 2. receivedMessages : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 3. lambda$receivedMessages$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED 4. receivedMessages : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED |
registry.register(() -> assertThat("Received messages", actual, matcher)); |
128 |
2
1. receivedMessages : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentReceivedSmsAssert::receivedMessages → NO_COVERAGE 2. receivedMessages : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentReceivedSmsAssert::receivedMessages → SURVIVED |
return receivedMessages(); |
129 | } | |
130 | ||
131 | } | |
Mutations | ||
64 |
1.1 2.2 3.3 4.4 |
|
65 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
108 |
1.1 2.2 3.3 4.4 5.5 |
|
127 |
1.1 2.2 3.3 4.4 |
|
128 |
1.1 2.2 |