1 | package fr.sii.ogham.testing.extension.junit.email; | |
2 | ||
3 | import static java.util.Arrays.stream; | |
4 | import static java.util.stream.Collectors.toList; | |
5 | ||
6 | import java.util.List; | |
7 | ||
8 | import org.junit.runners.model.FrameworkMethod; | |
9 | import org.junit.runners.model.Statement; | |
10 | ||
11 | import com.icegreen.greenmail.junit4.GreenMailRule; | |
12 | import com.icegreen.greenmail.server.AbstractServer; | |
13 | import com.icegreen.greenmail.util.ServerSetup; | |
14 | ||
15 | import fr.sii.ogham.testing.util.RandomPortUtils; | |
16 | ||
17 | /** | |
18 | * Just an extension for {@link GreenMailRule} to handle random port instead of | |
19 | * fixed port. | |
20 | * | |
21 | * @author Aurélien Baudet | |
22 | * | |
23 | */ | |
24 | public class RandomPortGreenMailRule extends GreenMailRule { | |
25 | ||
26 | /** | |
27 | * Initialize the rule for the SMTP protocol only (random port). | |
28 | */ | |
29 | public RandomPortGreenMailRule() { | |
30 | this(ServerSetup.PROTOCOL_SMTP); | |
31 | } | |
32 | ||
33 | /** | |
34 | * Initialize the rule for the provided protocols (random port for each | |
35 | * protocol). | |
36 | * | |
37 | * The random port range is [{@link RandomPortUtils#PORT_RANGE_MIN}, | |
38 | * {@link RandomPortUtils#PORT_RANGE_MAX}]. | |
39 | * | |
40 | * @param protocols | |
41 | * the list of protocols to start | |
42 | */ | |
43 | public RandomPortGreenMailRule(String... protocols) { | |
44 | this(RandomPortUtils.PORT_RANGE_MIN, RandomPortUtils.PORT_RANGE_MAX, protocols); | |
45 | } | |
46 | ||
47 | /** | |
48 | * Initialize the rule for the provided protocols (random port for each | |
49 | * protocol). | |
50 | * | |
51 | * The random port range is [{@link RandomPortUtils#PORT_RANGE_MIN}, | |
52 | * maxPort]. | |
53 | * | |
54 | * @param maxPort | |
55 | * the maximum port | |
56 | * @param protocols | |
57 | * the list of protocols to start | |
58 | */ | |
59 | public RandomPortGreenMailRule(int maxPort, String... protocols) { | |
60 | this(RandomPortUtils.PORT_RANGE_MIN, maxPort, protocols); | |
61 | } | |
62 | ||
63 | /** | |
64 | * Initialize the rule for the provided protocols (random port for each | |
65 | * protocol). | |
66 | * | |
67 | * The random port range is [minPort, maxPort]. | |
68 | * | |
69 | * @param minPort | |
70 | * the minimum port | |
71 | * @param maxPort | |
72 | * the maximum port | |
73 | * @param protocols | |
74 | * the list of protocols to start | |
75 | */ | |
76 | public RandomPortGreenMailRule(int minPort, int maxPort, String... protocols) { | |
77 | super(toServerSetup(minPort, maxPort, protocols)); | |
78 | } | |
79 | ||
80 | @Override | |
81 | public Statement apply(final Statement base, FrameworkMethod method, Object target) { | |
82 |
5
1. apply : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::apply → NO_COVERAGE 2. apply : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::apply → KILLED 3. apply : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::apply → KILLED 4. apply : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::apply → KILLED 5. apply : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::apply → KILLED |
return super.apply(new Statement() { |
83 | @Override | |
84 | public void evaluate() throws Throwable { | |
85 | try { | |
86 |
2
1. evaluate : removed call to org/junit/runners/model/Statement::evaluate → SURVIVED 2. evaluate : removed call to org/junit/runners/model/Statement::evaluate → NO_COVERAGE |
base.evaluate(); |
87 | } finally { | |
88 |
3
1. evaluate : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::access$000 → NO_COVERAGE 2. evaluate : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::access$000 → SURVIVED 3. evaluate : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::access$000 → TIMED_OUT |
resetPorts(); |
89 | } | |
90 | } | |
91 | }, method, target); | |
92 | } | |
93 | ||
94 | private void resetPorts() { | |
95 |
3
1. resetPorts : negated conditional → NO_COVERAGE 2. resetPorts : negated conditional → SURVIVED 3. resetPorts : negated conditional → TIMED_OUT |
if (getGreenMail() != null) { |
96 |
3
1. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → NO_COVERAGE 2. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → SURVIVED 3. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → TIMED_OUT |
resetPort(getGreenMail().getImap()); |
97 |
3
1. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → SURVIVED 2. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → NO_COVERAGE 3. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → TIMED_OUT |
resetPort(getGreenMail().getImaps()); |
98 |
3
1. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → SURVIVED 2. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → NO_COVERAGE 3. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → TIMED_OUT |
resetPort(getGreenMail().getPop3()); |
99 |
3
1. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → SURVIVED 2. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → NO_COVERAGE 3. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → TIMED_OUT |
resetPort(getGreenMail().getPop3s()); |
100 |
3
1. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → SURVIVED 2. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → NO_COVERAGE 3. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → TIMED_OUT |
resetPort(getGreenMail().getSmtp()); |
101 |
3
1. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → SURVIVED 2. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → NO_COVERAGE 3. resetPorts : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → TIMED_OUT |
resetPort(getGreenMail().getSmtps()); |
102 | } | |
103 | } | |
104 | ||
105 | private static void resetPort(AbstractServer server) { | |
106 |
5
1. resetPort : negated conditional → NO_COVERAGE 2. resetPort : negated conditional → TIMED_OUT 3. resetPort : negated conditional → KILLED 4. resetPort : negated conditional → KILLED 5. resetPort : negated conditional → KILLED |
if (server != null) { |
107 |
3
1. resetPort : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → SURVIVED 2. resetPort : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → NO_COVERAGE 3. resetPort : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::resetPort → TIMED_OUT |
resetPort(server.getServerSetup()); |
108 | } | |
109 | } | |
110 | ||
111 | private static void resetPort(ServerSetup setup) { | |
112 |
5
1. resetPort : negated conditional → NO_COVERAGE 2. resetPort : negated conditional → TIMED_OUT 3. resetPort : negated conditional → KILLED 4. resetPort : negated conditional → KILLED 5. resetPort : negated conditional → KILLED |
if (setup instanceof RandomPortServerSetup) { |
113 |
1
1. resetPort : removed call to fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::resetPort → NO_COVERAGE |
((RandomPortServerSetup) setup).resetPort(); |
114 | } | |
115 | } | |
116 | ||
117 | private static ServerSetup[] toServerSetup(int minPort, int maxPort, String... protocols) { | |
118 |
5
1. lambda$toServerSetup$0 : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::lambda$toServerSetup$0 → NO_COVERAGE 2. lambda$toServerSetup$0 : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::lambda$toServerSetup$0 → KILLED 3. lambda$toServerSetup$0 : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::lambda$toServerSetup$0 → KILLED 4. lambda$toServerSetup$0 : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::lambda$toServerSetup$0 → KILLED 5. lambda$toServerSetup$0 : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::lambda$toServerSetup$0 → KILLED |
List<ServerSetup> list = stream(protocols).map(p -> new RandomPortServerSetup(minPort, maxPort, p)).collect(toList()); |
119 |
5
1. toServerSetup : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::toServerSetup → NO_COVERAGE 2. toServerSetup : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::toServerSetup → KILLED 3. toServerSetup : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::toServerSetup → KILLED 4. toServerSetup : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::toServerSetup → KILLED 5. toServerSetup : replaced return value with null for fr/sii/ogham/testing/extension/junit/email/RandomPortGreenMailRule::toServerSetup → KILLED |
return list.toArray(new ServerSetup[list.size()]); |
120 | } | |
121 | } | |
Mutations | ||
82 |
1.1 2.2 3.3 4.4 5.5 |
|
86 |
1.1 2.2 |
|
88 |
1.1 2.2 3.3 |
|
95 |
1.1 2.2 3.3 |
|
96 |
1.1 2.2 3.3 |
|
97 |
1.1 2.2 3.3 |
|
98 |
1.1 2.2 3.3 |
|
99 |
1.1 2.2 3.3 |
|
100 |
1.1 2.2 3.3 |
|
101 |
1.1 2.2 3.3 |
|
106 |
1.1 2.2 3.3 4.4 5.5 |
|
107 |
1.1 2.2 3.3 |
|
112 |
1.1 2.2 3.3 4.4 5.5 |
|
113 |
1.1 |
|
118 |
1.1 2.2 3.3 4.4 5.5 |
|
119 |
1.1 2.2 3.3 4.4 5.5 |