| 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 org.apache.commons.lang3.ArrayUtils.toObject; | |
| 6 | ||
| 7 | import java.util.List; | |
| 8 | ||
| 9 | import org.hamcrest.Matcher; | |
| 10 | ||
| 11 | import fr.sii.ogham.testing.assertion.util.AssertionRegistry; | |
| 12 | import fr.sii.ogham.testing.sms.simulator.bean.OptionalParameter; | |
| 13 | import fr.sii.ogham.testing.sms.simulator.bean.SubmitSm; | |
| 14 | import fr.sii.ogham.testing.util.HasParent; | |
| 15 | ||
| 16 | /** | |
| 17 | * Make assertions on optional parameters of a {@link SubmitSm}. | |
| 18 | * | |
| 19 | * @author Aurélien Baudet | |
| 20 | * | |
| 21 | * @param <P> | |
| 22 | * The parent type | |
| 23 | */ | |
| 24 | public class FluentOptionalParameterAssert<P> extends HasParent<P> { | |
| 25 | private final List<OptionalParameterWithContext> actual; | |
| 26 | private final AssertionRegistry registry; | |
| 27 | ||
| 28 | /** | |
| 29 | * Initializes with the parent instance and optional parameters for each | |
| 30 | * {@link SubmitSm} message. | |
| 31 | * | |
| 32 | * @param parent | |
| 33 | * the parent instance | |
| 34 | * @param parameters | |
| 35 | * the optional parameters (with some contextual information) | |
| 36 | * @param registry | |
| 37 | * used to regsiter assertions | |
| 38 | */ | |
| 39 | public FluentOptionalParameterAssert(P parent, List<OptionalParameterWithContext> parameters, AssertionRegistry registry) { | |
| 40 | super(parent); | |
| 41 | this.actual = parameters; | |
| 42 | this.registry = registry; | |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * Make assertions on the whole optional parameter. | |
| 47 | * | |
| 48 | * <pre> | |
| 49 | * .receivedMessages().message(0) | |
| 50 | * .rawRequest() | |
| 51 | * .optionalParameter(Tag.MESSAGE_PAYLOAD) | |
| 52 | * .parameter(notNullValue()) | |
| 53 | * </pre> | |
| 54 | * | |
| 55 | * Will check if the 'message_payload' optional parameter of the first | |
| 56 | * message is not null. | |
| 57 | * | |
| 58 | * <pre> | |
| 59 | * .receivedMessages().every() | |
| 60 | * .rawRequest() | |
| 61 | * .optionalParameter(Tag.MESSAGE_PAYLOAD) | |
| 62 | * .parameter(notNullValue()) | |
| 63 | * </pre> | |
| 64 | * | |
| 65 | * Will check if the 'message_payload' optional parameter of every message | |
| 66 | * is not null. | |
| 67 | * | |
| 68 | * @param matcher | |
| 69 | * the assertion to apply on the optional parameter | |
| 70 | * @return the fluent API for chaining assertions on received message(s) | |
| 71 | */ | |
| 72 | public FluentOptionalParameterAssert<P> parameter(Matcher<? super OptionalParameter> matcher) { | |
| 73 | String message = "optional parameter '${tagName}'${found} of ${name} of message ${messageIndex}"; | |
| 74 | for (OptionalParameterWithContext parameterWithContext : actual) { | |
| 75 | OptionalParameter parameter = parameterWithContext.getParameter(); | |
| 76 |
4
1. lambda$parameter$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE 2. parameter : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 3. lambda$parameter$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED 4. parameter : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED |
registry.register(() -> assertThat(parameter, usingContext(message, parameterWithContext, matcher))); |
| 77 | } | |
| 78 |
2
1. parameter : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentOptionalParameterAssert::parameter → NO_COVERAGE 2. parameter : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentOptionalParameterAssert::parameter → KILLED |
return this; |
| 79 | } | |
| 80 | ||
| 81 | /** | |
| 82 | * Make assertions on the optional parameter value. | |
| 83 | * | |
| 84 | * <pre> | |
| 85 | * .receivedMessages().message(0) | |
| 86 | * .rawRequest() | |
| 87 | * .optionalParameter(Tag.MESSAGE_PAYLOAD) | |
| 88 | * .value(arrayWithSize(134)) | |
| 89 | * </pre> | |
| 90 | * | |
| 91 | * Will check if the value of the 'message_payload' optional parameter of | |
| 92 | * the first message is an array of 134 bytes. | |
| 93 | * | |
| 94 | * <pre> | |
| 95 | * .receivedMessages().every() | |
| 96 | * .rawRequest() | |
| 97 | * .optionalParameter(Tag.MESSAGE_PAYLOAD) | |
| 98 | * .value(arrayWithSize(134)) | |
| 99 | * </pre> | |
| 100 | * | |
| 101 | * Will check if the 'message_payload' optional parameter of every message | |
| 102 | * is an array of 134 bytes. | |
| 103 | * | |
| 104 | * @param matcher | |
| 105 | * the assertion to apply on the optional parameter value | |
| 106 | * @return the fluent API for chaining assertions on received message(s) | |
| 107 | */ | |
| 108 | public FluentOptionalParameterAssert<P> value(Matcher<? super Byte[]> matcher) { | |
| 109 | String message = "optional parameter '${tagName}'${found} value of ${name} of message ${messageIndex}"; | |
| 110 | for (OptionalParameterWithContext parameterWithContext : actual) { | |
| 111 | OptionalParameter parameter = parameterWithContext.getParameter(); | |
| 112 |
6
1. lambda$value$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE 2. lambda$value$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED 3. value : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 4. value : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 5. lambda$value$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED 6. value : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED |
registry.register(() -> assertThat(toObject(parameter.getValue()), usingContext(message, parameterWithContext, matcher))); |
| 113 | } | |
| 114 |
3
1. value : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentOptionalParameterAssert::value → NO_COVERAGE 2. value : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentOptionalParameterAssert::value → KILLED 3. value : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentOptionalParameterAssert::value → KILLED |
return this; |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * Make assertions on the optional parameter value. | |
| 119 | * | |
| 120 | * <pre> | |
| 121 | * .receivedMessages().message(0) | |
| 122 | * .rawRequest() | |
| 123 | * .optionalParameter(Tag.MESSAGE_PAYLOAD) | |
| 124 | * .value(is(134)) | |
| 125 | * </pre> | |
| 126 | * | |
| 127 | * Will check if the length of the 'message_payload' optional parameter of | |
| 128 | * the first message is 134. | |
| 129 | * | |
| 130 | * <pre> | |
| 131 | * .receivedMessages().every() | |
| 132 | * .rawRequest() | |
| 133 | * .optionalParameter(Tag.MESSAGE_PAYLOAD) | |
| 134 | * .value(is(134)) | |
| 135 | * </pre> | |
| 136 | * | |
| 137 | * Will check if the length of the 'message_payload' optional parameter of | |
| 138 | * every message is an array of 134 bytes. | |
| 139 | * | |
| 140 | * @param matcher | |
| 141 | * the assertion to apply on the optional parameter value | |
| 142 | * @return the fluent API for chaining assertions on received message(s) | |
| 143 | */ | |
| 144 | public FluentOptionalParameterAssert<P> length(Matcher<? super Integer> matcher) { | |
| 145 | String message = "optional parameter '${tagName}'${found} length of ${name} of message ${messageIndex}"; | |
| 146 | for (OptionalParameterWithContext parameterWithContext : actual) { | |
| 147 | OptionalParameter parameter = parameterWithContext.getParameter(); | |
| 148 |
6
1. lambda$length$2 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE 2. lambda$length$2 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED 3. length : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED 4. length : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE 5. lambda$length$2 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED 6. length : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED |
registry.register(() -> assertThat(parameter.getLength(), usingContext(message, parameterWithContext, matcher))); |
| 149 | } | |
| 150 |
3
1. length : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentOptionalParameterAssert::length → SURVIVED 2. length : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentOptionalParameterAssert::length → NO_COVERAGE 3. length : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentOptionalParameterAssert::length → KILLED |
return this; |
| 151 | } | |
| 152 | ||
| 153 | } | |
Mutations | ||
| 76 |
1.1 2.2 3.3 4.4 |
|
| 78 |
1.1 2.2 |
|
| 112 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 114 |
1.1 2.2 3.3 |
|
| 148 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 150 |
1.1 2.2 3.3 |