1 | package fr.sii.ogham.testing.assertion.internal; | |
2 | ||
3 | import static fr.sii.ogham.testing.assertion.internal.helper.ImplementationFinder.findParsers; | |
4 | import static java.util.stream.Collectors.toSet; | |
5 | ||
6 | import java.util.Set; | |
7 | ||
8 | import fr.sii.ogham.core.service.MessagingService; | |
9 | import fr.sii.ogham.email.message.Email; | |
10 | import fr.sii.ogham.sms.message.Sms; | |
11 | import fr.sii.ogham.template.freemarker.FreeMarkerParser; | |
12 | import fr.sii.ogham.testing.assertion.internal.helper.FoundParser; | |
13 | import fr.sii.ogham.testing.util.HasParent; | |
14 | import freemarker.template.Configuration; | |
15 | ||
16 | /** | |
17 | * Helper class to make assertions on FreeMarker instances created by Ogham. | |
18 | * | |
19 | * For example, to ensure that particular configuration is used for emails: | |
20 | * | |
21 | * <pre> | |
22 | * {@code | |
23 | * email() | |
24 | * .configuration() | |
25 | * .defaultEncoding(equalTo("UTF-8")) | |
26 | * } | |
27 | * </pre> | |
28 | * | |
29 | * @author Aurélien Baudet | |
30 | * | |
31 | */ | |
32 | public class FreemarkerAssersions extends HasParent<MessagingServiceAssertions> { | |
33 | private final Set<FoundParser<FreeMarkerParser>> freeMarkerParsers; | |
34 | ||
35 | public FreemarkerAssersions(MessagingServiceAssertions parent, Set<FoundParser<FreeMarkerParser>> freeMarkerParsers) { | |
36 | super(parent); | |
37 | this.freeMarkerParsers = freeMarkerParsers; | |
38 | } | |
39 | ||
40 | /** | |
41 | * Make assertions on {@link FreeMarkerParser} for both email and sms. | |
42 | * | |
43 | * For example, to ensure that all FreeMarker {@link Configuration} uses the | |
44 | * right default encoding: | |
45 | * | |
46 | * <pre> | |
47 | * {@code | |
48 | * all() | |
49 | * .configuration() | |
50 | * .defaultEncoding(equalTo("UTF-8")) | |
51 | * } | |
52 | * </pre> | |
53 | * | |
54 | * @return builder for fluent chaining | |
55 | */ | |
56 | public FreemarkerParserAssertions all() { | |
57 |
4
1. all : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::all → NO_COVERAGE 2. all : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::all → TIMED_OUT 3. all : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::all → KILLED 4. all : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::all → KILLED |
return new FreemarkerParserAssertions(this, freeMarkerParsers.stream() |
58 | .map(FoundParser::getParser) | |
59 | .collect(toSet())); | |
60 | } | |
61 | ||
62 | /** | |
63 | * Make assertions on {@link FreeMarkerParser} instantiated for sending | |
64 | * emails only. | |
65 | * | |
66 | * For example, to ensure that FreeMarker {@link Configuration} used by | |
67 | * email uses the right default encoding: | |
68 | * | |
69 | * <pre> | |
70 | * {@code | |
71 | * email() | |
72 | * .configuration() | |
73 | * .defaultEncoding(equalTo("UTF-8")) | |
74 | * } | |
75 | * </pre> | |
76 | * | |
77 | * @return builder for fluent chaining | |
78 | */ | |
79 | public FreemarkerParserAssertions email() { | |
80 | // @formatter:off | |
81 |
1
1. email : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::email → NO_COVERAGE |
return new FreemarkerParserAssertions(this, freeMarkerParsers.stream() |
82 |
2
1. lambda$email$0 : replaced boolean return with false for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::lambda$email$0 → NO_COVERAGE 2. lambda$email$0 : replaced boolean return with true for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::lambda$email$0 → NO_COVERAGE |
.filter(f -> f.getMessageType().equals(Email.class)) |
83 | .map(FoundParser::getParser) | |
84 | .collect(toSet())); | |
85 | // @formatter:on | |
86 | } | |
87 | ||
88 | /** | |
89 | * Make assertions on {@link FreeMarkerParser} instantiated for sending sms | |
90 | * only. | |
91 | * | |
92 | * For example, to ensure that FreeMarker {@link Configuration} used by sms | |
93 | * uses the right default encoding: | |
94 | * | |
95 | * <pre> | |
96 | * {@code | |
97 | * sms() | |
98 | * .configuration() | |
99 | * .defaultEncoding(equalTo("UTF-8")) | |
100 | * } | |
101 | * </pre> | |
102 | * | |
103 | * @return builder for fluent chaining | |
104 | */ | |
105 | public FreemarkerParserAssertions sms() { | |
106 | // @formatter:off | |
107 |
1
1. sms : replaced return value with null for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::sms → NO_COVERAGE |
return new FreemarkerParserAssertions(this, freeMarkerParsers.stream() |
108 |
2
1. lambda$sms$1 : replaced boolean return with false for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::lambda$sms$1 → NO_COVERAGE 2. lambda$sms$1 : replaced boolean return with true for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::lambda$sms$1 → NO_COVERAGE |
.filter(f -> f.getMessageType().equals(Sms.class)) |
109 | .map(FoundParser::getParser) | |
110 | .collect(toSet())); | |
111 | // @formatter:on | |
112 | } | |
113 | ||
114 | /** | |
115 | * Find instances of {@link FreeMarkerParser} | |
116 | * | |
117 | * @param messagingService | |
118 | * the messaging service | |
119 | * @return the found instances | |
120 | */ | |
121 | public static Set<FoundParser<FreeMarkerParser>> getFreemarkerParsers(MessagingService messagingService) { | |
122 |
3
1. getFreemarkerParsers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::getFreemarkerParsers → SURVIVED 2. getFreemarkerParsers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::getFreemarkerParsers → NO_COVERAGE 3. getFreemarkerParsers : replaced return value with Collections.emptyList for fr/sii/ogham/testing/assertion/internal/FreemarkerAssersions::getFreemarkerParsers → TIMED_OUT |
return findParsers(messagingService, FreeMarkerParser.class); |
123 | } | |
124 | ||
125 | } | |
Mutations | ||
57 |
1.1 2.2 3.3 4.4 |
|
81 |
1.1 |
|
82 |
1.1 2.2 |
|
107 |
1.1 |
|
108 |
1.1 2.2 |
|
122 |
1.1 2.2 3.3 |