| 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.usingContext; | |
| 5 | import static fr.sii.ogham.testing.sms.simulator.decode.SmsUtils.getSmsContent; | |
| 6 | ||
| 7 | import java.util.ArrayList; | |
| 8 | import java.util.Arrays; | |
| 9 | import java.util.List; | |
| 10 | ||
| 11 | import org.hamcrest.Matcher; | |
| 12 | ||
| 13 | import fr.sii.ogham.testing.assertion.context.SingleMessageContext; | |
| 14 | import fr.sii.ogham.testing.assertion.util.AssertionRegistry; | |
| 15 | import fr.sii.ogham.testing.sms.simulator.bean.SubmitSm; | |
| 16 | import fr.sii.ogham.testing.sms.simulator.decode.Charset; | |
| 17 | import fr.sii.ogham.testing.util.HasParent; | |
| 18 | ||
| 19 | /** | |
| 20 | * Make assertions on particular message. | |
| 21 | * | |
| 22 | * @author Aurélien Baudet | |
| 23 | * | |
| 24 | * @param <P> | |
| 25 | * the parent type | |
| 26 | * @param <S> | |
| 27 | * the type of the {@link SubmitSm} | |
| 28 | */ | |
| 29 | public class FluentSmsAssert<P, S extends SubmitSm> extends HasParent<P> { | |
| 30 | /** | |
| 31 | * The list of messages that will be used for assertions | |
| 32 | */ | |
| 33 | private final List<S> actual; | |
| 34 | private int index; | |
| 35 | private final AssertionRegistry registry; | |
| 36 | ||
| 37 | /** | |
| 38 | * Initializes with a single received message | |
| 39 | * | |
| 40 | * @param actual | |
| 41 | * received message | |
| 42 | * @param index | |
| 43 | * the index of the message | |
| 44 | * @param parent | |
| 45 | * the parent | |
| 46 | * @param registry | |
| 47 | * used to register assertions | |
| 48 | */ | |
| 49 | public FluentSmsAssert(S actual, int index, P parent, AssertionRegistry registry) { | |
| 50 | this(Arrays.asList(actual), parent, registry); | |
| 51 | this.index = index; | |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * Initializes with several received messages | |
| 56 | * | |
| 57 | * @param actual | |
| 58 | * received messages | |
| 59 | * @param parent | |
| 60 | * the parent | |
| 61 | * @param registry | |
| 62 | * used to register assertions | |
| 63 | */ | |
| 64 | public FluentSmsAssert(List<S> actual, P parent, AssertionRegistry registry) { | |
| 65 | super(parent); | |
| 66 | this.actual = actual; | |
| 67 | this.registry = registry; | |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * Make assertions on the content of the message(s). Alphabet/encoding is | |
| 72 | * automatically determined from message (based on Data Coding Scheme). | |
| 73 | * | |
| 74 | * <pre> | |
| 75 | * .receivedMessages().message(0) | |
| 76 | * .content(allOf(notNullValue(), is("hello world")) | |
| 77 | * </pre> | |
| 78 | * | |
| 79 | * Or: | |
| 80 | * | |
| 81 | * <pre> | |
| 82 | * .receivedMessages().message(0) | |
| 83 | * .content(notNullValue()) | |
| 84 | * .content(is("hello world")) | |
| 85 | * </pre> | |
| 86 | * | |
| 87 | * Will check if the content of the first message is not null and is exactly | |
| 88 | * "hello world". | |
| 89 | * | |
| 90 | * <pre> | |
| 91 | * .receivedMessages().every() | |
| 92 | * .content(allOf(notNullValue(), is("hello world")) | |
| 93 | * </pre> | |
| 94 | * | |
| 95 | * Or: | |
| 96 | * | |
| 97 | * <pre> | |
| 98 | * .receivedMessages().every() | |
| 99 | * .content(notNullValue()) | |
| 100 | * .content(is("hello world")) | |
| 101 | * </pre> | |
| 102 | * | |
| 103 | * Will check if the content of every message is not null and is exactly | |
| 104 | * "hello world". | |
| 105 | * | |
| 106 | * @param matcher | |
| 107 | * the assertion to apply on message content | |
| 108 | * @return the fluent API for chaining assertions on received message(s) | |
| 109 | */ | |
| 110 | public FluentSmsAssert<P, S> content(Matcher<? super String> matcher) { | |
| 111 | String desc = "content of message ${messageIndex}"; | |
| 112 | int msgIdx = index; | |
| 113 | for (S message : actual) { | |
| 114 | final int idx = msgIdx; | |
| 115 |
8
1. content : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 2. content : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 3. lambda$content$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED 4. lambda$content$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE 5. content : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → TIMED_OUT 6. lambda$content$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → TIMED_OUT 7. content : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 8. lambda$content$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED |
registry.register(() -> assertThat(getSmsContent(message), usingContext(desc, new SingleMessageContext(idx), matcher))); |
| 116 |
4
1. content : Changed increment from 1 to -1 → NO_COVERAGE 2. content : Changed increment from 1 to -1 → SURVIVED 3. content : Changed increment from 1 to -1 → TIMED_OUT 4. content : Changed increment from 1 to -1 → KILLED |
msgIdx++; |
| 117 | } | |
| 118 |
5
1. content : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::content → NO_COVERAGE 2. content : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::content → TIMED_OUT 3. content : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::content → KILLED 4. content : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::content → KILLED 5. content : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::content → KILLED |
return this; |
| 119 | } | |
| 120 | ||
| 121 | /** | |
| 122 | * Make assertions on the content of the message(s). Alphabet/encoding used | |
| 123 | * to decode the message is explicitly provided. | |
| 124 | * | |
| 125 | * <pre> | |
| 126 | * .receivedMessages().message(0) | |
| 127 | * .content(allOf(notNullValue(), is("hello world")) | |
| 128 | * </pre> | |
| 129 | * | |
| 130 | * Or: | |
| 131 | * | |
| 132 | * <pre> | |
| 133 | * .receivedMessages().message(0) | |
| 134 | * .content(notNullValue()) | |
| 135 | * .content(is("hello world")) | |
| 136 | * </pre> | |
| 137 | * | |
| 138 | * Will check if the content of the first message is not null and is exactly | |
| 139 | * "hello world". | |
| 140 | * | |
| 141 | * <pre> | |
| 142 | * .receivedMessages().every() | |
| 143 | * .content(allOf(notNullValue(), is("hello world")) | |
| 144 | * </pre> | |
| 145 | * | |
| 146 | * Or: | |
| 147 | * | |
| 148 | * <pre> | |
| 149 | * .receivedMessages().every() | |
| 150 | * .content(notNullValue()) | |
| 151 | * .content(is("hello world")) | |
| 152 | * </pre> | |
| 153 | * | |
| 154 | * Will check if the content of every message is not null and is exactly | |
| 155 | * "hello world". | |
| 156 | * | |
| 157 | * @param charset | |
| 158 | * the charset to use to decode the message (bytes to string) | |
| 159 | * @param matcher | |
| 160 | * the assertion to apply on message content | |
| 161 | * @return the fluent API for chaining assertions on received message(s) | |
| 162 | */ | |
| 163 | public FluentSmsAssert<P, S> content(Charset charset, Matcher<? super String> matcher) { | |
| 164 | String desc = "content of message ${messageIndex}"; | |
| 165 | int msgIdx = index; | |
| 166 | for (S message : actual) { | |
| 167 | final int idx = msgIdx; | |
| 168 |
4
1. content : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 2. lambda$content$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE 3. content : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 4. lambda$content$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED |
registry.register(() -> assertThat(getSmsContent(message, charset), usingContext(desc, new SingleMessageContext(idx), matcher))); |
| 169 |
2
1. content : Changed increment from 1 to -1 → NO_COVERAGE 2. content : Changed increment from 1 to -1 → KILLED |
msgIdx++; |
| 170 | } | |
| 171 |
2
1. content : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::content → NO_COVERAGE 2. content : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::content → KILLED |
return this; |
| 172 | } | |
| 173 | ||
| 174 | /** | |
| 175 | * Make assertions on the raw request ({@link SubmitSm}) of the message(s) | |
| 176 | * using fluent API. | |
| 177 | * | |
| 178 | * <pre> | |
| 179 | * .receivedMessages().message(0).rawRequest() | |
| 180 | * .alphabet(is(Alphabet.ALPHA_DEFAULT)) | |
| 181 | * .shortMessage() | |
| 182 | * .header(array(equalTo(0x01), equalTo(0x02), equalTo(0x03)))) | |
| 183 | * .payload(arrayWithSize(10)) | |
| 184 | * </pre> | |
| 185 | * | |
| 186 | * Will check if the received byte array of the first message has a header | |
| 187 | * with some expected bytes, the alphabet used to encode the message is | |
| 188 | * ALPHA_DEFAULT and the payload has exactly 10 bytes. | |
| 189 | * | |
| 190 | * <pre> | |
| 191 | * .receivedMessages().every().rawRequest() | |
| 192 | * .alphabet(is(Alphabet.ALPHA_DEFAULT)) | |
| 193 | * .shortMessage() | |
| 194 | * .header(array(equalTo(0x01), equalTo(0x02), equalTo(0x03)))) | |
| 195 | * .payload(arrayWithSize(10)) | |
| 196 | * </pre> | |
| 197 | * | |
| 198 | * Will check if the received byte array of every message has a header with | |
| 199 | * some expected bytes, the alphabet used to encode the message is | |
| 200 | * ALPHA_DEFAULT and the payload has exactly 10 bytes. | |
| 201 | * | |
| 202 | * @return the fluent API for chaining assertions on received message(s) | |
| 203 | */ | |
| 204 | public FluentPduRequestAssert<FluentSmsAssert<P, S>, S> rawRequest() { | |
| 205 | List<PduRequestWithContext<S>> requests = new ArrayList<>(); | |
| 206 | int msgIdx = index; | |
| 207 | for (S request : actual) { | |
| 208 | requests.add(new PduRequestWithContext<>(request, "raw request", new SingleMessageContext(msgIdx))); | |
| 209 |
3
1. rawRequest : Changed increment from 1 to -1 → NO_COVERAGE 2. rawRequest : Changed increment from 1 to -1 → SURVIVED 3. rawRequest : Changed increment from 1 to -1 → KILLED |
msgIdx++; |
| 210 | } | |
| 211 |
4
1. rawRequest : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::rawRequest → NO_COVERAGE 2. rawRequest : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::rawRequest → KILLED 3. rawRequest : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::rawRequest → KILLED 4. rawRequest : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::rawRequest → KILLED |
return new FluentPduRequestAssert<>(requests, this, registry); |
| 212 | } | |
| 213 | ||
| 214 | /** | |
| 215 | * Make assertions on the sender of the message(s) using fluent API. | |
| 216 | * | |
| 217 | * <pre> | |
| 218 | * .receivedMessages().message(0) | |
| 219 | * .from(notNullValue()) | |
| 220 | * </pre> | |
| 221 | * | |
| 222 | * Will check if the sender phone number of the first message is not null. | |
| 223 | * | |
| 224 | * <pre> | |
| 225 | * .receivedMessages().every() | |
| 226 | * .from(notNullValue()) | |
| 227 | * </pre> | |
| 228 | * | |
| 229 | * Will check if the sender phone number of every message is not null. | |
| 230 | * | |
| 231 | * @param matcher | |
| 232 | * the assertion to apply on the phone number | |
| 233 | * @return the fluent API for chaining assertions on received message(s) | |
| 234 | */ | |
| 235 | public FluentSmsAssert<P, S> from(Matcher<PhoneNumberInfo> matcher) { | |
| 236 | String desc = "sender of message ${messageIndex}"; | |
| 237 | int msgIdx = index; | |
| 238 | for (S message : actual) { | |
| 239 | PhoneNumberInfo number = new PhoneNumberInfo(message.getSourceAddress()); | |
| 240 | final int idx = msgIdx; | |
| 241 |
4
1. from : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 2. lambda$from$2 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE 3. from : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED 4. lambda$from$2 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED |
registry.register(() -> assertThat(number, usingContext(desc, new SingleMessageContext(idx), matcher))); |
| 242 |
2
1. from : Changed increment from 1 to -1 → NO_COVERAGE 2. from : Changed increment from 1 to -1 → KILLED |
msgIdx++; |
| 243 | } | |
| 244 |
2
1. from : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::from → NO_COVERAGE 2. from : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::from → KILLED |
return this; |
| 245 | } | |
| 246 | ||
| 247 | /** | |
| 248 | * Make assertions on the sender of the message(s) using fluent API. | |
| 249 | * | |
| 250 | * <pre> | |
| 251 | * .receivedMessages().message(0).from() | |
| 252 | * .number(is("+33102030405")) | |
| 253 | * .typeOfNumber(is(TypeOfNumber.INTERNATIONAL)) | |
| 254 | * </pre> | |
| 255 | * | |
| 256 | * Will check if the sender phone number of the first message is exactly | |
| 257 | * "+33102030405" and sender phone number type of the first message is an | |
| 258 | * international number. | |
| 259 | * | |
| 260 | * <pre> | |
| 261 | * .receivedMessages().every().from() | |
| 262 | * .number(is("+33102030405")) | |
| 263 | * .typeOfNumber(is(TypeOfNumber.INTERNATIONAL)) | |
| 264 | * </pre> | |
| 265 | * | |
| 266 | * Will check if the sender phone number of every message is exactly | |
| 267 | * "+33102030405" and sender phone number type of every message is an | |
| 268 | * international number. | |
| 269 | * | |
| 270 | * @return the fluent API for chaining assertions on received message(s) | |
| 271 | */ | |
| 272 | public FluentPhoneNumberAssert<FluentSmsAssert<P, S>> from() { | |
| 273 | List<PhoneNumberWithContext> numbers = new ArrayList<>(); | |
| 274 | int msgIdx = index; | |
| 275 | for (S message : actual) { | |
| 276 | PhoneNumberInfo number = new PhoneNumberInfo(message.getSourceAddress()); | |
| 277 | numbers.add(new PhoneNumberWithContext(number, "sender", new SingleMessageContext(msgIdx))); | |
| 278 |
3
1. from : Changed increment from 1 to -1 → SURVIVED 2. from : Changed increment from 1 to -1 → NO_COVERAGE 3. from : Changed increment from 1 to -1 → KILLED |
msgIdx++; |
| 279 | } | |
| 280 |
4
1. from : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::from → NO_COVERAGE 2. from : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::from → KILLED 3. from : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::from → KILLED 4. from : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::from → KILLED |
return new FluentPhoneNumberAssert<>(numbers, this, registry); |
| 281 | } | |
| 282 | ||
| 283 | /** | |
| 284 | * Make assertions on the recipient of the message(s) using fluent API. | |
| 285 | * | |
| 286 | * <pre> | |
| 287 | * .receivedMessages().message(0) | |
| 288 | * .to(notNullValue()) | |
| 289 | * </pre> | |
| 290 | * | |
| 291 | * Will check if the recipient phone number of the first message is not | |
| 292 | * null. | |
| 293 | * | |
| 294 | * <pre> | |
| 295 | * .receivedMessages().every() | |
| 296 | * .to(notNullValue()) | |
| 297 | * </pre> | |
| 298 | * | |
| 299 | * Will check if the recipient phone number of every message is not null. | |
| 300 | * | |
| 301 | * @param matcher | |
| 302 | * the assertion to apply on the phone number | |
| 303 | * @return the fluent API for chaining assertions on received message(s) | |
| 304 | */ | |
| 305 | public FluentSmsAssert<P, S> to(Matcher<PhoneNumberInfo> matcher) { | |
| 306 | String desc = "recipient of message ${messageIndex}"; | |
| 307 | int msgIdx = index; | |
| 308 | for (S message : actual) { | |
| 309 | PhoneNumberInfo number = new PhoneNumberInfo(message.getDestAddress()); | |
| 310 | final int idx = msgIdx; | |
| 311 |
4
1. lambda$to$3 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE 2. to : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 3. lambda$to$3 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED 4. to : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED |
registry.register(() -> assertThat(number, usingContext(desc, new SingleMessageContext(idx), matcher))); |
| 312 |
2
1. to : Changed increment from 1 to -1 → NO_COVERAGE 2. to : Changed increment from 1 to -1 → KILLED |
msgIdx++; |
| 313 | } | |
| 314 |
2
1. to : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::to → NO_COVERAGE 2. to : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::to → KILLED |
return this; |
| 315 | } | |
| 316 | ||
| 317 | /** | |
| 318 | * Make assertions on the recipient of the message(s) using fluent API. | |
| 319 | * | |
| 320 | * <pre> | |
| 321 | * .receivedMessages().message(0).to() | |
| 322 | * .number(is("+33102030405")) | |
| 323 | * .typeOfNumber(is(TypeOfNumber.INTERNATIONAL)) | |
| 324 | * </pre> | |
| 325 | * | |
| 326 | * Will check if the recipient phone number of the first message is exactly | |
| 327 | * "+33102030405" and recipient phone number type of the first message is an | |
| 328 | * international number. | |
| 329 | * | |
| 330 | * <pre> | |
| 331 | * .receivedMessages().every().to() | |
| 332 | * .number(is("+33102030405")) | |
| 333 | * .typeOfNumber(is(TypeOfNumber.INTERNATIONAL)) | |
| 334 | * </pre> | |
| 335 | * | |
| 336 | * Will check if the recipient phone number of every message is exactly | |
| 337 | * "+33102030405" and recipient phone number type of every message is an | |
| 338 | * international number. | |
| 339 | * | |
| 340 | * @return the fluent API for chaining assertions on received message(s) | |
| 341 | */ | |
| 342 | public FluentPhoneNumberAssert<FluentSmsAssert<P, S>> to() { | |
| 343 | List<PhoneNumberWithContext> numbers = new ArrayList<>(); | |
| 344 | int msgIdx = index; | |
| 345 | for (S message : actual) { | |
| 346 | PhoneNumberInfo number = new PhoneNumberInfo(message.getDestAddress()); | |
| 347 | numbers.add(new PhoneNumberWithContext(number, "recipient", new SingleMessageContext(msgIdx))); | |
| 348 |
3
1. to : Changed increment from 1 to -1 → NO_COVERAGE 2. to : Changed increment from 1 to -1 → SURVIVED 3. to : Changed increment from 1 to -1 → KILLED |
msgIdx++; |
| 349 | } | |
| 350 |
4
1. to : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::to → NO_COVERAGE 2. to : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::to → KILLED 3. to : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::to → KILLED 4. to : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentSmsAssert::to → KILLED |
return new FluentPhoneNumberAssert<>(numbers, this, registry); |
| 351 | } | |
| 352 | ||
| 353 | } | |
Mutations | ||
| 115 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 116 |
1.1 2.2 3.3 4.4 |
|
| 118 |
1.1 2.2 3.3 4.4 5.5 |
|
| 168 |
1.1 2.2 3.3 4.4 |
|
| 169 |
1.1 2.2 |
|
| 171 |
1.1 2.2 |
|
| 209 |
1.1 2.2 3.3 |
|
| 211 |
1.1 2.2 3.3 4.4 |
|
| 241 |
1.1 2.2 3.3 4.4 |
|
| 242 |
1.1 2.2 |
|
| 244 |
1.1 2.2 |
|
| 278 |
1.1 2.2 3.3 |
|
| 280 |
1.1 2.2 3.3 4.4 |
|
| 311 |
1.1 2.2 3.3 4.4 |
|
| 312 |
1.1 2.2 |
|
| 314 |
1.1 2.2 |
|
| 348 |
1.1 2.2 3.3 |
|
| 350 |
1.1 2.2 3.3 4.4 |