FluentShortMessageMessageAssert.java

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 java.util.Collections.unmodifiableList;
6
import static org.apache.commons.lang3.ArrayUtils.toObject;
7
8
import java.util.Arrays;
9
import java.util.List;
10
11
import org.hamcrest.Matcher;
12
13
import fr.sii.ogham.testing.assertion.util.AssertionRegistry;
14
import fr.sii.ogham.testing.sms.simulator.bean.SubmitSm;
15
import fr.sii.ogham.testing.util.HasParent;
16
17
/**
18
 * Make assertions on {@code short_message} field.
19
 * 
20
 * @author Aurélien Baudet
21
 *
22
 * @param <P>
23
 *            Parent type
24
 * @param <S>
25
 *            Sent SubmitSm type
26
 */
27
public class FluentShortMessageMessageAssert<P, S extends SubmitSm> extends HasParent<P> {
28
	private final List<ShortMessageWithContext<S>> actual;
29
	private final AssertionRegistry registry;
30
31
	/**
32
	 * Initializes with the list of short messages and the parent.
33
	 * 
34
	 * @param actual
35
	 *            the list of short messages (whit extra context for error
36
	 *            reporting)
37
	 * @param parent
38
	 *            the parent (used by {@link #and()})
39
	 * @param registry
40
	 *            used to register assertions
41
	 */
42
	public FluentShortMessageMessageAssert(List<ShortMessageWithContext<S>> actual, P parent, AssertionRegistry registry) {
43
		super(parent);
44
		this.actual = unmodifiableList(actual);
45
		this.registry = registry;
46
	}
47
48
	/**
49
	 * Make assertions on the header byte array of short message field of the
50
	 * message(s) using fluent API. The header byte array may be null. This is
51
	 * the default behavior. However, if the original message is split into
52
	 * several segments, each segment has a header that contains information to
53
	 * indicate how the message was split (number of segments, reference number,
54
	 * current segment number, ...).
55
	 * 
56
	 * <pre>
57
	 * .receivedMessages()
58
	 *   .message(0)
59
	 *     .rawRequest()
60
	 *       .shortMessage()
61
	 *         .header(array(equalTo(0x01), equalTo(0x02)))
62
	 * </pre>
63
	 * 
64
	 * Will check if the header byte array of the first message is exactly
65
	 * [0x01, 0x02].
66
	 * 
67
	 * <pre>
68
	 * .receivedMessages()
69
	 *   .every()
70
	 *     .rawRequest()
71
	 *       .shortMessage()
72
	 *         .header(array(equalTo(0x01), equalTo(0x02)))
73
	 * </pre>
74
	 * 
75
	 * Will check if the header byte array of every message is exactly [0x01,
76
	 * 0x02].
77
	 * 
78
	 * @param matcher
79
	 *            the assertion to apply on the header
80
	 * @return the fluent API for chaining assertions on received message(s)
81
	 */
82
	public FluentShortMessageMessageAssert<P, S> header(Matcher<? super Byte[]> matcher) {
83
		String message = "header of ${name} of message ${messageIndex}";
84
		for (ShortMessageWithContext<S> shortMessageWithContext : actual) {
85
			S msg = shortMessageWithContext.getRequest();
86 6 1. header : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED
2. header : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE
3. lambda$header$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE
4. lambda$header$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED
5. header : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED
6. lambda$header$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED
			registry.register(() -> assertThat(toObject(getHeader(msg)), usingContext(message, shortMessageWithContext, matcher)));
87
		}
88 3 1. header : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::header → NO_COVERAGE
2. header : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::header → KILLED
3. header : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::header → KILLED
		return this;
89
	}
90
91
	/**
92
	 * Make assertions on the payload byte array of short message field of the
93
	 * message(s) using fluent API. The payload is the part without the header
94
	 * (see {@link #header(Matcher)}). It contains the message (as byte array)
95
	 * displayed to the end-user.
96
	 * 
97
	 * <pre>
98
	 * .receivedMessages()
99
	 *   .message(0)
100
	 *     .rawRequest()
101
	 *       .shortMessage()
102
	 *         .payload(arrayWithSize(160))
103
	 * </pre>
104
	 * 
105
	 * Will check if the payload byte array of the first message has exactly 160
106
	 * bytes.
107
	 * 
108
	 * <pre>
109
	 * .receivedMessages()
110
	 *   .every()
111
	 *     .rawRequest()
112
	 *       .shortMessage()
113
	 *         .payload(arrayWithSize(160))
114
	 * </pre>
115
	 * 
116
	 * Will check if the payload byte array of the first message has exactly 160
117
	 * bytes.
118
	 * 
119
	 * @param matcher
120
	 *            the assertion to apply on the payload
121
	 * @return the fluent API for chaining assertions on received message(s)
122
	 */
123
	public FluentShortMessageMessageAssert<P, S> payload(Matcher<? super Byte[]> matcher) {
124
		String message = "payload of ${name} of message ${messageIndex}";
125
		for (ShortMessageWithContext<S> shortMessageWithContext : actual) {
126
			S msg = shortMessageWithContext.getRequest();
127 6 1. lambda$payload$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE
2. lambda$payload$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED
3. payload : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED
4. payload : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE
5. lambda$payload$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED
6. payload : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED
			registry.register(() -> assertThat(toObject(getPayload(msg)), usingContext(message, shortMessageWithContext, matcher)));
128
		}
129 3 1. payload : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::payload → SURVIVED
2. payload : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::payload → NO_COVERAGE
3. payload : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::payload → KILLED
		return this;
130
	}
131
132
	@SuppressWarnings("squid:S1168")
133
	private byte[] getHeader(S msg) {
134
		byte[] shortMessage = msg.getShortMessage();
135 3 1. getHeader : negated conditional → NO_COVERAGE
2. getHeader : negated conditional → KILLED
3. getHeader : negated conditional → KILLED
		if (msg.isUdhi()) {
136 3 1. getHeader : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getHeader → NO_COVERAGE
2. getHeader : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getHeader → KILLED
3. getHeader : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getHeader → KILLED
			return Arrays.copyOfRange(shortMessage, 0, headerLength(shortMessage));
137
		}
138
		return null;
139
	}
140
141
	private static int headerLength(byte[] shortMessage) {
142 6 1. headerLength : Replaced integer addition with subtraction → NO_COVERAGE
2. headerLength : replaced int return with 0 for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::headerLength → NO_COVERAGE
3. headerLength : Replaced integer addition with subtraction → KILLED
4. headerLength : Replaced integer addition with subtraction → KILLED
5. headerLength : replaced int return with 0 for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::headerLength → KILLED
6. headerLength : replaced int return with 0 for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::headerLength → KILLED
		return shortMessage[0] + 1;
143
	}
144
145
	private byte[] getPayload(S msg) {
146
		byte[] shortMessage = msg.getShortMessage();
147 4 1. getPayload : negated conditional → NO_COVERAGE
2. getPayload : negated conditional → KILLED
3. getPayload : negated conditional → KILLED
4. getPayload : negated conditional → KILLED
		if (msg.isUdhi()) {
148 3 1. getPayload : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → NO_COVERAGE
2. getPayload : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → KILLED
3. getPayload : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → KILLED
			return Arrays.copyOfRange(shortMessage, headerLength(shortMessage), shortMessage.length);
149
		}
150 4 1. getPayload : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → NO_COVERAGE
2. getPayload : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → KILLED
3. getPayload : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → KILLED
4. getPayload : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → KILLED
		return shortMessage;
151
	}
152
}

