AssertSms.java

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

Mutations

40

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → NO_COVERAGE

41

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE

68

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

2.2
Location : lambda$assertEquals$0
Killed by :
removed call to org/junit/jupiter/api/Assertions::assertEquals → NO_COVERAGE

69

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → NO_COVERAGE

2.2
Location : assertEquals
Killed by :
negated conditional → NO_COVERAGE

70

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE

95

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → NO_COVERAGE

96

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE

126

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → NO_COVERAGE

127

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::execute → NO_COVERAGE

131

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

2.2
Location : lambda$assertEquals$1
Killed by :
removed call to org/junit/jupiter/api/Assertions::assertEquals → NO_COVERAGE

132

1.1
Location : assertEquals
Killed by :
changed conditional boundary → NO_COVERAGE

2.2
Location : assertEquals
Killed by :
negated conditional → NO_COVERAGE

133

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

2.2
Location : assertEquals
Killed by :
changed conditional boundary → NO_COVERAGE

3.3
Location : assertEquals
Killed by :
negated conditional → NO_COVERAGE

4.4
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/sms/AssertSms::assertEquals → NO_COVERAGE

138

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

2.2
Location : lambda$assertEquals$2
Killed by :
removed call to org/junit/jupiter/api/Assertions::assertEquals → NO_COVERAGE

139

1.1
Location : lambda$assertEquals$3
Killed by :
removed call to org/junit/jupiter/api/Assertions::assertEquals → NO_COVERAGE

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

140

1.1
Location : lambda$assertEquals$4
Killed by :
removed call to org/junit/jupiter/api/Assertions::assertEquals → NO_COVERAGE

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

142

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

2.2
Location : lambda$assertEquals$5
Killed by :
removed call to org/junit/jupiter/api/Assertions::assertEquals → NO_COVERAGE

143

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

2.2
Location : lambda$assertEquals$6
Killed by :
removed call to org/junit/jupiter/api/Assertions::assertEquals → NO_COVERAGE

144

1.1
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

2.2
Location : lambda$assertEquals$7
Killed by :
removed call to org/junit/jupiter/api/Assertions::assertEquals → NO_COVERAGE

146

1.1
Location : lambda$assertEquals$8
Killed by :
removed call to org/junit/jupiter/api/Assertions::assertEquals → NO_COVERAGE

2.2
Location : lambda$assertEquals$8
Killed by :
negated conditional → NO_COVERAGE

3.3
Location : assertEquals
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

150

1.1
Location : getValue
Killed by :
negated conditional → NO_COVERAGE

154

1.1
Location : getValue
Killed by :
negated conditional → NO_COVERAGE

157

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

Active mutators

Tests examined


Report generated by PIT 1.13.1