ContentTranslatorSender.java

1
package fr.sii.ogham.core.sender;
2
3
import org.slf4j.Logger;
4
import org.slf4j.LoggerFactory;
5
6
import fr.sii.ogham.core.exception.MessageException;
7
import fr.sii.ogham.core.exception.MessageNotSentException;
8
import fr.sii.ogham.core.exception.handler.ContentTranslatorException;
9
import fr.sii.ogham.core.message.Message;
10
import fr.sii.ogham.core.translator.content.ContentTranslator;
11
12
/**
13
 * Decorator sender that transforms the content of the message before really
14
 * sending it. This sender relies on {@link ContentTranslator} to transform the
15
 * message content. Once the content has been updated, then this sender
16
 * delegates to a real implementation the sending of the message.
17
 * 
18
 * @author Aurélien Baudet
19
 * @see ContentTranslator
20
 */
21
public class ContentTranslatorSender implements ConditionalSender {
22
	private static final Logger LOG = LoggerFactory.getLogger(ContentTranslatorSender.class);
23
24
	/**
25
	 * The translator that transforms the content of the message
26
	 */
27
	private ContentTranslator translator;
28
29
	/**
30
	 * The decorated sender that will really send the message
31
	 */
32
	private MessageSender delegate;
33
34
	/**
35
	 * Initialize the sender with the provided translator and decorated sender.
36
	 * The translator implementation will transform the content of the message.
37
	 * The decorated sender will really send the message.
38
	 * 
39
	 * @param translator
40
	 *            the translator implementation that will transform the content
41
	 *            of the message
42
	 * @param delegate
43
	 *            The decorated sender will really send the message
44
	 */
45
	public ContentTranslatorSender(ContentTranslator translator, MessageSender delegate) {
46
		super();
47
		this.translator = translator;
48
		this.delegate = delegate;
49
	}
50
51
	@Override
52
	public boolean supports(Message message) {
53 1 1. supports : negated conditional → RUN_ERROR
		if (delegate instanceof ConditionalSender) {
54 2 1. supports : replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → RUN_ERROR
2. supports : replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → RUN_ERROR
			return ((ConditionalSender) delegate).supports(message);
55
		}
56 1 1. supports : replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → NO_COVERAGE
		return true;
57
	}
58
59
	@Override
60
	public void send(Message message) throws MessageException {
61
		try {
62
			LOG.debug("Translate the message content using {}", translator);
63
			LOG.trace("content: {}", message.getContent());
64 1 1. send : removed call to fr/sii/ogham/core/message/Message::setContent → RUN_ERROR
			message.setContent(translator.translate(message.getContent()));
65
			LOG.debug("Message content translated using {}", translator);
66
			LOG.trace("content: {}", message.getContent());
67
			LOG.debug("Sending translated message using {}", delegate);
68
			LOG.trace("message: {}", message);
69 1 1. send : removed call to fr/sii/ogham/core/sender/MessageSender::send → RUN_ERROR
			delegate.send(message);
70
		} catch (ContentTranslatorException e) {
71
			throw new MessageNotSentException("Failed to send message due to content handler", message, e);
72
		}
73
	}
74
75
	@Override
76
	public String toString() {
77
		StringBuilder builder = new StringBuilder();
78
		builder.append("ContentTranslatorSender [translator=").append(translator).append(", delegate=").append(delegate).append("]");
79 1 1. toString : replaced return value with "" for fr/sii/ogham/core/sender/ContentTranslatorSender::toString → RUN_ERROR
		return builder.toString();
80
	}
81
}

Mutations

53

1.1
Location : supports
Killed by :
negated conditional → RUN_ERROR

54

1.1
Location : supports
Killed by :
replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → RUN_ERROR

2.2
Location : supports
Killed by :
replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → RUN_ERROR

56

1.1
Location : supports
Killed by :
replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → NO_COVERAGE

64

1.1
Location : send
Killed by :
removed call to fr/sii/ogham/core/message/Message::setContent → RUN_ERROR

69

1.1
Location : send
Killed by :
removed call to fr/sii/ogham/core/sender/MessageSender::send → RUN_ERROR

79

1.1
Location : toString
Killed by :
replaced return value with "" for fr/sii/ogham/core/sender/ContentTranslatorSender::toString → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1