View Javadoc
1   package org.apache.maven.plugin.surefire;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.DefaultArtifact;
24  import org.apache.maven.artifact.handler.ArtifactHandler;
25  import org.apache.maven.artifact.versioning.VersionRange;
26  import org.apache.maven.plugin.surefire.log.PluginConsoleLogger;
27  import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
28  import org.apache.maven.surefire.booter.Classpath;
29  import org.apache.maven.surefire.booter.ModularClasspathConfiguration;
30  import org.apache.maven.surefire.booter.StartupConfiguration;
31  import org.apache.maven.surefire.extensions.ForkNodeFactory;
32  import org.apache.maven.surefire.api.suite.RunResult;
33  import org.apache.maven.surefire.api.util.DefaultScanResult;
34  import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
35  import org.codehaus.plexus.languages.java.jpms.LocationManager;
36  import org.codehaus.plexus.languages.java.jpms.ResolvePathResult;
37  import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;
38  import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult;
39  import org.codehaus.plexus.languages.java.jpms.ModuleNameSource;
40  import org.codehaus.plexus.logging.Logger;
41  import org.junit.Test;
42  import org.junit.runner.RunWith;
43  import org.mockito.ArgumentCaptor;
44  import org.mockito.Mock;
45  import org.powermock.core.classloader.annotations.PowerMockIgnore;
46  import org.powermock.core.classloader.annotations.PrepareForTest;
47  import org.powermock.modules.junit4.PowerMockRunner;
48  
49  import java.io.File;
50  import java.util.HashMap;
51  import java.util.List;
52  import java.util.LinkedHashMap;
53  import java.util.Map;
54  import java.util.Set;
55  
56  import static java.util.Arrays.asList;
57  import static java.util.Collections.singleton;
58  import static java.util.Collections.singletonMap;
59  import static org.apache.maven.artifact.versioning.VersionRange.createFromVersion;
60  import static org.fest.assertions.Assertions.assertThat;
61  import static org.fest.assertions.Index.atIndex;
62  import static org.mockito.ArgumentMatchers.anyString;
63  import static org.mockito.ArgumentMatchers.eq;
64  import static org.mockito.Mockito.never;
65  import static org.mockito.Mockito.times;
66  import static org.mockito.Mockito.verify;
67  import static org.mockito.Mockito.when;
68  import static org.powermock.api.mockito.PowerMockito.doReturn;
69  import static org.powermock.api.mockito.PowerMockito.doNothing;
70  import static org.powermock.api.mockito.PowerMockito.mock;
71  import static org.powermock.api.mockito.PowerMockito.mockStatic;
72  import static org.powermock.api.mockito.PowerMockito.spy;
73  import static org.powermock.api.mockito.PowerMockito.verifyStatic;
74  import static org.powermock.reflect.Whitebox.invokeMethod;
75  
76  /**
77   * Test for {@link AbstractSurefireMojo}.
78   */
79  @RunWith( PowerMockRunner.class )
80  @PrepareForTest( { AbstractSurefireMojo.class, ResolvePathsRequest.class } )
81  @PowerMockIgnore( { "org.jacoco.agent.rt.*", "com.vladium.emma.rt.*" } )
82  public class AbstractSurefireMojoJava7PlusTest
83  {
84      @Mock
85      private ArtifactHandler handler;
86  
87      @Mock
88      private LocationManager locationManager;
89  
90      @Mock
91      private JavaModuleDescriptor descriptor;
92  
93      @Test
94      @SuppressWarnings( "checkstyle:linelength" )
95      public void shouldHaveStartupConfigForModularClasspath()
96              throws Exception
97      {
98          AbstractSurefireMojo mojo = spy( new Mojo() );
99          doReturn( locationManager )
100                 .when( mojo, "getLocationManager" );
101 
102         when( handler.isAddedToClasspath() ).thenReturn( true );
103 
104         VersionRange v1 = createFromVersion( "1" );
105         Artifact modular = new DefaultArtifact( "x", "modular", v1, "compile", "jar", "", handler );
106         modular.setFile( mockFile( "modular.jar" ) );
107 
108         VersionRange v2 = createFromVersion( "1" );
109         Artifact nonModular = new DefaultArtifact( "x", "non-modular", v2, "test", "jar", "", handler );
110         nonModular.setFile( mockFile( "non-modular.jar" ) );
111 
112         VersionRange v3 = createFromVersion( "4.12" );
113         Artifact junit = new DefaultArtifact( "junit", "junit", v3, "test", "jar", "", handler );
114         junit.setFile( mockFile( "junit.jar" ) );
115 
116         VersionRange v4 = createFromVersion( "1.3.0" );
117         Artifact hamcrest = new DefaultArtifact( "org.hamcrest", "hamcrest-core", v4, "test", "jar", "", handler );
118         hamcrest.setFile( mockFile( "hamcrest.jar" ) );
119 
120         File classesDir = mockFile( "classes" );
121         File testClassesDir = mockFile( "test-classes" );
122 
123         TestClassPath testClasspath =
124                 new TestClassPath( asList( modular, nonModular, junit, hamcrest ), classesDir, testClassesDir,
125                         null );
126 
127         doReturn( testClasspath ).when( mojo, "generateTestClasspath" );
128         doReturn( 1 ).when( mojo, "getEffectiveForkCount" );
129         doReturn( true ).when( mojo, "effectiveIsEnableAssertions" );
130         when( mojo.isChildDelegation() ).thenReturn( false );
131         when( mojo.getTestClassesDirectory() ).thenReturn( testClassesDir );
132 
133         DefaultScanResult scanResult = mock( DefaultScanResult.class );
134         when( scanResult.getClasses() ).thenReturn( asList( "org.apache.A", "org.apache.B" ) );
135 
136         ClassLoaderConfiguration classLoaderConfiguration = new ClassLoaderConfiguration( false, true );
137 
138         VersionRange v5 = createFromVersion( "1" );
139         Artifact providerArtifact = new DefaultArtifact( "org.apache.maven.surefire", "surefire-provider",
140             v5, "runtime", "jar", "", handler );
141         providerArtifact.setFile( mockFile( "surefire-provider.jar" ) );
142         Set<Artifact> providerClasspath = singleton( providerArtifact );
143 
144         ResolvePathResult moduleInfo = mock( ResolvePathResult.class );
145         when( moduleInfo.getModuleDescriptor() ).thenReturn( descriptor );
146 
147         @SuppressWarnings( "unchecked" )
148         ResolvePathsRequest<String> req = mock( ResolvePathsRequest.class );
149         mockStatic( ResolvePathsRequest.class );
150         when( ResolvePathsRequest.ofStrings( eq( testClasspath.toClasspath().getClassPath() ) ) ).thenReturn( req );
151         when( req.setJdkHome( anyString() ) ).thenReturn( req );
152         when( req.setModuleDescriptor( eq( descriptor ) ) ).thenReturn( req );
153 
154         when( descriptor.name() ).thenReturn( "abc" );
155 
156         @SuppressWarnings( "unchecked" )
157         ResolvePathsResult<String> res = mock( ResolvePathsResult.class );
158         when( res.getMainModuleDescriptor() ).thenReturn( descriptor );
159         when( res.getClasspathElements() ).thenReturn( asList( "non-modular.jar", "junit.jar", "hamcrest.jar" ) );
160         Map<String, ModuleNameSource> mod = new LinkedHashMap<>();
161         mod.put( "modular.jar", null );
162         mod.put( "classes", null );
163         when( res.getModulepathElements() ).thenReturn( mod );
164         when( res.getPathExceptions() ).thenReturn( singletonMap( "java 1.8", new Exception( "low version" ) ) );
165         when( locationManager.resolvePaths( eq( req ) ) ).thenReturn( res );
166 
167         Logger logger = mock( Logger.class );
168         when( logger.isDebugEnabled() ).thenReturn( true );
169         doNothing().when( logger ).debug( anyString() );
170         when( mojo.getConsoleLogger() ).thenReturn( new PluginConsoleLogger( logger ) );
171 
172         Artifact common = new DefaultArtifact( "org.apache.maven.surefire", "maven-surefire-common", v5, "runtime",
173                 "jar", "", handler );
174         common.setFile( mockFile( "maven-surefire-common.jar" ) );
175 
176         Artifact ext = new DefaultArtifact( "org.apache.maven.surefire", "surefire-extensions-api", v5, "runtime",
177                 "jar", "", handler );
178         ext.setFile( mockFile( "surefire-extensions-api.jar" ) );
179 
180         Artifact api = new DefaultArtifact( "org.apache.maven.surefire", "surefire-api", v5, "runtime",
181                 "jar", "", handler );
182         api.setFile( mockFile( "surefire-api.jar" ) );
183 
184         Artifact loggerApi = new DefaultArtifact( "org.apache.maven.surefire", "surefire-logger-api", v5, "runtime",
185                 "jar", "", handler );
186         loggerApi.setFile( mockFile( "surefire-logger-api.jar" ) );
187 
188         Artifact spi = new DefaultArtifact( "org.apache.maven.surefire", "surefire-extensions-spi",
189             createFromVersion( "1" ), "runtime", "jar", "", handler );
190         spi.setFile( mockFile( "surefire-extensions-spi.jar" ) );
191 
192         Artifact booter = new DefaultArtifact( "org.apache.maven.surefire", "surefire-booter",
193             createFromVersion( "1" ), "runtime", "jar", "", handler );
194         booter.setFile( mockFile( "surefire-booter.jar" ) );
195 
196         Artifact utils = new DefaultArtifact( "org.apache.maven.surefire", "surefire-shared-utils",
197             createFromVersion( "1" ), "runtime", "jar", "", handler );
198         utils.setFile( mockFile( "surefire-shared-utils.jar" ) );
199 
200         Map<String, Artifact> artifacts = new HashMap<>();
201         artifacts.put( "org.apache.maven.surefire:maven-surefire-common", common );
202         artifacts.put( "org.apache.maven.surefire:surefire-extensions-api", ext );
203         artifacts.put( "org.apache.maven.surefire:surefire-api", api );
204         artifacts.put( "org.apache.maven.surefire:surefire-logger-api", loggerApi );
205         artifacts.put( "org.apache.maven.surefire:surefire-extensions-spi", spi );
206         artifacts.put( "org.apache.maven.surefire:surefire-booter", booter );
207         artifacts.put( "org.apache.maven.surefire:surefire-shared-utils", utils );
208         when( mojo.getPluginArtifactMap() ).thenReturn( artifacts );
209 
210         ProviderInfo providerInfo = mock( ProviderInfo.class );
211         when( providerInfo.getProviderName() ).thenReturn( "org.asf.Provider" );
212         when( providerInfo.getProviderClasspath() ).thenReturn( providerClasspath );
213 
214         StartupConfiguration conf = invokeMethod( mojo, "newStartupConfigWithModularPath",
215             classLoaderConfiguration, providerInfo,
216             new ResolvePathResultWrapper( moduleInfo, true ), scanResult, "", testClasspath );
217 
218         verify( mojo, times( 1 ) ).effectiveIsEnableAssertions();
219         verify( mojo, times( 1 ) ).isChildDelegation();
220         verify( mojo, times( 1 ) ).getTestClassesDirectory();
221         verify( scanResult, times( 1 ) ).getClasses();
222         verifyStatic( ResolvePathsRequest.class, times( 1 ) );
223         ResolvePathsRequest.ofStrings( eq( testClasspath.toClasspath().getClassPath() ) );
224         verify( req, times( 1 ) ).setModuleDescriptor( eq( descriptor ) );
225         verify( res, times( 1 ) ).getClasspathElements();
226         verify( res, times( 1 ) ).getModulepathElements();
227         verify( locationManager, times( 1 ) ).resolvePaths( eq( req ) );
228         ArgumentCaptor<String> argument1 = ArgumentCaptor.forClass( String.class );
229         ArgumentCaptor<Exception> argument2 = ArgumentCaptor.forClass( Exception.class );
230         verify( logger, times( 1 ) ).warn( argument1.capture(), argument2.capture() );
231         assertThat( argument1.getValue() )
232                 .isEqualTo( "Exception for 'java 1.8'." );
233         assertThat( argument2.getValue().getMessage() )
234                 .isEqualTo( "low version" );
235         ArgumentCaptor<String> argument = ArgumentCaptor.forClass( String.class );
236         verify( logger, times( 9 ) ).debug( argument.capture() );
237         assertThat( argument.getAllValues() )
238                 .containsExactly( "main module descriptor name: abc",
239                         "test classpath:  non-modular.jar  junit.jar  hamcrest.jar",
240                         "test modulepath:  modular.jar  classes",
241                         "provider classpath:  surefire-provider.jar",
242                         "test(compact) classpath:  non-modular.jar  junit.jar  hamcrest.jar",
243                         "test(compact) modulepath:  modular.jar  classes",
244                         "provider(compact) classpath:  surefire-provider.jar",
245                         "in-process classpath:  surefire-provider.jar  maven-surefire-common.jar  surefire-booter.jar  surefire-extensions-api.jar  surefire-api.jar  surefire-extensions-spi.jar  surefire-logger-api.jar  surefire-shared-utils.jar",
246                         "in-process(compact) classpath:  surefire-provider.jar  maven-surefire-common.jar  surefire-booter.jar  surefire-extensions-api.jar  surefire-api.jar  surefire-extensions-spi.jar  surefire-logger-api.jar  surefire-shared-utils.jar"
247                 );
248 
249         assertThat( conf ).isNotNull();
250         assertThat( conf.isShadefire() ).isFalse();
251         assertThat( conf.isProviderMainClass() ).isFalse();
252         assertThat( conf.isManifestOnlyJarRequestedAndUsable() ).isFalse();
253         assertThat( conf.getClassLoaderConfiguration() ).isSameAs( classLoaderConfiguration );
254         assertThat( conf.getProviderClassName() ).isEqualTo( "org.asf.Provider" );
255         assertThat( conf.getActualClassName() ).isEqualTo( "org.asf.Provider" );
256         assertThat( conf.getClasspathConfiguration() ).isNotNull();
257         assertThat( ( Object ) conf.getClasspathConfiguration().getTestClasspath() )
258                 .isEqualTo( new Classpath( res.getClasspathElements() ) );
259         assertThat( ( Object ) conf.getClasspathConfiguration().getProviderClasspath() )
260                 .isEqualTo( new Classpath( singleton( "surefire-provider.jar" ) ) );
261         assertThat( conf.getClasspathConfiguration() ).isInstanceOf( ModularClasspathConfiguration.class );
262         ModularClasspathConfiguration mcc = ( ModularClasspathConfiguration ) conf.getClasspathConfiguration();
263         assertThat( mcc.getModularClasspath().getModuleNameFromDescriptor() ).isEqualTo( "abc" );
264         assertThat( mcc.getModularClasspath().getPackages() ).containsOnly( "org.apache" );
265         assertThat( mcc.getModularClasspath().getPatchFile().getAbsolutePath() )
266                 .isEqualTo( "test-classes" );
267         assertThat( mcc.getModularClasspath().getModulePath() )
268                 .containsExactly( "modular.jar", "classes" );
269     }
270 
271     @Test
272     @SuppressWarnings( "checkstyle:linelength" )
273     public void shouldHaveStartupConfigForModularClasspathAndTestDescriptor()
274         throws Exception
275     {
276         AbstractSurefireMojo mojo = spy( new Mojo() );
277         doReturn( locationManager )
278             .when( mojo, "getLocationManager" );
279 
280         when( handler.isAddedToClasspath() ).thenReturn( true );
281 
282         VersionRange v1 = createFromVersion( "1" );
283         Artifact modular = new DefaultArtifact( "x", "modular", v1, "compile", "jar", "", handler );
284         modular.setFile( mockFile( "modular.jar" ) );
285 
286         VersionRange v2 = createFromVersion( "1" );
287         Artifact nonModular = new DefaultArtifact( "x", "non-modular", v2, "test", "jar", "", handler );
288         nonModular.setFile( mockFile( "non-modular.jar" ) );
289 
290         VersionRange v3 = createFromVersion( "4.12" );
291         Artifact junit = new DefaultArtifact( "junit", "junit", v3, "test", "jar", "", handler );
292         junit.setFile( mockFile( "junit.jar" ) );
293 
294         VersionRange v4 = createFromVersion( "1.3.0" );
295         Artifact hamcrest = new DefaultArtifact( "org.hamcrest", "hamcrest-core", v4, "test", "jar", "", handler );
296         hamcrest.setFile( mockFile( "hamcrest.jar" ) );
297 
298         File classesDir = mockFile( "classes" );
299         File testClassesDir = mockFile( "test-classes" );
300 
301         TestClassPath testClasspath =
302             new TestClassPath( asList( modular, nonModular, junit, hamcrest ), classesDir, testClassesDir,
303                 null );
304 
305         doReturn( testClasspath ).when( mojo, "generateTestClasspath" );
306         doReturn( 1 ).when( mojo, "getEffectiveForkCount" );
307         doReturn( true ).when( mojo, "effectiveIsEnableAssertions" );
308         when( mojo.isChildDelegation() ).thenReturn( false );
309         when( mojo.getTestClassesDirectory() ).thenReturn( testClassesDir );
310 
311         DefaultScanResult scanResult = mock( DefaultScanResult.class );
312         when( scanResult.getClasses() ).thenReturn( asList( "org.apache.A", "org.apache.B" ) );
313 
314         ClassLoaderConfiguration classLoaderConfiguration = new ClassLoaderConfiguration( false, true );
315 
316         VersionRange v5 = createFromVersion( "1" );
317         Artifact providerArtifact = new DefaultArtifact( "org.apache.maven.surefire", "surefire-provider",
318             v5, "runtime", "jar", "", handler );
319         providerArtifact.setFile( mockFile( "surefire-provider.jar" ) );
320         Set<Artifact> providerClasspath = singleton( providerArtifact );
321 
322         ResolvePathResult moduleInfo = mock( ResolvePathResult.class );
323         when( moduleInfo.getModuleDescriptor() ).thenReturn( descriptor );
324 
325         when( descriptor.name() ).thenReturn( "abc" );
326 
327         Logger logger = mock( Logger.class );
328         when( logger.isDebugEnabled() ).thenReturn( true );
329         doNothing().when( logger ).debug( anyString() );
330         when( mojo.getConsoleLogger() ).thenReturn( new PluginConsoleLogger( logger ) );
331 
332         Artifact common = new DefaultArtifact( "org.apache.maven.surefire", "maven-surefire-common", v5, "runtime",
333             "jar", "", handler );
334         common.setFile( mockFile( "maven-surefire-common.jar" ) );
335 
336         Artifact ext = new DefaultArtifact( "org.apache.maven.surefire", "surefire-extensions-api", v5, "runtime",
337             "jar", "", handler );
338         ext.setFile( mockFile( "surefire-extensions-api.jar" ) );
339 
340         Artifact api = new DefaultArtifact( "org.apache.maven.surefire", "surefire-api", v5, "runtime",
341             "jar", "", handler );
342         api.setFile( mockFile( "surefire-api.jar" ) );
343 
344         Artifact loggerApi = new DefaultArtifact( "org.apache.maven.surefire", "surefire-logger-api", v5, "runtime",
345             "jar", "", handler );
346         loggerApi.setFile( mockFile( "surefire-logger-api.jar" ) );
347 
348         Artifact spi = new DefaultArtifact( "org.apache.maven.surefire", "surefire-extensions-spi",
349             createFromVersion( "1" ), "runtime", "jar", "", handler );
350         spi.setFile( mockFile( "surefire-extensions-spi.jar" ) );
351 
352         Artifact booter = new DefaultArtifact( "org.apache.maven.surefire", "surefire-booter",
353             createFromVersion( "1" ), "runtime", "jar", "", handler );
354         booter.setFile( mockFile( "surefire-booter.jar" ) );
355 
356         Artifact utils = new DefaultArtifact( "org.apache.maven.surefire", "surefire-shared-utils",
357             createFromVersion( "1" ), "runtime", "jar", "", handler );
358         utils.setFile( mockFile( "surefire-shared-utils.jar" ) );
359 
360         Map<String, Artifact> artifacts = new HashMap<>();
361         artifacts.put( "org.apache.maven.surefire:maven-surefire-common", common );
362         artifacts.put( "org.apache.maven.surefire:surefire-extensions-api", ext );
363         artifacts.put( "org.apache.maven.surefire:surefire-api", api );
364         artifacts.put( "org.apache.maven.surefire:surefire-logger-api", loggerApi );
365         artifacts.put( "org.apache.maven.surefire:surefire-extensions-spi", spi );
366         artifacts.put( "org.apache.maven.surefire:surefire-booter", booter );
367         artifacts.put( "org.apache.maven.surefire:surefire-shared-utils", utils );
368         when( mojo.getPluginArtifactMap() ).thenReturn( artifacts );
369 
370         ProviderInfo providerInfo = mock( ProviderInfo.class );
371         when( providerInfo.getProviderName() ).thenReturn( "org.asf.Provider" );
372         when( providerInfo.getProviderClasspath() ).thenReturn( providerClasspath );
373 
374         StartupConfiguration conf = invokeMethod( mojo, "newStartupConfigWithModularPath",
375             classLoaderConfiguration, providerInfo,
376             new ResolvePathResultWrapper( moduleInfo, false ), scanResult, "", testClasspath );
377 
378         verify( mojo, times( 1 ) ).effectiveIsEnableAssertions();
379         verify( mojo, times( 1 ) ).isChildDelegation();
380         verify( mojo, never() ).getTestClassesDirectory();
381         ArgumentCaptor<String> argument = ArgumentCaptor.forClass( String.class );
382         verify( logger, times( 9 ) ).debug( argument.capture() );
383         assertThat( argument.getAllValues() )
384             .containsExactly( "main module descriptor name: abc",
385                 "test classpath:",
386                 "test modulepath:  test-classes  classes  modular.jar  non-modular.jar  junit.jar  hamcrest.jar",
387                 "provider classpath:  surefire-provider.jar",
388                 "test(compact) classpath:",
389                 "test(compact) modulepath:  test-classes  classes  modular.jar  non-modular.jar  junit.jar  hamcrest.jar",
390                 "provider(compact) classpath:  surefire-provider.jar",
391                 "in-process classpath:  surefire-provider.jar  maven-surefire-common.jar  surefire-booter.jar  surefire-extensions-api.jar  surefire-api.jar  surefire-extensions-spi.jar  surefire-logger-api.jar  surefire-shared-utils.jar",
392                 "in-process(compact) classpath:  surefire-provider.jar  maven-surefire-common.jar  surefire-booter.jar  surefire-extensions-api.jar  surefire-api.jar  surefire-extensions-spi.jar  surefire-logger-api.jar  surefire-shared-utils.jar"
393             );
394 
395         assertThat( conf ).isNotNull();
396         assertThat( conf.isShadefire() ).isFalse();
397         assertThat( conf.isProviderMainClass() ).isFalse();
398         assertThat( conf.isManifestOnlyJarRequestedAndUsable() ).isFalse();
399         assertThat( conf.getClassLoaderConfiguration() ).isSameAs( classLoaderConfiguration );
400         assertThat( conf.getProviderClassName() ).isEqualTo( "org.asf.Provider" );
401         assertThat( conf.getActualClassName() ).isEqualTo( "org.asf.Provider" );
402         assertThat( conf.getClasspathConfiguration() ).isNotNull();
403         assertThat( ( Object ) conf.getClasspathConfiguration().getTestClasspath() )
404             .isEqualTo( Classpath.emptyClasspath() );
405         assertThat( ( Object ) conf.getClasspathConfiguration().getProviderClasspath() )
406             .isEqualTo( new Classpath( singleton( "surefire-provider.jar" ) ) );
407         assertThat( conf.getClasspathConfiguration() ).isInstanceOf( ModularClasspathConfiguration.class );
408         ModularClasspathConfiguration mcc = ( ModularClasspathConfiguration ) conf.getClasspathConfiguration();
409         assertThat( mcc.getModularClasspath().getModuleNameFromDescriptor() ).isEqualTo( "abc" );
410         assertThat( mcc.getModularClasspath().getPackages() ).isEmpty();
411         assertThat( mcc.getModularClasspath().getPatchFile() )
412             .isNull();
413         assertThat( mcc.getModularClasspath().getModulePath() )
414             .hasSize( 6 )
415             .containsSequence( "test-classes", "classes", "modular.jar", "non-modular.jar",
416                 "junit.jar", "hamcrest.jar" );
417     }
418 
419     @Test
420     public void testAllProviderInfo()
421     {
422         Mojo mojo = new Mojo();
423 
424         ProviderRequirements providerRequirements = new ProviderRequirements( true, false, true );
425 
426         ProviderInfo providerInfo = mojo.newDynamicProviderInfo();
427         assertThat( providerInfo.getProviderName() )
428             .isEqualTo( "custom.Provider" );
429         assertThat( providerInfo.getJpmsArguments( providerRequirements ) )
430             .isEmpty();
431 
432         providerInfo = mojo.newJUnit3ProviderInfo();
433         assertThat( providerInfo.getProviderName() )
434             .isEqualTo( "org.apache.maven.surefire.junit.JUnit3Provider" );
435         assertThat( providerInfo.getJpmsArguments( providerRequirements ) )
436             .isEmpty();
437 
438         providerInfo = mojo.newJUnit4ProviderInfo();
439         assertThat( providerInfo.getProviderName() )
440             .isEqualTo( "org.apache.maven.surefire.junit4.JUnit4Provider" );
441         assertThat( providerInfo.getJpmsArguments( providerRequirements ) )
442             .isEmpty();
443 
444         providerInfo = mojo.newJUnit47ProviderInfo();
445         assertThat( providerInfo.getProviderName() )
446             .isEqualTo( "org.apache.maven.surefire.junitcore.JUnitCoreProvider" );
447         assertThat( providerInfo.getJpmsArguments( providerRequirements ) )
448             .isEmpty();
449 
450         providerInfo = mojo.newTestNgProviderInfo();
451         assertThat( providerInfo.getProviderName() )
452             .isEqualTo( "org.apache.maven.surefire.testng.TestNGProvider" );
453         assertThat( providerInfo.getJpmsArguments( providerRequirements ) )
454             .isEmpty();
455 
456         providerInfo = mojo.newJUnitPlatformProviderInfo();
457         assertThat( providerInfo.getProviderName() )
458             .isEqualTo( "org.apache.maven.surefire.junitplatform.JUnitPlatformProvider" );
459         List<String[]> args = providerInfo.getJpmsArguments( providerRequirements );
460         assertThat( args )
461             .isNotEmpty()
462             .hasSize( 2 )
463             .contains( new String[] {
464             "--add-opens", "org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED"}, atIndex( 0 ) )
465             .contains( new String[] {
466             "--add-opens", "org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED"}, atIndex( 1 ) );
467     }
468 
469     private static File mockFile( String absolutePath )
470     {
471         File f = mock( File.class );
472         when( f.getAbsolutePath() ).thenReturn( absolutePath );
473         return f;
474     }
475 
476     /**
477      *
478      */
479     public static class Mojo
480             extends AbstractSurefireMojo
481     {
482         ProviderInfo newDynamicProviderInfo()
483         {
484             return new DynamicProviderInfo( "custom.Provider" );
485         }
486 
487         ProviderInfo newJUnit3ProviderInfo()
488         {
489             return new JUnit3ProviderInfo();
490         }
491 
492         ProviderInfo newJUnit4ProviderInfo()
493         {
494             return new JUnit4ProviderInfo( null, null );
495         }
496 
497         ProviderInfo newJUnit47ProviderInfo()
498         {
499             return new JUnitCoreProviderInfo( null, null );
500         }
501 
502         ProviderInfo newTestNgProviderInfo()
503         {
504             return new TestNgProviderInfo( null );
505         }
506 
507         ProviderInfo newJUnitPlatformProviderInfo()
508         {
509             return new JUnitPlatformProviderInfo( null, null );
510         }
511 
512         @Override
513         protected String getPluginName()
514         {
515             return null;
516         }
517 
518         @Override
519         protected int getRerunFailingTestsCount()
520         {
521             return 0;
522         }
523 
524         @Override
525         public boolean isSkipTests()
526         {
527             return false;
528         }
529 
530         @Override
531         public void setSkipTests( boolean skipTests )
532         {
533 
534         }
535 
536         @Override
537         public boolean isSkipExec()
538         {
539             return false;
540         }
541 
542         @Override
543         public void setSkipExec( boolean skipExec )
544         {
545 
546         }
547 
548         @Override
549         public boolean isSkip()
550         {
551             return false;
552         }
553 
554         @Override
555         public void setSkip( boolean skip )
556         {
557 
558         }
559 
560         @Override
561         public File getBasedir()
562         {
563             return null;
564         }
565 
566         @Override
567         public void setBasedir( File basedir )
568         {
569 
570         }
571 
572         @Override
573         public File getTestClassesDirectory()
574         {
575             return null;
576         }
577 
578         @Override
579         public void setTestClassesDirectory( File testClassesDirectory )
580         {
581 
582         }
583 
584         @Override
585         public File getMainBuildPath()
586         {
587             return null;
588         }
589 
590         @Override
591         public void setMainBuildPath( File mainBuildPath )
592         {
593 
594         }
595 
596         @Override
597         public File getReportsDirectory()
598         {
599             return null;
600         }
601 
602         @Override
603         public void setReportsDirectory( File reportsDirectory )
604         {
605 
606         }
607 
608         @Override
609         public String getTest()
610         {
611             return null;
612         }
613 
614         @Override
615         public void setTest( String test )
616         {
617 
618         }
619 
620         @Override
621         public List<String> getIncludes()
622         {
623             return null;
624         }
625 
626         @Override
627         public File getIncludesFile()
628         {
629             return null;
630         }
631 
632         @Override
633         public void setIncludes( List<String> includes )
634         {
635 
636         }
637 
638         @Override
639         public boolean isPrintSummary()
640         {
641             return false;
642         }
643 
644         @Override
645         public void setPrintSummary( boolean printSummary )
646         {
647 
648         }
649 
650         @Override
651         public String getReportFormat()
652         {
653             return null;
654         }
655 
656         @Override
657         public void setReportFormat( String reportFormat )
658         {
659 
660         }
661 
662         @Override
663         public boolean isUseFile()
664         {
665             return false;
666         }
667 
668         @Override
669         public void setUseFile( boolean useFile )
670         {
671 
672         }
673 
674         @Override
675         public String getDebugForkedProcess()
676         {
677             return null;
678         }
679 
680         @Override
681         public void setDebugForkedProcess( String debugForkedProcess )
682         {
683 
684         }
685 
686         @Override
687         public int getForkedProcessTimeoutInSeconds()
688         {
689             return 0;
690         }
691 
692         @Override
693         public void setForkedProcessTimeoutInSeconds( int forkedProcessTimeoutInSeconds )
694         {
695 
696         }
697 
698         @Override
699         public int getForkedProcessExitTimeoutInSeconds()
700         {
701             return 0;
702         }
703 
704         @Override
705         public void setForkedProcessExitTimeoutInSeconds( int forkedProcessTerminationTimeoutInSeconds )
706         {
707 
708         }
709 
710         @Override
711         public double getParallelTestsTimeoutInSeconds()
712         {
713             return 0;
714         }
715 
716         @Override
717         public void setParallelTestsTimeoutInSeconds( double parallelTestsTimeoutInSeconds )
718         {
719 
720         }
721 
722         @Override
723         public double getParallelTestsTimeoutForcedInSeconds()
724         {
725             return 0;
726         }
727 
728         @Override
729         public void setParallelTestsTimeoutForcedInSeconds( double parallelTestsTimeoutForcedInSeconds )
730         {
731 
732         }
733 
734         @Override
735         public boolean isUseSystemClassLoader()
736         {
737             return false;
738         }
739 
740         @Override
741         public void setUseSystemClassLoader( boolean useSystemClassLoader )
742         {
743 
744         }
745 
746         @Override
747         public boolean isUseManifestOnlyJar()
748         {
749             return false;
750         }
751 
752         @Override
753         public void setUseManifestOnlyJar( boolean useManifestOnlyJar )
754         {
755 
756         }
757 
758         @Override
759         public String getEncoding()
760         {
761             return null;
762         }
763 
764         @Override
765         public void setEncoding( String encoding )
766         {
767 
768         }
769 
770         @Override
771         public Boolean getFailIfNoSpecifiedTests()
772         {
773             return null;
774         }
775 
776         @Override
777         public void setFailIfNoSpecifiedTests( boolean failIfNoSpecifiedTests )
778         {
779 
780         }
781 
782         @Override
783         public int getSkipAfterFailureCount()
784         {
785             return 0;
786         }
787 
788         @Override
789         public String getShutdown()
790         {
791             return null;
792         }
793 
794         @Override
795         public File getExcludesFile()
796         {
797             return null;
798         }
799 
800         @Override
801         protected List<File> suiteXmlFiles()
802         {
803             return null;
804         }
805 
806         @Override
807         protected boolean hasSuiteXmlFiles()
808         {
809             return false;
810         }
811 
812         @Override
813         protected String[] getExcludedEnvironmentVariables()
814         {
815             return new String[0];
816         }
817 
818         @Override
819         public File[] getSuiteXmlFiles()
820         {
821             return new File[0];
822         }
823 
824         @Override
825         public void setSuiteXmlFiles( File[] suiteXmlFiles )
826         {
827 
828         }
829 
830         @Override
831         public String getRunOrder()
832         {
833             return null;
834         }
835 
836         @Override
837         public void setRunOrder( String runOrder )
838         {
839 
840         }
841 
842         @Override
843         protected void handleSummary( RunResult summary, Exception firstForkException )
844         {
845 
846         }
847 
848         @Override
849         protected boolean isSkipExecution()
850         {
851             return false;
852         }
853 
854         @Override
855         protected String[] getDefaultIncludes()
856         {
857             return new String[0];
858         }
859 
860         @Override
861         protected String getReportSchemaLocation()
862         {
863             return null;
864         }
865 
866         @Override
867         protected boolean useModulePath()
868         {
869             return false;
870         }
871 
872         @Override
873         protected void setUseModulePath( boolean useModulePath )
874         {
875 
876         }
877 
878         @Override
879         protected String getEnableProcessChecker()
880         {
881             return null;
882         }
883 
884         @Override
885         protected ForkNodeFactory getForkNode()
886         {
887             return null;
888         }
889 
890         @Override
891         protected Artifact getMojoArtifact()
892         {
893             return null;
894         }
895 
896         @Override
897         public File getSystemPropertiesFile()
898         {
899             return null;
900         }
901 
902         @Override
903         public void setSystemPropertiesFile( File systemPropertiesFile )
904         {
905 
906         }
907     }
908 }