CloudhopperCharsetSupportingEncoder.java

1
package fr.sii.ogham.sms.sender.impl.cloudhopper.encoder;
2
3
import com.cloudhopper.commons.charset.Charset;
4
5
import fr.sii.ogham.sms.encoder.Encoded;
6
import fr.sii.ogham.sms.encoder.EncodedMessage;
7
import fr.sii.ogham.sms.encoder.Encoder;
8
import fr.sii.ogham.sms.encoder.SupportingEncoder;
9
import fr.sii.ogham.sms.exception.message.EncodingException;
10
11
/**
12
 * An {@link Encoder} that checks if the message can be encoded with a
13
 * particular {@link Charset}.
14
 * 
15
 * <p>
16
 * To test if message can be encoded by the provided {@link Charset}, the
17
 * message is first encoded into a byte array and then the byte array is decoded
18
 * into a string (using {@link Charset#normalize(CharSequence)} method). If the
19
 * result of normalization has not the same length, it means that the
20
 * {@link Charset} can't handle the message properly.
21
 * 
22
 * <p>
23
 * Moreover, {@link Charset} implementations use '?' character if a character of
24
 * original string can't be properly converted. Therefore, the number of '?'
25
 * characters are count before and after normalization. If the number is not the
26
 * same, it means that the {@link Charset} can't handle the message properly.
27
 * 
28
 * @author Aurélien Baudet
29
 *
30
 */
31
public class CloudhopperCharsetSupportingEncoder implements SupportingEncoder {
32
	private final NamedCharset charset;
33
34
	/**
35
	 * Initializes with the charset used to encode the message if it can.
36
	 * 
37
	 * @param charset
38
	 *            the charset to use
39
	 */
40
	public CloudhopperCharsetSupportingEncoder(NamedCharset charset) {
41
		super();
42
		this.charset = charset;
43
	}
44
45
	@Override
46
	public Encoded encode(String message) throws EncodingException {
47 4 1. encode : replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::encode → NO_COVERAGE
2. encode : replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::encode → TIMED_OUT
3. encode : replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::encode → KILLED
4. encode : replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::encode → KILLED
		return new EncodedMessage(message, charset.getCharset().encode(message), charset.getCharsetName());
48
	}
49
50
	@Override
51
	public boolean canEncode(String message) {
52
		String normalized = charset.getCharset().normalize(message);
53 8 1. canEncode : changed conditional boundary → NO_COVERAGE
2. canEncode : negated conditional → NO_COVERAGE
3. canEncode : changed conditional boundary → TIMED_OUT
4. canEncode : negated conditional → TIMED_OUT
5. canEncode : changed conditional boundary → KILLED
6. canEncode : changed conditional boundary → KILLED
7. canEncode : negated conditional → KILLED
8. canEncode : negated conditional → KILLED
		if (normalized.length() > message.length()) {
54 1 1. canEncode : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::canEncode → NO_COVERAGE
			return false;
55
		}
56 8 1. canEncode : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::canEncode → NO_COVERAGE
2. canEncode : negated conditional → NO_COVERAGE
3. canEncode : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::canEncode → TIMED_OUT
4. canEncode : negated conditional → TIMED_OUT
5. canEncode : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::canEncode → KILLED
6. canEncode : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::canEncode → KILLED
7. canEncode : negated conditional → KILLED
8. canEncode : negated conditional → KILLED
		return countQuestionMarks(message) == countQuestionMarks(normalized);
57
	}
58
59
	private static long countQuestionMarks(String str) {
60 11 1. countQuestionMarks : replaced long return with 0 for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::countQuestionMarks → NO_COVERAGE
2. lambda$countQuestionMarks$0 : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::lambda$countQuestionMarks$0 → NO_COVERAGE
3. lambda$countQuestionMarks$0 : negated conditional → SURVIVED
4. lambda$countQuestionMarks$0 : negated conditional → NO_COVERAGE
5. countQuestionMarks : replaced long return with 0 for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::countQuestionMarks → TIMED_OUT
6. lambda$countQuestionMarks$0 : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::lambda$countQuestionMarks$0 → TIMED_OUT
7. lambda$countQuestionMarks$0 : negated conditional → TIMED_OUT
8. countQuestionMarks : replaced long return with 0 for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::countQuestionMarks → KILLED
9. countQuestionMarks : replaced long return with 0 for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::countQuestionMarks → KILLED
10. lambda$countQuestionMarks$0 : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::lambda$countQuestionMarks$0 → KILLED
11. lambda$countQuestionMarks$0 : replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::lambda$countQuestionMarks$0 → KILLED
		return str.chars().filter(ch -> ch == '?').count();
61
	}
62
}

Mutations

47

1.1
Location : encode
Killed by : none
replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::encode → NO_COVERAGE

2.2
Location : encode
Killed by : oghamcloudhopper.it.PartialConfigurationTest.nothingConfiguredAndLongMessageShouldSendOneLongMessageUsingDefaultEncoding(oghamcloudhopper.it.PartialConfigurationTest)
replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::encode → KILLED

3.3
Location : encode
Killed by : none
replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::encode → TIMED_OUT

4.4
Location : encode
Killed by : oghamall.it.sms.SmsSMPPGsm7bitTest.longMessage(oghamall.it.sms.SmsSMPPGsm7bitTest)
replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::encode → KILLED

