1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.surefire;
20
21 import java.util.Arrays;
22 import java.util.Collection;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.artifact.DefaultArtifact;
26 import org.apache.maven.surefire.providerapi.ProviderInfo;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.Parameterized;
30
31 import static org.assertj.core.api.Assertions.assertThat;
32 import static org.mockito.Mockito.spy;
33 import static org.mockito.Mockito.when;
34
35
36
37
38 @RunWith(Parameterized.class)
39 public class AbstractSurefireMojoJunitCoreProvidersInfoTest {
40 private final Artifact junitArtifact;
41 private final Artifact junitDepArtifact;
42 private final boolean isParallel;
43 private final boolean hasGroups;
44
45 private final boolean isApplicable;
46
47 @Parameterized.Parameters(name = "{index}: junit={0}, junitDep={1}, parallel={2}, groups={3} then isApplicable={4}")
48 public static Collection<Object[]> data() {
49 return Arrays.asList(new Object[][] {
50
51 {null, null, false, false, false},
52 {null, null, true, false, false},
53 {null, null, false, true, false},
54 {null, null, true, true, false},
55
56
57
58 {"4.5", null, false, false, false},
59 {"4.7", null, false, false, false},
60
61
62 {"4.5", null, true, false, false},
63 {"4.7", null, true, false, true},
64
65
66 {"4.5", null, false, true, false},
67 {"4.7", null, false, true, true},
68
69
70
71 {null, "4.5", false, false, false},
72 {null, "4.7", false, false, false},
73
74
75 {null, "4.5", true, false, false},
76 {null, "4.7", true, false, true},
77
78
79 {null, "4.5", false, true, false},
80 {null, "4.7", false, true, true}
81 });
82 }
83
84 public AbstractSurefireMojoJunitCoreProvidersInfoTest(
85 String junitVersion, String junitDepVersion, boolean isParallel, boolean hasGroups, boolean isApplicable) {
86 this.junitArtifact = junitVersion != null ? aArtifact(junitVersion) : null;
87 this.junitDepArtifact = junitDepVersion != null ? aArtifact(junitDepVersion) : null;
88 this.isParallel = isParallel;
89 this.hasGroups = hasGroups;
90 this.isApplicable = isApplicable;
91 }
92
93 private Artifact aArtifact(String version) {
94 return new DefaultArtifact("test", "test", version, "test", "jar", "", null);
95 }
96
97 @Test
98 public void test() {
99 AbstractSurefireMojo mojo = spy(AbstractSurefireMojo.class);
100
101 when(mojo.isAnyConcurrencySelected()).thenReturn(isParallel);
102 when(mojo.isAnyGroupsSelected()).thenReturn(hasGroups);
103
104 ProviderInfo providerInfo = mojo.new JUnitCoreProviderInfo(junitArtifact, junitDepArtifact);
105
106 assertThat(providerInfo.isApplicable()).isEqualTo(isApplicable);
107 }
108 }