MultiContent.java

1
package fr.sii.ogham.core.message.content;
2
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.List;
6
7
import fr.sii.ogham.core.util.ArrayUtils;
8
import fr.sii.ogham.core.util.EqualsBuilder;
9
import fr.sii.ogham.core.util.HashCodeBuilder;
10
11
/**
12
 * Decorator content that provide ability to handle several sub contents. The
13
 * aim is to be able to handle messages with several distinct contents like
14
 * email for example that can contain at the same time an HTML message and a
15
 * text message. The email client implementation is free to display the content
16
 * it is able to handle.
17
 * 
18
 * @author Aurélien Baudet
19
 *
20
 */
21
public class MultiContent implements Content {
22
	/**
23
	 * The list of sub contents
24
	 */
25
	private final List<Content> contents;
26
27
	/**
28
	 * Initialize the content with one or several sub contents directly as strings.
29
	 * 
30
	 * @param content
31
	 *            the mandatory content
32
	 * @param contents
33
	 *            the contents either as array or multiple arguments
34
	 */
35
	public MultiContent(String content, String... contents) {
36
		this(toContent(ArrayUtils.concat(content, contents)));
37
	}
38
39
	/**
40
	 * Initialize the content with none, one or several sub contents.
41
	 * 
42
	 * @param contents
43
	 *            the contents either as array or multiple arguments
44
	 */
45
	public MultiContent(Content... contents) {
46
		this(new ArrayList<>(Arrays.asList(contents)));
47
	}
48
49
	/**
50
	 * Initialize the content with a list of sub contents
51
	 * 
52
	 * @param contents
53
	 *            the list of sub contents
54
	 */
55
	public MultiContent(List<Content> contents) {
56
		super();
57
		this.contents = contents;
58
	}
59
60
	public List<Content> getContents() {
61 4 1. getContents : replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → NO_COVERAGE
2. getContents : replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → KILLED
3. getContents : replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → KILLED
4. getContents : replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → KILLED
		return contents;
62
	}
63
64
	/**
65
	 * Add a sub content to the list of sub contents.
66
	 * 
67
	 * @param content
68
	 *            the content to add
69
	 */
70
	public void addContent(Content content) {
71
		contents.add(content);
72
	}
73
74
	@Override
75
	public String toString() {
76
		StringBuilder builder = new StringBuilder();
77
		builder.append("MultiContent [contents=").append(contents).append("]");
78 1 1. toString : replaced return value with "" for fr/sii/ogham/core/message/content/MultiContent::toString → NO_COVERAGE
		return builder.toString();
79
	}
80
	
81
	@Override
82
	public int hashCode() {
83 2 1. hashCode : replaced int return with 0 for fr/sii/ogham/core/message/content/MultiContent::hashCode → NO_COVERAGE
2. hashCode : replaced int return with 0 for fr/sii/ogham/core/message/content/MultiContent::hashCode → KILLED
		return new HashCodeBuilder().append(contents).hashCode();
84
	}
85
86
	@Override
87
	public boolean equals(Object obj) {
88 4 1. equals : replaced boolean return with false for fr/sii/ogham/core/message/content/MultiContent::equals → NO_COVERAGE
2. equals : replaced boolean return with true for fr/sii/ogham/core/message/content/MultiContent::equals → NO_COVERAGE
3. equals : replaced boolean return with false for fr/sii/ogham/core/message/content/MultiContent::equals → KILLED
4. equals : replaced boolean return with true for fr/sii/ogham/core/message/content/MultiContent::equals → KILLED
		return new EqualsBuilder(this, obj).appendFields("contents").isEqual();
89
	}
90
	
91
	private static Content[] toContent(String[] strs) {
92
		Content[] contents = new Content[strs.length];
93 4 1. toContent : changed conditional boundary → NO_COVERAGE
2. toContent : negated conditional → NO_COVERAGE
3. toContent : changed conditional boundary → KILLED
4. toContent : negated conditional → KILLED
		for(int i=0 ; i<strs.length ; i++) {
94
			contents[i] = new StringContent(strs[i]);
95
		}
96 2 1. toContent : replaced return value with null for fr/sii/ogham/core/message/content/MultiContent::toContent → NO_COVERAGE
2. toContent : replaced return value with null for fr/sii/ogham/core/message/content/MultiContent::toContent → KILLED
		return contents;
97
	}
98
}

Mutations

61

1.1
Location : getContents
Killed by : none
replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → NO_COVERAGE

2.2
Location : getContents
Killed by : oghamjavamail.it.JavaMailStructureTest.htmlAndTextBodyWithAttachments(oghamjavamail.it.JavaMailStructureTest)
replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → KILLED

3.3
Location : getContents
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → KILLED

4.4
Location : getContents
Killed by : oghamcore.ut.core.translator.content.MultiContentTranslatorTest.nullTextShouldReturnOneParsedContent(oghamcore.ut.core.translator.content.MultiContentTranslatorTest)
replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → KILLED

78

1.1
Location : toString
Killed by : none
replaced return value with "" for fr/sii/ogham/core/message/content/MultiContent::toString → NO_COVERAGE

83

1.1
Location : hashCode
Killed by : oghamcore.ut.core.EqualsTest.multiContent(oghamcore.ut.core.EqualsTest)
replaced int return with 0 for fr/sii/ogham/core/message/content/MultiContent::hashCode → KILLED

2.2
Location : hashCode
Killed by : none
replaced int return with 0 for fr/sii/ogham/core/message/content/MultiContent::hashCode → NO_COVERAGE

88

1.1
Location : equals
Killed by : oghamcore.ut.core.EqualsTest.multiContent(oghamcore.ut.core.EqualsTest)
replaced boolean return with false for fr/sii/ogham/core/message/content/MultiContent::equals → KILLED

2.2
Location : equals
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/message/content/MultiContent::equals → NO_COVERAGE

3.3
Location : equals
Killed by : oghamcore.ut.core.EqualsTest.multiContent(oghamcore.ut.core.EqualsTest)
replaced boolean return with true for fr/sii/ogham/core/message/content/MultiContent::equals → KILLED

4.4
Location : equals
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/message/content/MultiContent::equals → NO_COVERAGE

93

1.1
Location : toContent
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : toContent
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
changed conditional boundary → KILLED

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

4.4
Location : toContent
Killed by : none
negated conditional → NO_COVERAGE

96

1.1
Location : toContent
Killed by : none
replaced return value with null for fr/sii/ogham/core/message/content/MultiContent::toContent → NO_COVERAGE

2.2
Location : toContent
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
replaced return value with null for fr/sii/ogham/core/message/content/MultiContent::toContent → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM