TextPrefixSubjectProvider.java

1
package fr.sii.ogham.core.subject.provider;
2
3
import fr.sii.ogham.core.message.Message;
4
import fr.sii.ogham.core.message.content.Content;
5
import fr.sii.ogham.core.message.content.MayHaveStringContent;
6
import fr.sii.ogham.core.message.content.StringContent;
7
import fr.sii.ogham.core.message.content.UpdatableStringContent;
8
9
/**
10
 * Provider that analyzes the content of the message. If the first line contains
11
 * the provided prefix (<code>"Subject:"</code> by default), then the subject is
12
 * the first line without the prefix. The extracted subject is trimmed. If the
13
 * extracted subject is empty then the final subject is empty string. If the
14
 * first line doesn't contain the prefix, then the subject is null.
15
 * 
16
 * @author Aurélien Baudet
17
 *
18
 */
19
public class TextPrefixSubjectProvider implements SubjectProvider {
20
	private static final String NEW_LINE = "\n";
21
	private static final String DEFAULT_PREFIX = "Subject:";
22
23
	/**
24
	 * The prefix
25
	 */
26
	private String prefix;
27
28
	public TextPrefixSubjectProvider() {
29
		this(DEFAULT_PREFIX);
30
	}
31
32
	public TextPrefixSubjectProvider(String prefix) {
33
		super();
34
		this.prefix = prefix;
35
	}
36
37
	@Override
38
	public String provide(Message message) {
39
		Content msgContent = message.getContent();
40 8 1. provide : negated conditional → NO_COVERAGE
2. provide : negated conditional → NO_COVERAGE
3. provide : negated conditional → TIMED_OUT
4. provide : negated conditional → TIMED_OUT
5. provide : negated conditional → KILLED
6. provide : negated conditional → KILLED
7. provide : negated conditional → KILLED
8. provide : negated conditional → KILLED
		if(msgContent instanceof MayHaveStringContent && ((MayHaveStringContent) msgContent).canProvideString()) {
41
			String content = ((MayHaveStringContent) msgContent).asString();
42
			int idx = content.indexOf(NEW_LINE);
43 11 1. provide : changed conditional boundary → NO_COVERAGE
2. provide : changed conditional boundary → SURVIVED
3. provide : negated conditional → NO_COVERAGE
4. provide : negated conditional → NO_COVERAGE
5. provide : changed conditional boundary → TIMED_OUT
6. provide : negated conditional → TIMED_OUT
7. provide : negated conditional → TIMED_OUT
8. provide : negated conditional → KILLED
9. provide : negated conditional → KILLED
10. provide : negated conditional → KILLED
11. provide : negated conditional → KILLED
			if (idx > 0 && content.startsWith(prefix)) {
44
				// remove the subject from the content and update the content
45 3 1. provide : Replaced integer addition with subtraction → NO_COVERAGE
2. provide : Replaced integer addition with subtraction → KILLED
3. provide : Replaced integer addition with subtraction → KILLED
				String bodyContent = content.substring(idx+1);
46 3 1. provide : negated conditional → SURVIVED
2. provide : negated conditional → NO_COVERAGE
3. provide : negated conditional → KILLED
				if(msgContent instanceof UpdatableStringContent) {
47 3 1. provide : removed call to fr/sii/ogham/core/message/content/UpdatableStringContent::setStringContent → NO_COVERAGE
2. provide : removed call to fr/sii/ogham/core/message/content/UpdatableStringContent::setStringContent → KILLED
3. provide : removed call to fr/sii/ogham/core/message/content/UpdatableStringContent::setStringContent → KILLED
					((UpdatableStringContent) msgContent).setStringContent(bodyContent);
48
				} else {
49 1 1. provide : removed call to fr/sii/ogham/core/message/Message::setContent → NO_COVERAGE
					message.setContent(new StringContent(bodyContent));
50
				}
51
				// returns the subject
52 3 1. provide : replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → NO_COVERAGE
2. provide : replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → KILLED
3. provide : replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → KILLED
				return content.substring(prefix.length(), idx).trim();
53
			}
54
		}
55 4 1. provide : replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → NO_COVERAGE
2. provide : replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → TIMED_OUT
3. provide : replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → KILLED
4. provide : replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → KILLED
		return null;
56
	}
57
58
}

Mutations

40

1.1
Location : provide
Killed by : none
negated conditional → TIMED_OUT

2.2
Location : provide
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
negated conditional → KILLED

3.3
Location : provide
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : provide
Killed by : oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest.withPrefix(oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest)
negated conditional → KILLED

5.5
Location : provide
Killed by : none
negated conditional → TIMED_OUT

6.6
Location : provide
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
negated conditional → KILLED

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

8.8
Location : provide
Killed by : oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest.withPrefix(oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest)
negated conditional → KILLED

43

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

2.2
Location : provide
Killed by : none
changed conditional boundary → NO_COVERAGE

3.3
Location : provide
Killed by : none
changed conditional boundary → SURVIVED

4.4
Location : provide
Killed by : oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest.withPrefix(oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest)
negated conditional → KILLED

5.5
Location : provide
Killed by : none
negated conditional → NO_COVERAGE

6.6
Location : provide
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
negated conditional → KILLED

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

8.8
Location : provide
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
negated conditional → KILLED

9.9
Location : provide
Killed by : none
negated conditional → NO_COVERAGE

10.10
Location : provide
Killed by : none
negated conditional → TIMED_OUT

11.11
Location : provide
Killed by : oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest.noPrefix(oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest)
negated conditional → KILLED

45

1.1
Location : provide
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
Replaced integer addition with subtraction → KILLED

2.2
Location : provide
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location : provide
Killed by : oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest.withPrefix(oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest)
Replaced integer addition with subtraction → KILLED

46

1.1
Location : provide
Killed by : none
negated conditional → SURVIVED

2.2
Location : provide
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
negated conditional → KILLED

3.3
Location : provide
Killed by : none
negated conditional → NO_COVERAGE

47

1.1
Location : provide
Killed by : oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest.withPrefix(oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest)
removed call to fr/sii/ogham/core/message/content/UpdatableStringContent::setStringContent → KILLED

2.2
Location : provide
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
removed call to fr/sii/ogham/core/message/content/UpdatableStringContent::setStringContent → KILLED

3.3
Location : provide
Killed by : none
removed call to fr/sii/ogham/core/message/content/UpdatableStringContent::setStringContent → NO_COVERAGE

49

1.1
Location : provide
Killed by : none
removed call to fr/sii/ogham/core/message/Message::setContent → NO_COVERAGE

52

1.1
Location : provide
Killed by : oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest.withPrefix(oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest)
replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → KILLED

2.2
Location : provide
Killed by : none
replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → NO_COVERAGE

3.3
Location : provide
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → KILLED

55

1.1
Location : provide
Killed by : none
replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → TIMED_OUT

2.2
Location : provide
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → KILLED

3.3
Location : provide
Killed by : none
replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → NO_COVERAGE

4.4
Location : provide
Killed by : oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest.noPrefix(oghamcore.ut.email.subject.provider.TextPrefixSubjectProviderTest)
replaced return value with "" for fr/sii/ogham/core/subject/provider/TextPrefixSubjectProvider::provide → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM