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 |
2
1. host : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE 2. host : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED |
assertThat(getHost(javaMailSender), matcher); |
38 |
3
1. host : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::host → NO_COVERAGE 2. host : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::host → SURVIVED 3. host : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::host → TIMED_OUT |
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 |
4
1. getJavaMailSender : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getJavaMailSender → NO_COVERAGE 2. getJavaMailSender : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getJavaMailSender → TIMED_OUT 3. getJavaMailSender : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getJavaMailSender → KILLED 4. getJavaMailSender : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getJavaMailSender → KILLED |
return findSender(messagingService, JavaMailSender.class); |
50 | } | |
51 | ||
52 | private String getHost(JavaMailSender javaMailSender) { | |
53 | Properties properties = getProperties(javaMailSender); | |
54 |
4
1. getHost : replaced return value with "" for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getHost → NO_COVERAGE 2. getHost : replaced return value with "" for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getHost → KILLED 3. getHost : replaced return value with "" for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getHost → KILLED 4. getHost : replaced return value with "" for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getHost → KILLED |
return properties.getProperty("mail.smtp.host", properties.getProperty("mail.host")); |
55 | } | |
56 | ||
57 | private static Properties getProperties(JavaMailSender javaMailSender) { | |
58 | try { | |
59 |
4
1. getProperties : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getProperties → NO_COVERAGE 2. getProperties : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getProperties → KILLED 3. getProperties : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getProperties → KILLED 4. getProperties : replaced return value with null for fr/sii/ogham/testing/assertion/internal/JavaMailAssertions::getProperties → KILLED |
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 2.2 |
|
38 |
1.1 2.2 3.3 |
|
49 |
1.1 2.2 3.3 4.4 |
|
54 |
1.1 2.2 3.3 4.4 |
|
59 |
1.1 2.2 3.3 4.4 |