1 | package fr.sii.ogham.testing.sms.simulator.jsmpp; | |
2 | ||
3 | import java.math.BigInteger; | |
4 | import java.util.Arrays; | |
5 | ||
6 | import org.jsmpp.bean.SubmitSm; | |
7 | ||
8 | import com.cloudhopper.commons.util.HexUtil; | |
9 | ||
10 | import fr.sii.ogham.testing.sms.simulator.bean.OptionalParameter; | |
11 | ||
12 | /** | |
13 | * Adapts a JSMPP optional parameter to the Ogham abstraction | |
14 | * | |
15 | * @author Aurélien Baudet | |
16 | * | |
17 | */ | |
18 | public class OptionalParameterAdapter implements OptionalParameter { | |
19 | private final SubmitSm original; | |
20 | private final short tag; | |
21 | ||
22 | /** | |
23 | * @param original | |
24 | * the JSMPP {@link SubmitSm} request | |
25 | * @param tag | |
26 | * the tag to extract | |
27 | */ | |
28 | public OptionalParameterAdapter(SubmitSm original, short tag) { | |
29 | super(); | |
30 | this.original = original; | |
31 | this.tag = tag; | |
32 | } | |
33 | ||
34 | @Override | |
35 | public Short getTag() { | |
36 | byte[] tagValue = getOptionalParameterBytes(0, 2); | |
37 |
3
1. getTag : negated conditional → SURVIVED 2. getTag : negated conditional → NO_COVERAGE 3. getTag : negated conditional → KILLED |
if (tagValue == null) { |
38 |
2
1. getTag : replaced Short return value with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getTag → NO_COVERAGE 2. getTag : replaced Short return value with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getTag → KILLED |
return null; |
39 | } | |
40 |
3
1. getTag : replaced Short return value with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getTag → SURVIVED 2. getTag : replaced Short return value with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getTag → NO_COVERAGE 3. getTag : replaced Short return value with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getTag → KILLED |
return new BigInteger(tagValue).shortValue(); |
41 | } | |
42 | ||
43 | @Override | |
44 | public Integer getLength() { | |
45 | byte[] length = getOptionalParameterBytes(2, 4); | |
46 |
3
1. getLength : negated conditional → NO_COVERAGE 2. getLength : negated conditional → KILLED 3. getLength : negated conditional → KILLED |
if (length == null) { |
47 |
2
1. getLength : replaced Integer return value with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getLength → NO_COVERAGE 2. getLength : replaced Integer return value with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getLength → KILLED |
return null; |
48 | } | |
49 |
3
1. getLength : replaced Integer return value with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getLength → NO_COVERAGE 2. getLength : replaced Integer return value with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getLength → KILLED 3. getLength : replaced Integer return value with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getLength → KILLED |
return new BigInteger(length).intValue(); |
50 | } | |
51 | ||
52 | @Override | |
53 | public byte[] getValue() { | |
54 |
3
1. getValue : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getValue → NO_COVERAGE 2. getValue : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getValue → KILLED 3. getValue : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getValue → KILLED |
return getOptionalParameterBytes(4, null); |
55 | } | |
56 | | |
57 | @Override | |
58 | public String toString() { | |
59 |
2
1. toString : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::toString → NO_COVERAGE 2. toString : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::toString → KILLED |
return "["+getTag()+"|"+getLength()+"|"+HexUtil.toHexString(getValue())+"]"; |
60 | } | |
61 | ||
62 | @SuppressWarnings("squid:S1168") | |
63 | private byte[] getOptionalParameterBytes(int from, Integer to) { | |
64 | org.jsmpp.bean.OptionalParameter parameter = original.getOptionalParameter(tag); | |
65 |
3
1. getOptionalParameterBytes : negated conditional → NO_COVERAGE 2. getOptionalParameterBytes : negated conditional → KILLED 3. getOptionalParameterBytes : negated conditional → KILLED |
if (parameter == null) { |
66 | return null; | |
67 | } | |
68 | byte[] bytes = parameter.serialize(); | |
69 |
3
1. getOptionalParameterBytes : negated conditional → NO_COVERAGE 2. getOptionalParameterBytes : negated conditional → KILLED 3. getOptionalParameterBytes : negated conditional → KILLED |
if (bytes == null) { |
70 | return null; | |
71 | } | |
72 |
6
1. getOptionalParameterBytes : negated conditional → NO_COVERAGE 2. getOptionalParameterBytes : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getOptionalParameterBytes → NO_COVERAGE 3. getOptionalParameterBytes : negated conditional → KILLED 4. getOptionalParameterBytes : negated conditional → KILLED 5. getOptionalParameterBytes : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getOptionalParameterBytes → KILLED 6. getOptionalParameterBytes : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/OptionalParameterAdapter::getOptionalParameterBytes → KILLED |
return Arrays.copyOfRange(bytes, from, to == null ? bytes.length : to); |
73 | } | |
74 | } | |
Mutations | ||
37 |
1.1 2.2 3.3 |
|
38 |
1.1 2.2 |
|
40 |
1.1 2.2 3.3 |
|
46 |
1.1 2.2 3.3 |
|
47 |
1.1 2.2 |
|
49 |
1.1 2.2 3.3 |
|
54 |
1.1 2.2 3.3 |
|
59 |
1.1 2.2 |
|
65 |
1.1 2.2 3.3 |
|
69 |
1.1 2.2 3.3 |
|
72 |
1.1 2.2 3.3 4.4 5.5 6.6 |