DefaultSmsCodingDetector.java

1
package fr.sii.ogham.sms.sender.impl.ovh;
2
3
/**
4
 * See <a href=
5
 * "https://docs.ovh.com/fr/sms/envoyer_des_sms_depuis_une_url_-_http2sms/#annexe_2">https://docs.ovh.com/fr/sms/envoyer_des_sms_depuis_une_url_-_http2sms/#annexe_2</a>
6
 * 
7
 * @author Aurélien Baudet
8
 *
9
 */
10
public class DefaultSmsCodingDetector implements SmsCodingDetector {
11
	/**
12
	 * Basic characters
13
	 */
14
	private static final char[] CHAR_TABLE = {
15
		// @formatter:off
16
		'@', '\u00a3', '$', '\u00a5', '\u00e8', '\u00e9', '\u00f9', '\u00ec',
17
		'\u00f2', '\u00c7', '\n', '\u00d8', '\u00f8', '\r', '\u00c5', '\u00e5',
18
		'\u0394', '_', '\u03a6', '\u0393', '\u039b', '\u03a9', '\u03a0', '\u03a8',
19
		'\u03a3', '\u0398', '\u039e', ' ', '\u00c6', '\u00e6', '\u00df', '\u00c9',  // 0x1B is actually an escape which we'll encode to a space char
20
		' ', '!', '"', '#', '\u00a4', '%', '&', '\'',
21
		'(', ')', '*', '+', ',', '-', '.', '/',
22
		'0', '1', '2', '3', '4', '5', '6', '7',
23
		'8', '9', ':', ';', '<', '=', '>', '?',
24
		'\u00a1', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
25
		'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
26
		'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
27
		'X', 'Y', 'Z', '\u00c4', '\u00d6', '\u00d1', '\u00dc', '\u00a7',
28
		'\u00bf', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
29
		'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
30
		'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
31
		'x', 'y', 'z', '\u00e4', '\u00f6', '\u00f1', '\u00fc', '\u00e0',
32
		// @formatter:on
33
	};
34
35
	/**
36
	 * Extended character table.
37
	 */
38
	private static final char[] EXT_CHAR_TABLE = {
39
		// @formatter:off
40
		'\u20ac' /* € */, '\f', '[', '\\', ']',
41
		'^', '{', '|', '}', '~', 
42
		 // @formatter:on
43
	};
44
45
	@Override
46
	public SmsCoding detect(String message) {
47 2 1. detect : replaced return value with null for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::detect → NO_COVERAGE
2. detect : negated conditional → NO_COVERAGE
		return canUseGsm7(message) ? SmsCoding.GSM7 : SmsCoding.UNICODE;
48
	}
49
50
	private static boolean canUseGsm7(String message) {
51 2 1. canUseGsm7 : negated conditional → NO_COVERAGE
2. canUseGsm7 : changed conditional boundary → NO_COVERAGE
		for (int i=0 ; i<message.length() ; i++) {
52
			char c = message.charAt(i);
53 2 1. canUseGsm7 : negated conditional → NO_COVERAGE
2. canUseGsm7 : negated conditional → NO_COVERAGE
			if (!isInCharTable(c) && !isInExtensionCharTable(c)) {
54 1 1. canUseGsm7 : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::canUseGsm7 → NO_COVERAGE
				return false;
55
			}
56
		}
57 1 1. canUseGsm7 : replaced boolean return with false for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::canUseGsm7 → NO_COVERAGE
		return true;
58
	}
59
	
60
	private static boolean isInCharTable(char c) {
61 2 1. isInCharTable : changed conditional boundary → NO_COVERAGE
2. isInCharTable : negated conditional → NO_COVERAGE
		for (int i=0 ; i<CHAR_TABLE.length ; i++) {
62 1 1. isInCharTable : negated conditional → NO_COVERAGE
			if (c == CHAR_TABLE[i]) {
63 1 1. isInCharTable : replaced boolean return with false for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::isInCharTable → NO_COVERAGE
				return true;
64
			}
65
		}
66 1 1. isInCharTable : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::isInCharTable → NO_COVERAGE
		return false;
67
	}
68
69
	private static boolean isInExtensionCharTable(char c) {
70 2 1. isInExtensionCharTable : changed conditional boundary → NO_COVERAGE
2. isInExtensionCharTable : negated conditional → NO_COVERAGE
		for (int i=0 ; i<EXT_CHAR_TABLE.length ; i++) {
71 1 1. isInExtensionCharTable : negated conditional → NO_COVERAGE
			if (c == EXT_CHAR_TABLE[i]) {
72 1 1. isInExtensionCharTable : replaced boolean return with false for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::isInExtensionCharTable → NO_COVERAGE
				return true;
73
			}
74
		}
75 1 1. isInExtensionCharTable : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::isInExtensionCharTable → NO_COVERAGE
		return false;
76
	}
77
78
}

Mutations

47

1.1
Location : detect
Killed by :
replaced return value with null for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::detect → NO_COVERAGE

2.2
Location : detect
Killed by :
negated conditional → NO_COVERAGE

51

1.1
Location : canUseGsm7
Killed by :
negated conditional → NO_COVERAGE

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

53

1.1
Location : canUseGsm7
Killed by :
negated conditional → NO_COVERAGE

2.2
Location : canUseGsm7
Killed by :
negated conditional → NO_COVERAGE

54

1.1
Location : canUseGsm7
Killed by :
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::canUseGsm7 → NO_COVERAGE

57

1.1
Location : canUseGsm7
Killed by :
replaced boolean return with false for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::canUseGsm7 → NO_COVERAGE

61

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

2.2
Location : isInCharTable
Killed by :
negated conditional → NO_COVERAGE

62

1.1
Location : isInCharTable
Killed by :
negated conditional → NO_COVERAGE

63

1.1
Location : isInCharTable
Killed by :
replaced boolean return with false for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::isInCharTable → NO_COVERAGE

66

1.1
Location : isInCharTable
Killed by :
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::isInCharTable → NO_COVERAGE

70

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

2.2
Location : isInExtensionCharTable
Killed by :
negated conditional → NO_COVERAGE

71

1.1
Location : isInExtensionCharTable
Killed by :
negated conditional → NO_COVERAGE

72

1.1
Location : isInExtensionCharTable
Killed by :
replaced boolean return with false for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::isInExtensionCharTable → NO_COVERAGE

75

1.1
Location : isInExtensionCharTable
Killed by :
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/ovh/DefaultSmsCodingDetector::isInExtensionCharTable → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.13.1