NoSplitMessageSplitter.java

1
package fr.sii.ogham.sms.splitter;
2
3
import static java.util.Arrays.asList;
4
5
import java.util.List;
6
7
import fr.sii.ogham.sms.encoder.Encoder;
8
import fr.sii.ogham.sms.exception.message.EncodingException;
9
import fr.sii.ogham.sms.exception.message.SplitMessageException;
10
11
/**
12
 * A no-op splitter that never splits any message.
13
 * 
14
 * <p>
15
 * It always returns a single segment with the whole message.
16
 * 
17
 * <p>
18
 * The message is encoded using the provided {@link Encoder}. The
19
 * {@link Encoder} may be null and the result segment wraps the unencoded
20
 * original string.
21
 * 
22
 * @author Aurélien Baudet
23
 *
24
 */
25
public class NoSplitMessageSplitter implements MessageSplitter {
26
	private final Encoder encoder;
27
28
	/**
29
	 * Initializes with no encoder. The result of split is one segment with
30
	 * unencoded original message.
31
	 * 
32
	 */
33
	public NoSplitMessageSplitter() {
34
		this(null);
35
	}
36
37
	/**
38
	 * Initializes with the {@link Encoder} used to encode the string message
39
	 * into a byte array.
40
	 * 
41
	 * <p>
42
	 * The encoder may be null, resulting in a single segment with the unencoded
43
	 * original string.
44
	 * 
45
	 * @param encoder
46
	 *            the encoder used to encode the message
47
	 */
48
	public NoSplitMessageSplitter(Encoder encoder) {
49
		super();
50
		this.encoder = encoder;
51
	}
52
53
	@Override
54
	public List<Segment> split(String message) throws SplitMessageException {
55 2 1. split : negated conditional → NO_COVERAGE
2. split : negated conditional → KILLED
		if (encoder == null) {
56 1 1. split : replaced return value with Collections.emptyList for fr/sii/ogham/sms/splitter/NoSplitMessageSplitter::split → NO_COVERAGE
			return asList(new StringSegment(message));
57
		}
58
		try {
59 2 1. split : replaced return value with Collections.emptyList for fr/sii/ogham/sms/splitter/NoSplitMessageSplitter::split → NO_COVERAGE
2. split : replaced return value with Collections.emptyList for fr/sii/ogham/sms/splitter/NoSplitMessageSplitter::split → KILLED
			return asList(new EncodedSegment(encoder.encode(message)));
60
		} catch (EncodingException e) {
61
			throw new SplitMessageException("Message couldn't be encoded", message, e);
62
		}
63
	}
64
65
}

Mutations

55

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

2.2
Location : split
Killed by : none
negated conditional → NO_COVERAGE

56

1.1
Location : split
Killed by : none
replaced return value with Collections.emptyList for fr/sii/ogham/sms/splitter/NoSplitMessageSplitter::split → NO_COVERAGE

59

1.1
Location : split
Killed by : none
replaced return value with Collections.emptyList for fr/sii/ogham/sms/splitter/NoSplitMessageSplitter::split → NO_COVERAGE

2.2
Location : split
Killed by : oghamcloudhopper.it.PartialConfigurationTest.nothingConfiguredAndLongMessageShouldSendOneLongMessageUsingDefaultEncoding(oghamcloudhopper.it.PartialConfigurationTest)
replaced return value with Collections.emptyList for fr/sii/ogham/sms/splitter/NoSplitMessageSplitter::split → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM