PriorizedContentHandler.java

1
package fr.sii.ogham.email.sender.impl.javamail;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.function.Predicate;
6
7
import javax.mail.Multipart;
8
import javax.mail.internet.MimePart;
9
10
import fr.sii.ogham.core.message.content.Content;
11
import fr.sii.ogham.core.util.PriorityComparator;
12
import fr.sii.ogham.core.util.PriorizedMatchingHandler;
13
import fr.sii.ogham.email.exception.handler.ContentHandlerException;
14
import fr.sii.ogham.email.exception.handler.NoContentHandlerException;
15
import fr.sii.ogham.email.message.Email;
16
17
/**
18
 * Provides a content handler based on the class of the content.
19
 * 
20
 * @author Aurélien Baudet
21
 *
22
 */
23
public class PriorizedContentHandler implements JavaMailContentHandler {
24
25
	/**
26
	 * The list of content handlers with corresponding matcher and priority
27
	 */
28
	private List<PriorizedMatchingHandler<JavaMailContentHandler>> matchingHandlers;
29
30
	/**
31
	 * Initialize with the list of content handlers with matching predicate and
32
	 * priority.
33
	 * 
34
	 * Higher priority means that handler will be used first.
35
	 * 
36
	 * @param matchingHandlers
37
	 *            the list of content handlers with the associated content
38
	 *            matcher and priority
39
	 */
40
	public PriorizedContentHandler(List<PriorizedMatchingHandler<JavaMailContentHandler>> matchingHandlers) {
41
		super();
42
		this.matchingHandlers = matchingHandlers;
43
	}
44
45
	/**
46
	 * Initialize with an empty list
47
	 */
48
	public PriorizedContentHandler() {
49
		this(new ArrayList<>());
50
	}
51
52
	@Override
53
	public void setContent(MimePart message, Multipart multipart, Email email, Content content) throws ContentHandlerException {
54
		JavaMailContentHandler contentHandler = getContentHandler(content);
55 3 1. setContent : negated conditional → TIMED_OUT
2. setContent : negated conditional → KILLED
3. setContent : negated conditional → KILLED
		if (contentHandler == null) {
56
			throw new NoContentHandlerException("there is no content handler defined for managing " + content.getClass().getSimpleName() + " content class", content);
57
		}
58 3 1. setContent : removed call to fr/sii/ogham/email/sender/impl/javamail/JavaMailContentHandler::setContent → TIMED_OUT
2. setContent : removed call to fr/sii/ogham/email/sender/impl/javamail/JavaMailContentHandler::setContent → KILLED
3. setContent : removed call to fr/sii/ogham/email/sender/impl/javamail/JavaMailContentHandler::setContent → KILLED
		contentHandler.setContent(message, multipart, email, content);
59
	}
60
61
	/**
62
	 * Register a new content handler using the provided content matcher.
63
	 * 
64
	 * @param contentMatcher
65
	 *            the class of the content to match
66
	 * @param handler
67
	 *            the content handler to use if the class matches
68
	 * @param priority
69
	 *            the priority order (means that matching handler with higher
70
	 *            priority is used)
71
	 */
72
	public void register(Predicate<Content> contentMatcher, JavaMailContentHandler handler, int priority) {
73
		matchingHandlers.add(new PriorizedMatchingHandler<>(contentMatcher, handler, priority));
74
	}
75
76
	/**
77
	 * Register a new content handler using the provided content matcher.
78
	 * 
79
	 * The priority is the registration order (first registered has higher
80
	 * priority).
81
	 * 
82
	 * @param contentMatcher
83
	 *            the class of the content
84
	 * @param handler
85
	 *            the content handler
86
	 */
87
	public void register(Predicate<Content> contentMatcher, JavaMailContentHandler handler) {
88 2 1. register : removed negation → NO_COVERAGE
2. register : removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → NO_COVERAGE
		register(contentMatcher, handler, -matchingHandlers.size());
89
	}
90
91
	/**
92
	 * Register a new content handler. The matching predicate is only based on
93
	 * the class. It means that if the class of the content is a sub-class of
94
	 * clazz parameter, then the associated handler is used.
95
	 * 
96
	 * @param clazz
97
	 *            the class of the content to match
98
	 * @param handler
99
	 *            the content handler to use if the class matches
100
	 * @param priority
101
	 *            the priority order (means that matching handler with higher
102
	 *            priority is used)
103
	 */
104
	public void register(Class<? extends Content> clazz, JavaMailContentHandler handler, int priority) {
105 11 1. lambda$register$0 : replaced boolean return with false for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → TIMED_OUT
2. lambda$register$0 : replaced boolean return with true for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → TIMED_OUT
3. lambda$register$0 : replaced boolean return with false for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → KILLED
4. lambda$register$0 : replaced boolean return with false for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → KILLED
5. lambda$register$0 : replaced boolean return with false for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → KILLED
6. lambda$register$0 : replaced boolean return with true for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → KILLED
7. lambda$register$0 : replaced boolean return with true for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → KILLED
8. register : removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED
9. register : removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED
10. register : removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED
11. register : removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED
		register(c -> clazz.isAssignableFrom(c.getClass()), handler, priority);
106
	}
107
108
	/**
109
	 * Register a new content handler. The matching predicate is only based on
110
	 * the class. It means that if the class of the content is a sub-class of
111
	 * clazz parameter, then the associated handler is used.
112
	 * 
113
	 * The priority is the registration order (first registered has higher
114
	 * priority).
115
	 * 
116
	 * @param clazz
117
	 *            the class of the content
118
	 * @param handler
119
	 *            the content handler
120
	 */
121
	public void register(Class<? extends Content> clazz, JavaMailContentHandler handler) {
122 7 1. register : removed negation → SURVIVED
2. register : removed negation → TIMED_OUT
3. register : removed negation → KILLED
4. register : removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED
5. register : removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED
6. register : removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED
7. register : removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED
		register(clazz, handler, -matchingHandlers.size());
123
	}
124
125
	private JavaMailContentHandler getContentHandler(Content content) {
126 2 1. getContentHandler : removed call to java/util/List::sort → SURVIVED
2. getContentHandler : removed call to java/util/List::sort → TIMED_OUT
		matchingHandlers.sort(new PriorityComparator<>(PriorizedMatchingHandler::getPriority));
127
		for (PriorizedMatchingHandler<JavaMailContentHandler> entry : matchingHandlers) {
128 3 1. getContentHandler : negated conditional → TIMED_OUT
2. getContentHandler : negated conditional → KILLED
3. getContentHandler : negated conditional → KILLED
			if (entry.matches(content)) {
129 3 1. getContentHandler : replaced return value with null for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::getContentHandler → TIMED_OUT
2. getContentHandler : replaced return value with null for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::getContentHandler → KILLED
3. getContentHandler : replaced return value with null for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::getContentHandler → KILLED
				return entry.getHandler();
130
			}
131
		}
132
		return null;
133
	}
134
}

Mutations

55

1.1
Location : setContent
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
negated conditional → KILLED

2.2
Location : setContent
Killed by : none
negated conditional → TIMED_OUT

3.3
Location : setContent
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
negated conditional → KILLED

58

1.1
Location : setContent
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
removed call to fr/sii/ogham/email/sender/impl/javamail/JavaMailContentHandler::setContent → KILLED

2.2
Location : setContent
Killed by : none
removed call to fr/sii/ogham/email/sender/impl/javamail/JavaMailContentHandler::setContent → TIMED_OUT

3.3
Location : setContent
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
removed call to fr/sii/ogham/email/sender/impl/javamail/JavaMailContentHandler::setContent → KILLED

88

1.1
Location : register
Killed by : none
removed negation → NO_COVERAGE

2.2
Location : register
Killed by : none
removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → NO_COVERAGE

105

1.1
Location : lambda$register$0
Killed by : none
replaced boolean return with false for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → TIMED_OUT

2.2
Location : lambda$register$0
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
replaced boolean return with false for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → KILLED

3.3
Location : lambda$register$0
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredResourceResolutionCantAttachFilesFromPath(oghamall.it.configuration.EmptyBuilderTest)
replaced boolean return with false for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → KILLED

4.4
Location : lambda$register$0
Killed by : oghamspringbootv1autoconfigure.it.SpringWebBeanResolutionTest.emailUsingThymeleafTemplateShouldResolveBeansAndUrls(oghamspringbootv1autoconfigure.it.SpringWebBeanResolutionTest)
replaced boolean return with false for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → KILLED

5.5
Location : lambda$register$0
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
replaced boolean return with true for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → KILLED

6.6
Location : lambda$register$0
Killed by : none
replaced boolean return with true for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → TIMED_OUT

7.7
Location : lambda$register$0
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
replaced boolean return with true for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::lambda$register$0 → KILLED

8.8
Location : register
Killed by : oghamspringbootv2autoconfigure.it.StaticMethodAccessTest.emailUsingFreemarkerTemplateShouldBeAbleToCallStaticMethodsWithCustomVariableName(oghamspringbootv2autoconfigure.it.StaticMethodAccessTest)
removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED

9.9
Location : register
Killed by : oghamspringbootv1autoconfigure.it.StaticMethodsAccessTest.emailUsingFreemarkerTemplateShouldBeAbleToCallStaticMethods(oghamspringbootv1autoconfigure.it.StaticMethodsAccessTest)
removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED

10.10
Location : register
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredResourceResolutionCantAttachFilesFromPath(oghamall.it.configuration.EmptyBuilderTest)
removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED

11.11
Location : register
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED

122

1.1
Location : register
Killed by : none
removed negation → TIMED_OUT

2.2
Location : register
Killed by : none
removed negation → SURVIVED

3.3
Location : register
Killed by : oghamall.it.resolver.FreemarkerRelativeResourcesTests.relativeToPrefixSuffixAndPath(oghamall.it.resolver.FreemarkerRelativeResourcesTests)
removed negation → KILLED

4.4
Location : register
Killed by : oghamspringbootv1autoconfigure.it.StaticMethodsAccessTest.emailUsingFreemarkerTemplateShouldBeAbleToCallStaticMethods(oghamspringbootv1autoconfigure.it.StaticMethodsAccessTest)
removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED

5.5
Location : register
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED

6.6
Location : register
Killed by : oghamspringbootv2autoconfigure.it.StaticMethodAccessTest.emailUsingFreemarkerTemplateShouldBeAbleToCallStaticMethodsWithCustomVariableName(oghamspringbootv2autoconfigure.it.StaticMethodAccessTest)
removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED

7.7
Location : register
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredResourceResolutionCantAttachFilesFromPath(oghamall.it.configuration.EmptyBuilderTest)
removed call to fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::register → KILLED

126

1.1
Location : getContentHandler
Killed by : none
removed call to java/util/List::sort → TIMED_OUT

2.2
Location : getContentHandler
Killed by : none
removed call to java/util/List::sort → SURVIVED

128

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

2.2
Location : getContentHandler
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
negated conditional → KILLED

3.3
Location : getContentHandler
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
negated conditional → KILLED

129

1.1
Location : getContentHandler
Killed by : oghamjavamail.it.JavaMailStructureTest.plainTextBody(oghamjavamail.it.JavaMailStructureTest)
replaced return value with null for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::getContentHandler → KILLED

2.2
Location : getContentHandler
Killed by : none
replaced return value with null for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::getContentHandler → TIMED_OUT

3.3
Location : getContentHandler
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredResourceResolutionCantAttachFilesFromPath(oghamall.it.configuration.EmptyBuilderTest)
replaced return value with null for fr/sii/ogham/email/sender/impl/javamail/PriorizedContentHandler::getContentHandler → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM