JavaMailAssertions.java

1
package fr.sii.ogham.testing.assertion.internal;
2
3
import static fr.sii.ogham.testing.assertion.internal.helper.ImplementationFinder.findSender;
4
import static fr.sii.ogham.testing.assertion.util.AssertionHelper.assertThat;
5
import static org.apache.commons.lang3.reflect.FieldUtils.readField;
6
7
import java.util.Properties;
8
9
import org.hamcrest.Matcher;
10
11
import fr.sii.ogham.core.service.MessagingService;
12
import fr.sii.ogham.email.sender.impl.JavaMailSender;
13
import fr.sii.ogham.testing.util.HasParent;
14
15
/**
16
 * Helper to mke assertions on {@link JavaMailSender} instance created by Ogham.
17
 * 
18
 * @author Aurélien Baudet
19
 *
20
 */
21
public class JavaMailAssertions extends HasParent<MessagingServiceAssertions> {
22
	private final JavaMailSender javaMailSender;
23
24
	public JavaMailAssertions(MessagingServiceAssertions parent, JavaMailSender javaMailSender) {
25
		super(parent);
26
		this.javaMailSender = javaMailSender;
27
	}
28
29
	/**
30
	 * Ensure that host value is correctly configured as expected.
31
	 * 
32
	 * @param matcher
33
	 *            the matcher used to check that host is configured as expected.
34
	 * @return this instance for fluent chaining
35
	 */
36
	public JavaMailAssertions host(Matcher<String> matcher) {
37 1 1. host : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → RUN_ERROR
		assertThat(getHost(javaMailSender), matcher);
38 1 1. host : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::host → RUN_ERROR
		return this;
39
	}
40
41
	/**
42
	 * Find the {@link JavaMailSender} instance.
43
	 * 
44
	 * @param messagingService
45
	 *            the messaging service
46
	 * @return the found instance
47
	 */
48
	public static JavaMailSender getJavaMailSender(MessagingService messagingService) {
49 1 1. getJavaMailSender : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getJavaMailSender → RUN_ERROR
		return findSender(messagingService, JavaMailSender.class);
50
	}
51
52
	private String getHost(JavaMailSender javaMailSender) {
53
		Properties properties = getProperties(javaMailSender);
54 1 1. getHost : replaced return value with "" for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getHost → RUN_ERROR
		return properties.getProperty("mail.smtp.host", properties.getProperty("mail.host"));
55
	}
56
57
	private static Properties getProperties(JavaMailSender javaMailSender) {
58
		try {
59 1 1. getProperties : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getProperties → RUN_ERROR
			return (Properties) readField(javaMailSender, "properties", true);
60
		} catch (IllegalAccessException e) {
61
			throw new IllegalStateException("Failed to get 'properties' of JavaMailSender", e);
62
		}
63
	}
64
}

Mutations

37

1.1
Location : host
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → RUN_ERROR

38

1.1
Location : host
Killed by :
replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::host → RUN_ERROR

49

1.1
Location : getJavaMailSender
Killed by :
replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getJavaMailSender → RUN_ERROR

54

1.1
Location : getHost
Killed by :
replaced return value with "" for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getHost → RUN_ERROR

59

1.1
Location : getProperties
Killed by :
replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getProperties → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1