1 | package fr.sii.ogham.testing.assertion.sms; | |
2 | ||
3 | import static fr.sii.ogham.testing.sms.simulator.decode.SmsUtils.getSmsContent; | |
4 | ||
5 | import java.util.List; | |
6 | import java.util.function.Function; | |
7 | ||
8 | import org.junit.Assert; | |
9 | ||
10 | import fr.sii.ogham.testing.assertion.util.AssertionRegistry; | |
11 | import fr.sii.ogham.testing.assertion.util.FailAtEndRegistry; | |
12 | import fr.sii.ogham.testing.sms.simulator.bean.Address; | |
13 | import fr.sii.ogham.testing.sms.simulator.bean.SubmitSm; | |
14 | ||
15 | /** | |
16 | * Utility class for checking if the received SMS content is as expected. | |
17 | * | |
18 | * @author Aurélien Baudet | |
19 | * | |
20 | */ | |
21 | public final class AssertSms { | |
22 | ||
23 | /** | |
24 | * Assert that the fields of the received SMS using SMPP protocol are equal | |
25 | * to the expected values. It will check that: | |
26 | * <ul> | |
27 | * <li>The received sender address corresponds to the expected phone number | |
28 | * of the sender</li> | |
29 | * <li>The received receiver address corresponds to the expected phone | |
30 | * number of the receiver</li> | |
31 | * <li>The received message corresponds to the expected message</li> | |
32 | * </ul> | |
33 | * | |
34 | * @param expected | |
35 | * all the fields with their expected values | |
36 | * @param actual | |
37 | * the received SMS | |
38 | */ | |
39 | public static void assertEquals(ExpectedSms expected, SubmitSm actual) { | |
40 | AssertionRegistry registry = new FailAtEndRegistry(); | |
41 |
2
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → KILLED |
assertEquals("1/1", expected, actual, registry); |
42 |
2
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → KILLED |
registry.execute(); |
43 | } | |
44 | ||
45 | /** | |
46 | * Assert that the fields of the received SMS using SMPP protocol are equal | |
47 | * to the expected values. It will check that: | |
48 | * <ul> | |
49 | * <li>The received sender address corresponds to the expected phone number | |
50 | * of the sender</li> | |
51 | * <li>The received receiver address corresponds to the expected phone | |
52 | * number of the receiver</li> | |
53 | * <li>The received message corresponds to the expected message</li> | |
54 | * </ul> | |
55 | * <p> | |
56 | * It also checks that there is exactly one received message. | |
57 | * </p> | |
58 | * <p> | |
59 | * This is a shortcut useful in unit testing. | |
60 | * </p> | |
61 | * | |
62 | * @param expected | |
63 | * all the fields with their expected values | |
64 | * @param receivedMessages | |
65 | * the list of received SMS | |
66 | */ | |
67 | public static void assertEquals(ExpectedSms expected, List<SubmitSm> receivedMessages) { | |
68 | AssertionRegistry registry = new FailAtEndRegistry(); | |
69 |
4
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 2. lambda$assertEquals$0 : removed call to org/junit/Assert::assertEquals → NO_COVERAGE 3. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 4. lambda$assertEquals$0 : removed call to org/junit/Assert::assertEquals → KILLED |
registry.register(() -> Assert.assertEquals("should have received exactly one message", 1, receivedMessages.size())); |
70 |
4
1. assertEquals : negated conditional → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → NO_COVERAGE 3. assertEquals : negated conditional → KILLED 4. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → KILLED |
assertEquals("1/1", expected, receivedMessages.size()==1 ? receivedMessages.get(0) : null, registry); |
71 |
2
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → KILLED |
registry.execute(); |
72 | } | |
73 | ||
74 | /** | |
75 | * Assert that the fields of each received SMS using SMPP protocol are equal | |
76 | * to values of each expected message. For each message, it will check that: | |
77 | * <ul> | |
78 | * <li>The received sender address corresponds to the expected phone number | |
79 | * of the sender</li> | |
80 | * <li>The received receiver address corresponds to the expected phone | |
81 | * number of the receiver</li> | |
82 | * <li>The received message corresponds to the expected message</li> | |
83 | * </ul> | |
84 | * <p> | |
85 | * It also checks that there are exactly the same number of received message | |
86 | * as the expected number. | |
87 | * </p> | |
88 | * | |
89 | * @param expected | |
90 | * all the fields with their expected values | |
91 | * @param receivedMessages | |
92 | * the received SMS | |
93 | */ | |
94 | public static void assertEquals(List<ExpectedSms> expected, List<SubmitSm> receivedMessages) { | |
95 | AssertionRegistry registry = new FailAtEndRegistry(); | |
96 |
3
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → SURVIVED 3. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → KILLED |
assertEquals(expected, receivedMessages, registry); |
97 |
3
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → SURVIVED 3. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → KILLED |
registry.execute(); |
98 | } | |
99 | ||
100 | /** | |
101 | * <p> | |
102 | * When message is too long, the SMS is split into several parts. This | |
103 | * method helps to check this case. | |
104 | * </p> | |
105 | * Assert that the fields of each received SMS using SMPP protocol are equal | |
106 | * to values of each expected message part. For each message part, it will | |
107 | * check that: | |
108 | * <ul> | |
109 | * <li>The received sender address corresponds to the expected phone number | |
110 | * of the sender</li> | |
111 | * <li>The received receiver address corresponds to the expected phone | |
112 | * number of the receiver</li> | |
113 | * <li>The received message corresponds to the expected message</li> | |
114 | * </ul> | |
115 | * <p> | |
116 | * It also checks that there are exactly the same number of received message | |
117 | * as the expected number of parts. | |
118 | * </p> | |
119 | * | |
120 | * @param expected | |
121 | * all the fields with their expected values | |
122 | * @param receivedMessages | |
123 | * the received SMS | |
124 | */ | |
125 | public static void assertEquals(SplitSms expected, List<SubmitSm> receivedMessages) { | |
126 | AssertionRegistry registry = new FailAtEndRegistry(); | |
127 |
2
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → KILLED |
assertEquals(expected.getParts(), receivedMessages, registry); |
128 |
2
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → KILLED |
registry.execute(); |
129 | } | |
130 | ||
131 | private static void assertEquals(List<ExpectedSms> expected, List<SubmitSm> receivedMessages, AssertionRegistry registry) { | |
132 |
6
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 3. lambda$assertEquals$1 : removed call to org/junit/Assert::assertEquals → NO_COVERAGE 4. lambda$assertEquals$1 : removed call to org/junit/Assert::assertEquals → SURVIVED 5. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 6. lambda$assertEquals$1 : removed call to org/junit/Assert::assertEquals → KILLED |
registry.register(() -> Assert.assertEquals("should have received exactly " + expected.size() + " message(s)", expected.size(), receivedMessages.size())); |
133 |
6
1. assertEquals : changed conditional boundary → NO_COVERAGE 2. assertEquals : negated conditional → SURVIVED 3. assertEquals : negated conditional → NO_COVERAGE 4. assertEquals : changed conditional boundary → KILLED 5. assertEquals : changed conditional boundary → KILLED 6. assertEquals : negated conditional → KILLED |
for (int i = 0; i < expected.size(); i++) { |
134 |
12
1. assertEquals : changed conditional boundary → SURVIVED 2. assertEquals : changed conditional boundary → NO_COVERAGE 3. assertEquals : Replaced integer addition with subtraction → SURVIVED 4. assertEquals : Replaced integer addition with subtraction → NO_COVERAGE 5. assertEquals : negated conditional → NO_COVERAGE 6. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → NO_COVERAGE 7. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → SURVIVED 8. assertEquals : changed conditional boundary → KILLED 9. assertEquals : Replaced integer addition with subtraction → KILLED 10. assertEquals : negated conditional → KILLED 11. assertEquals : negated conditional → KILLED 12. assertEquals : removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → KILLED |
assertEquals((i+1)+"/"+expected.size(), expected.get(i), i<receivedMessages.size() ? receivedMessages.get(i) : null, registry); |
135 | } | |
136 | } | |
137 | ||
138 | private static void assertEquals(String msgIdx, ExpectedSms expected, SubmitSm actual, AssertionRegistry registry) { | |
139 |
6
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 3. lambda$assertEquals$2 : removed call to org/junit/Assert::assertEquals → NO_COVERAGE 4. lambda$assertEquals$2 : removed call to org/junit/Assert::assertEquals → SURVIVED 5. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 6. lambda$assertEquals$2 : removed call to org/junit/Assert::assertEquals → KILLED |
registry.register(() -> Assert.assertEquals("Sender number of message "+ msgIdx + " should be " + expected.getSenderNumber().getNumber(), expected.getSenderNumber().getNumber(), getValue(actual, SubmitSm::getSourceAddress, Address::getAddress))); |
140 |
6
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 3. lambda$assertEquals$3 : removed call to org/junit/Assert::assertEquals → SURVIVED 4. lambda$assertEquals$3 : removed call to org/junit/Assert::assertEquals → NO_COVERAGE 5. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 6. lambda$assertEquals$3 : removed call to org/junit/Assert::assertEquals → KILLED |
registry.register(() -> Assert.assertEquals("Sender ton of message "+ msgIdx + " should be " + expected.getSenderNumber().getTon(), (Byte) expected.getSenderNumber().getTon(), getValue(actual, SubmitSm::getSourceAddress, Address::getTon))); |
141 |
6
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 3. lambda$assertEquals$4 : removed call to org/junit/Assert::assertEquals → SURVIVED 4. lambda$assertEquals$4 : removed call to org/junit/Assert::assertEquals → NO_COVERAGE 5. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 6. lambda$assertEquals$4 : removed call to org/junit/Assert::assertEquals → KILLED |
registry.register(() -> Assert.assertEquals("Sender npi of message "+ msgIdx + " should be " + expected.getSenderNumber().getNpi(), (Byte) expected.getSenderNumber().getNpi(), getValue(actual, SubmitSm::getSourceAddress, Address::getNpi))); |
142 | ||
143 |
6
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 3. lambda$assertEquals$5 : removed call to org/junit/Assert::assertEquals → NO_COVERAGE 4. lambda$assertEquals$5 : removed call to org/junit/Assert::assertEquals → SURVIVED 5. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 6. lambda$assertEquals$5 : removed call to org/junit/Assert::assertEquals → KILLED |
registry.register(() -> Assert.assertEquals("Receiver number of message "+ msgIdx + " should be " + expected.getReceiverNumber().getNumber(), expected.getReceiverNumber().getNumber(), getValue(actual, SubmitSm::getDestAddress, Address::getAddress))); |
144 |
6
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 3. lambda$assertEquals$6 : removed call to org/junit/Assert::assertEquals → NO_COVERAGE 4. lambda$assertEquals$6 : removed call to org/junit/Assert::assertEquals → SURVIVED 5. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 6. lambda$assertEquals$6 : removed call to org/junit/Assert::assertEquals → KILLED |
registry.register(() -> Assert.assertEquals("Receiver ton of message "+ msgIdx + " should be " + expected.getReceiverNumber().getTon(), (Byte) expected.getReceiverNumber().getTon(), getValue(actual, SubmitSm::getDestAddress, Address::getTon))); |
145 |
6
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 3. lambda$assertEquals$7 : removed call to org/junit/Assert::assertEquals → NO_COVERAGE 4. lambda$assertEquals$7 : removed call to org/junit/Assert::assertEquals → SURVIVED 5. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 6. lambda$assertEquals$7 : removed call to org/junit/Assert::assertEquals → KILLED |
registry.register(() -> Assert.assertEquals("Receiver npi of message "+ msgIdx + " should be " + expected.getReceiverNumber().getNpi(), (Byte) expected.getReceiverNumber().getNpi(), getValue(actual, SubmitSm::getDestAddress, Address::getNpi))); |
146 | ||
147 |
9
1. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 2. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 3. lambda$assertEquals$8 : negated conditional → NO_COVERAGE 4. lambda$assertEquals$8 : removed call to org/junit/Assert::assertEquals → NO_COVERAGE 5. lambda$assertEquals$8 : removed call to org/junit/Assert::assertEquals → SURVIVED 6. assertEquals : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 7. lambda$assertEquals$8 : negated conditional → KILLED 8. lambda$assertEquals$8 : negated conditional → KILLED 9. lambda$assertEquals$8 : removed call to org/junit/Assert::assertEquals → KILLED |
registry.register(() -> Assert.assertEquals("Message " + msgIdx + " not consistent with expected", expected.getMessage(), actual==null ? null : getSmsContent(actual))); |
148 | } | |
149 | ||
150 | private static <T> T getValue(SubmitSm actual, Function<SubmitSm, Address> addressAccessor, Function<Address, T> valueAccessor) { | |
151 |
3
1. getValue : negated conditional → NO_COVERAGE 2. getValue : negated conditional → KILLED 3. getValue : negated conditional → KILLED |
if (actual == null) { |
152 | return null; | |
153 | } | |
154 | Address address = addressAccessor.apply(actual); | |
155 |
3
1. getValue : negated conditional → NO_COVERAGE 2. getValue : negated conditional → KILLED 3. getValue : negated conditional → KILLED |
if (address == null) { |
156 | return null; | |
157 | } | |
158 |
3
1. getValue : replaced return value with null for fr/sii/ogham/testing/assertion/sms/AssertSms::getValue → NO_COVERAGE 2. getValue : replaced return value with null for fr/sii/ogham/testing/assertion/sms/AssertSms::getValue → KILLED 3. getValue : replaced return value with null for fr/sii/ogham/testing/assertion/sms/AssertSms::getValue → KILLED |
return valueAccessor.apply(address); |
159 | } | |
160 | ||
161 | private AssertSms() { | |
162 | super(); | |
163 | } | |
164 | } | |
Mutations | ||
41 |
1.1 2.2 |
|
42 |
1.1 2.2 |
|
69 |
1.1 2.2 3.3 4.4 |
|
70 |
1.1 2.2 3.3 4.4 |
|
71 |
1.1 2.2 |
|
96 |
1.1 2.2 3.3 |
|
97 |
1.1 2.2 3.3 |
|
127 |
1.1 2.2 |
|
128 |
1.1 2.2 |
|
132 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
133 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
134 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 |
|
139 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
140 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
141 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
143 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
144 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
145 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
147 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 |
|
151 |
1.1 2.2 3.3 |
|
155 |
1.1 2.2 3.3 |
|
158 |
1.1 2.2 3.3 |