53

1.1
Location : canEncode
Killed by : none
changed conditional boundary → TIMED_OUT

2.2
Location : canEncode
Killed by : oghamall.it.sms.SmsSMPPGsm7bitTest.longMessage(oghamall.it.sms.SmsSMPPGsm7bitTest)
changed conditional boundary → KILLED

3.3
Location : canEncode
Killed by : none
changed conditional boundary → NO_COVERAGE

4.4
Location : canEncode
Killed by : oghamcloudhopper.it.SpecialCharactersTest.gsm8bit(oghamcloudhopper.it.SpecialCharactersTest)
changed conditional boundary → KILLED

5.5
Location : canEncode
Killed by : oghamall.it.sms.SmsSMPPGsm7bitTest.longMessage(oghamall.it.sms.SmsSMPPGsm7bitTest)
negated conditional → KILLED

6.6
Location : canEncode
Killed by : oghamcloudhopper.it.SpecialCharactersTest.gsm8bit(oghamcloudhopper.it.SpecialCharactersTest)
negated conditional → KILLED

7.7
Location : canEncode
Killed by : none
negated conditional → NO_COVERAGE

8.8
Location : canEncode
Killed by : none
negated conditional → TIMED_OUT

54

1.1
Location : canEncode
Killed by : none
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::canEncode → NO_COVERAGE

56

1.1
Location : canEncode
Killed by : none
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::canEncode → NO_COVERAGE

2.2
Location : canEncode
Killed by : oghamall.it.sms.SmsSMPPDefaultsTest.gsmUcs2(oghamall.it.sms.SmsSMPPDefaultsTest)
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::canEncode → KILLED

3.3
Location : canEncode
Killed by : none
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::canEncode → TIMED_OUT

4.4
Location : canEncode
Killed by : oghamcloudhopper.it.PartialConfigurationTest.splitterEnabledAndAutoGuessEnabledAndGsm7bitEncodingConfiguredAndLongMessageWithUnsupportedCharactersShouldFailIndicatingThatMessageCantBeSplit(oghamcloudhopper.it.PartialConfigurationTest)
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::canEncode → KILLED

5.5
Location : canEncode
Killed by : oghamcloudhopper.it.PartialConfigurationTest.splitterEnabledAndAutoGuessEnabledAndGsm7bitEncodingConfiguredAndLongMessageWithUnsupportedCharactersShouldFailIndicatingThatMessageCantBeSplit(oghamcloudhopper.it.PartialConfigurationTest)
negated conditional → KILLED

6.6
Location : canEncode
Killed by : none
negated conditional → NO_COVERAGE

7.7
Location : canEncode
Killed by : none
negated conditional → TIMED_OUT

8.8
Location : canEncode
Killed by : oghamall.it.sms.SmsSMPPGsm7bitTest.longMessage(oghamall.it.sms.SmsSMPPGsm7bitTest)
negated conditional → KILLED

60

1.1
Location : countQuestionMarks
Killed by : oghamcloudhopper.it.PartialConfigurationTest.splitterEnabledAndAutoGuessEnabledAndGsm7bitEncodingConfiguredAndLongMessageWithUnsupportedCharactersShouldFailIndicatingThatMessageCantBeSplit(oghamcloudhopper.it.PartialConfigurationTest)
replaced long return with 0 for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::countQuestionMarks → KILLED

2.2
Location : countQuestionMarks
Killed by : none
replaced long return with 0 for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::countQuestionMarks → NO_COVERAGE

3.3
Location : countQuestionMarks
Killed by : oghamall.it.sms.SmsSMPPDefaultsTest.gsmUcs2(oghamall.it.sms.SmsSMPPDefaultsTest)
replaced long return with 0 for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::countQuestionMarks → KILLED

4.4
Location : countQuestionMarks
Killed by : none
replaced long return with 0 for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::countQuestionMarks → TIMED_OUT

5.5
Location : lambda$countQuestionMarks$0
Killed by : oghamall.it.sms.SmsSMPPDefaultsTest.gsmUcs2(oghamall.it.sms.SmsSMPPDefaultsTest)
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::lambda$countQuestionMarks$0 → KILLED

6.6
Location : lambda$countQuestionMarks$0
Killed by : none
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::lambda$countQuestionMarks$0 → NO_COVERAGE

7.7
Location : lambda$countQuestionMarks$0
Killed by : none
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::lambda$countQuestionMarks$0 → TIMED_OUT

8.8
Location : lambda$countQuestionMarks$0
Killed by : oghamcloudhopper.it.PartialConfigurationTest.splitterEnabledAndAutoGuessEnabledAndGsm7bitEncodingConfiguredAndLongMessageWithUnsupportedCharactersShouldFailIndicatingThatMessageCantBeSplit(oghamcloudhopper.it.PartialConfigurationTest)
replaced boolean return with true for fr/sii/ogham/sms/sender/impl/cloudhopper/encoder/CloudhopperCharsetSupportingEncoder::lambda$countQuestionMarks$0 → KILLED

9.9
Location : lambda$countQuestionMarks$0
Killed by : none
negated conditional → SURVIVED

10.10
Location : lambda$countQuestionMarks$0
Killed by : none
negated conditional → TIMED_OUT

11.11
Location : lambda$countQuestionMarks$0
Killed by : none
negated conditional → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM