View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * Testing JUnitCoreProviderInfo applicable behavior.
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              // junit and junitDep are null
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              // only junit artifact
57              // without parallel and groups
58              {"4.5", null, false, false, false},
59              {"4.7", null, false, false, false},
60  
61              // with parallel
62              {"4.5", null, true, false, false},
63              {"4.7", null, true, false, true},
64  
65              // with groups
66              {"4.5", null, false, true, false},
67              {"4.7", null, false, true, true},
68  
69              // only junitDep artifact
70              // without parallel and groups
71              {null, "4.5", false, false, false},
72              {null, "4.7", false, false, false},
73  
74              // with parallel
75              {null, "4.5", true, false, false},
76              {null, "4.7", true, false, true},
77  
78              // with groups
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 }