Mutations

86

1.1
Location : header
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED

2.2
Location : header
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

3.3
Location : header
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED

4.4
Location : lambda$header$0
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE

5.5
Location : lambda$header$0
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED

6.6
Location : lambda$header$0
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED

88

1.1
Location : header
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::header → NO_COVERAGE

2.2
Location : header
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::header → KILLED

3.3
Location : header
Killed by : oghamcloudhopper.it.PartialConfigurationTest.nothingConfiguredAndLongMessageShouldSendOneLongMessageUsingDefaultEncoding(oghamcloudhopper.it.PartialConfigurationTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::header → KILLED

127

1.1
Location : lambda$payload$1
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE

2.2
Location : lambda$payload$1
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED

3.3
Location : lambda$payload$1
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED

4.4
Location : payload
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED

5.5
Location : payload
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED

6.6
Location : payload
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

129

1.1
Location : payload
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::payload → SURVIVED

2.2
Location : payload
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::payload → NO_COVERAGE

3.3
Location : payload
Killed by : oghamcloudhopper.it.PartialConfigurationTest.splitterEnabledAndAutoGuessEnabledAndGsm7bitEncodingConfiguredAndLongMessageShouldSendTwoMessages(oghamcloudhopper.it.PartialConfigurationTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::payload → KILLED

135

1.1
Location : getHeader
Killed by : oghamcloudhopper.it.PartialConfigurationTest.nothingConfiguredAndLongMessageShouldSendOneLongMessageUsingDefaultEncoding(oghamcloudhopper.it.PartialConfigurationTest)
negated conditional → KILLED

2.2
Location : getHeader
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
negated conditional → KILLED

3.3
Location : getHeader
Killed by : none
negated conditional → NO_COVERAGE

136

1.1
Location : getHeader
Killed by : oghamcloudhopper.it.PartialConfigurationTest.splitterEnabledAndAutoGuessEnabledAndGsm7bitEncodingConfiguredAndLongMessageShouldSendTwoMessages(oghamcloudhopper.it.PartialConfigurationTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getHeader → KILLED

2.2
Location : getHeader
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getHeader → NO_COVERAGE

3.3
Location : getHeader
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getHeader → KILLED

142

1.1
Location : headerLength
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : headerLength
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
Replaced integer addition with subtraction → KILLED

3.3
Location : headerLength
Killed by : oghamcloudhopper.it.PartialConfigurationTest.splitterEnabledAndAutoGuessEnabledAndGsm7bitEncodingConfiguredAndLongMessageShouldSendTwoMessages(oghamcloudhopper.it.PartialConfigurationTest)
Replaced integer addition with subtraction → KILLED

4.4
Location : headerLength
Killed by : oghamcloudhopper.it.PartialConfigurationTest.splitterEnabledAndAutoGuessEnabledAndGsm7bitEncodingConfiguredAndLongMessageShouldSendTwoMessages(oghamcloudhopper.it.PartialConfigurationTest)
replaced int return with 0 for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::headerLength → KILLED

5.5
Location : headerLength
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
replaced int return with 0 for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::headerLength → KILLED

6.6
Location : headerLength
Killed by : none
replaced int return with 0 for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::headerLength → NO_COVERAGE

147

1.1
Location : getPayload
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getPayload
Killed by : oghamall.it.sms.SmsSMPPDefaultsTest.gsm8bitDefaultAlphabet(oghamall.it.sms.SmsSMPPDefaultsTest)
negated conditional → KILLED

3.3
Location : getPayload
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
negated conditional → KILLED

4.4
Location : getPayload
Killed by : oghamcloudhopper.it.PartialConfigurationTest.nothingConfiguredAndLongMessageShouldSendOneLongMessageUsingDefaultEncoding(oghamcloudhopper.it.PartialConfigurationTest)
negated conditional → KILLED

148

1.1
Location : getPayload
Killed by : oghamcloudhopper.it.PartialConfigurationTest.splitterEnabledAndAutoGuessEnabledAndGsm7bitEncodingConfiguredAndLongMessageShouldSendTwoMessages(oghamcloudhopper.it.PartialConfigurationTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → KILLED

2.2
Location : getPayload
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → KILLED

3.3
Location : getPayload
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → NO_COVERAGE

150

1.1
Location : getPayload
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → KILLED

2.2
Location : getPayload
Killed by : oghamcloudhopper.it.PartialConfigurationTest.nothingConfiguredAndLongMessageShouldSendOneLongMessageUsingDefaultEncoding(oghamcloudhopper.it.PartialConfigurationTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → KILLED

3.3
Location : getPayload
Killed by : oghamall.it.sms.SmsSMPPDefaultsTest.gsm8bitDefaultAlphabet(oghamall.it.sms.SmsSMPPDefaultsTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → KILLED

4.4
Location : getPayload
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentShortMessageMessageAssert::getPayload → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM