You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/06/13 15:11:11 UTC
[maven-surefire] branch deps updated: replace PowerMock
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch deps
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/deps by this push:
new 22b2880 replace PowerMock
22b2880 is described below
commit 22b2880dc94ec43c990d4d1dd1e2e40d9c79e979
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Sat Jun 13 11:09:03 2020 -0400
replace PowerMock
---
pom.xml | 2 +-
.../maven/surefire/booter/SystemUtilsTest.java | 465 +++++++++------------
2 files changed, 200 insertions(+), 267 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3e89042..b25f80c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -97,7 +97,7 @@
<doxiaSitetoolsVersion>1.9.2</doxiaSitetoolsVersion>
<plexus-java-version>1.0.5</plexus-java-version>
<!-- maven-shared-utils:3.2.0+ another behavior - broke Surefire performance - end of subprocess notification not arrived in ForkStarter -->
- <mavenSharedUtilsVersion>3.2.1</mavenSharedUtilsVersion>
+ <mavenSharedUtilsVersion>3.1.0</mavenSharedUtilsVersion>
<powermockVersion>2.0.5</powermockVersion>
<jacocoVersion>0.8.5</jacocoVersion>
<maven.surefire.scm.devConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-surefire.git</maven.surefire.scm.devConnection>
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java
index c504e04..63e4de9 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java
@@ -20,11 +20,6 @@ package org.apache.maven.surefire.booter;
*/
import org.junit.Test;
-import org.junit.experimental.runners.Enclosed;
-import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import java.io.File;
import java.io.IOException;
@@ -40,13 +35,6 @@ import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_NET_BSD;
import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_OPEN_BSD;
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-import static org.powermock.api.mockito.PowerMockito.mockStatic;
-import static org.powermock.api.mockito.PowerMockito.verifyStatic;
-import static org.powermock.reflect.Whitebox.invokeMethod;
/**
* Test of {@link SystemUtils}.
@@ -55,316 +43,261 @@ import static org.powermock.reflect.Whitebox.invokeMethod;
* @since 2.20.1
*/
@SuppressWarnings( "checkstyle:magicnumber" )
-@RunWith( Enclosed.class )
public class SystemUtilsTest
{
- /**
- *
- */
- public static class PlainUnitTests
+
+ @Test
+ public void shouldParseProprietaryReleaseFile() throws IOException
{
+ String classes = new File( "." ).getCanonicalPath() + separator + "target" + separator + "test-classes";
- @Test
- public void shouldMatchJavaSpecVersion() throws Exception
- {
- BigDecimal actual = invokeMethod( SystemUtils.class, "getJavaSpecificationVersion" );
- BigDecimal expected =
- new BigDecimal( System.getProperty( "java.specification.version" ) ).stripTrailingZeros();
- assertThat( actual ).isEqualTo( expected );
- assertThat( SystemUtils.JAVA_SPECIFICATION_VERSION ).isEqualTo( expected );
- }
+ File path = new File( classes, "jdk8-IBM" + separator + "bin" + separator + "java" );
+ assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isFalse();
- @Test
- public void shouldParseProprietaryReleaseFile() throws IOException
- {
- String classes = new File( "." ).getCanonicalPath() + separator + "target" + separator + "test-classes";
+ path = new File( classes, "jdk8-oracle" + separator + "bin" + separator + "java" );
+ assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isFalse();
- File path = new File( classes, "jdk8-IBM" + separator + "bin" + separator + "java" );
- assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isFalse();
+ path = new File( classes, "jdk9-oracle" + separator + "bin" + separator + "java" );
+ assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isTrue();
+ }
- path = new File( classes, "jdk8-oracle" + separator + "bin" + separator + "java" );
- assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isFalse();
+ @Test
+ public void incorrectJdkPath()
+ {
+ File jre = new File( System.getProperty( "java.home" ) );
+ File jdk = jre.getParentFile();
+ File incorrect = jdk.getParentFile();
+ assertThat( SystemUtils.isJava9AtLeast( incorrect.getAbsolutePath() ) ).isFalse();
+ }
- path = new File( classes, "jdk9-oracle" + separator + "bin" + separator + "java" );
- assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isTrue();
- }
+ @Test
+ public void shouldHaveJavaPath()
+ {
+ String javaPath = System.getProperty( "java.home" ) + separator + "bin" + separator + "java";
+ assertThat( SystemUtils.endsWithJavaPath( javaPath ) ).isTrue();
+ }
- @Test
- public void incorrectJdkPath()
- {
- File jre = new File( System.getProperty( "java.home" ) );
- File jdk = jre.getParentFile();
- File incorrect = jdk.getParentFile();
- assertThat( SystemUtils.isJava9AtLeast( incorrect.getAbsolutePath() ) ).isFalse();
- }
+ @Test
+ public void shouldNotHaveJavaPath()
+ {
+ assertThat( SystemUtils.endsWithJavaPath( "/jdk" ) ).isFalse();
+ }
- @Test
- public void shouldHaveJavaPath()
- {
- String javaPath = System.getProperty( "java.home" ) + separator + "bin" + separator + "java";
- assertThat( SystemUtils.endsWithJavaPath( javaPath ) ).isTrue();
- }
+ @Test
+ public void shouldNotExtractJdkHomeFromJavaExec()
+ {
+ File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( "/jdk/binx/java" );
+ assertThat( pathToJdk ).isNull();
+ }
- @Test
- public void shouldNotHaveJavaPath()
- {
- assertThat( SystemUtils.endsWithJavaPath( "/jdk" ) ).isFalse();
- }
+ @Test
+ public void shouldExtractJdkHomeFromJavaExec()
+ {
+ File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( "/jdk/bin/java" );
+ assertThat( pathToJdk ).isEqualTo( new File( "/jdk" ).getAbsoluteFile() );
+ }
- @Test
- public void shouldNotExtractJdkHomeFromJavaExec()
- {
- File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( "/jdk/binx/java" );
- assertThat( pathToJdk ).isNull();
- }
+ @Test
+ public void shouldNotExtractJdkHomeFromJreExec() throws IOException
+ {
+ String classes = new File( "." ).getCanonicalPath() + separator + "target" + separator + "test-classes";
+ File jdk = new File( classes, "jdk" );
+ String pathToJreExec = jdk.getAbsolutePath() + separator + "jre" + separator + "binx" + separator + "java";
+ File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( pathToJreExec );
+ assertThat( pathToJdk ).isNull();
+ }
- @Test
- public void shouldExtractJdkHomeFromJavaExec()
- {
- File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( "/jdk/bin/java" );
- assertThat( pathToJdk ).isEqualTo( new File( "/jdk" ).getAbsoluteFile() );
- }
+ @Test
+ public void shouldExtractJdkHomeFromJreExec() throws IOException
+ {
+ String classes = new File( "." ).getCanonicalPath() + separator + "target" + separator + "test-classes";
+ File jdk = new File( classes, "jdk" );
+ String pathToJreExec = jdk.getAbsolutePath() + separator + "jre" + separator + "bin" + separator + "java";
+ File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( pathToJreExec );
+ assertThat( pathToJdk ).isEqualTo( jdk );
+ }
- @Test
- public void shouldNotExtractJdkHomeFromJreExec() throws IOException
- {
- String classes = new File( "." ).getCanonicalPath() + separator + "target" + separator + "test-classes";
- File jdk = new File( classes, "jdk" );
- String pathToJreExec = jdk.getAbsolutePath() + separator + "jre" + separator + "binx" + separator + "java";
- File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( pathToJreExec );
- assertThat( pathToJdk ).isNull();
- }
+ @Test
+ public void shouldExtractJdkHomeFromJre()
+ {
+ File pathToJdk = SystemUtils.toJdkHomeFromJre( "/jdk/jre" );
+ assertThat( pathToJdk ).isEqualTo( new File( "/jdk" ).getAbsoluteFile() );
+ }
- @Test
- public void shouldExtractJdkHomeFromJreExec() throws IOException
- {
- String classes = new File( "." ).getCanonicalPath() + separator + "target" + separator + "test-classes";
- File jdk = new File( classes, "jdk" );
- String pathToJreExec = jdk.getAbsolutePath() + separator + "jre" + separator + "bin" + separator + "java";
- File pathToJdk = SystemUtils.toJdkHomeFromJvmExec( pathToJreExec );
- assertThat( pathToJdk ).isEqualTo( jdk );
- }
+ @Test
+ public void shouldExtractJdkHomeFromJdk()
+ {
+ File pathToJdk = SystemUtils.toJdkHomeFromJre( "/jdk/" );
+ assertThat( pathToJdk ).isEqualTo( new File( "/jdk" ).getAbsoluteFile() );
+ }
- @Test
- public void shouldExtractJdkHomeFromJre()
- {
- File pathToJdk = SystemUtils.toJdkHomeFromJre( "/jdk/jre" );
- assertThat( pathToJdk ).isEqualTo( new File( "/jdk" ).getAbsoluteFile() );
- }
+ @Test
+ public void shouldExtractJdkHomeFromRealPath()
+ {
+ File pathToJdk = SystemUtils.toJdkHomeFromJre();
- @Test
- public void shouldExtractJdkHomeFromJdk()
+ if ( JAVA_RECENT.atLeast( JAVA_9 ) )
{
- File pathToJdk = SystemUtils.toJdkHomeFromJre( "/jdk/" );
- assertThat( pathToJdk ).isEqualTo( new File( "/jdk" ).getAbsoluteFile() );
+ File realJdkHome = new File( System.getProperty( "java.home" ) ).getAbsoluteFile();
+ assertThat( realJdkHome ).isDirectory();
+ assertThat( realJdkHome.getName() ).isNotEqualTo( "jre" );
+ assertThat( pathToJdk ).isEqualTo( realJdkHome );
}
-
- @Test
- public void shouldExtractJdkHomeFromRealPath()
+ else
{
- File pathToJdk = SystemUtils.toJdkHomeFromJre();
-
- if ( JAVA_RECENT.atLeast( JAVA_9 ) )
- {
- File realJdkHome = new File( System.getProperty( "java.home" ) ).getAbsoluteFile();
- assertThat( realJdkHome ).isDirectory();
- assertThat( realJdkHome.getName() ).isNotEqualTo( "jre" );
- assertThat( pathToJdk ).isEqualTo( realJdkHome );
- }
- else
- {
- File realJreHome = new File( System.getProperty( "java.home" ) ).getAbsoluteFile();
- assertThat( realJreHome ).isDirectory();
- assertThat( realJreHome.getName() ).isEqualTo( "jre" );
- File realJdkHome = realJreHome.getParentFile();
- assertThat( pathToJdk ).isEqualTo( realJdkHome );
- }
+ File realJreHome = new File( System.getProperty( "java.home" ) ).getAbsoluteFile();
+ assertThat( realJreHome ).isDirectory();
+ assertThat( realJreHome.getName() ).isEqualTo( "jre" );
+ File realJdkHome = realJreHome.getParentFile();
+ assertThat( pathToJdk ).isEqualTo( realJdkHome );
}
+ }
- @Test
- public void shouldBeJavaVersion()
- {
- assertThat( SystemUtils.isJava9AtLeast( (BigDecimal ) null ) ).isFalse();
- assertThat( SystemUtils.isJava9AtLeast( new BigDecimal( "1.8" ) ) ).isFalse();
- assertThat( SystemUtils.isJava9AtLeast( new BigDecimal( 9 ) ) ).isTrue();
- }
+ @Test
+ public void shouldBeJavaVersion()
+ {
+ assertThat( SystemUtils.isJava9AtLeast( (BigDecimal ) null ) ).isFalse();
+ assertThat( SystemUtils.isJava9AtLeast( new BigDecimal( "1.8" ) ) ).isFalse();
+ assertThat( SystemUtils.isJava9AtLeast( new BigDecimal( 9 ) ) ).isTrue();
+ }
- @Test
- public void shouldBePlatformClassLoader()
+ @Test
+ public void shouldBePlatformClassLoader()
+ {
+ ClassLoader cl = SystemUtils.platformClassLoader();
+ if ( JAVA_RECENT.atLeast( JAVA_9 ) )
{
- ClassLoader cl = SystemUtils.platformClassLoader();
- if ( JAVA_RECENT.atLeast( JAVA_9 ) )
- {
- assertThat( cl ).isNotNull();
- }
- else
- {
- assertThat( cl ).isNull();
- }
+ assertThat( cl ).isNotNull();
}
-
- @Test
- public void shouldNotFindClassLoader()
+ else
{
- ClassLoader cl = SystemUtils.reflectClassLoader( getClass(), "_getPlatformClassLoader_" );
assertThat( cl ).isNull();
}
+ }
- @Test
- public void shouldFindClassLoader()
- {
- ClassLoader cl = SystemUtils.reflectClassLoader( getClass(), "getPlatformClassLoader" );
- assertThat( cl ).isSameAs( ClassLoader.getSystemClassLoader() );
- }
+ @Test
+ public void shouldNotFindClassLoader()
+ {
+ ClassLoader cl = SystemUtils.reflectClassLoader( getClass(), "_getPlatformClassLoader_" );
+ assertThat( cl ).isNull();
+ }
- @Test
- public void shouldBePidOnJigsaw()
- {
- assumeTrue( JAVA_RECENT.atLeast( JAVA_9 ) );
+ @Test
+ public void shouldFindClassLoader()
+ {
+ ClassLoader cl = SystemUtils.reflectClassLoader( getClass(), "getPlatformClassLoader" );
+ assertThat( cl ).isSameAs( ClassLoader.getSystemClassLoader() );
+ }
- Long actualPid = SystemUtils.pidOnJava9();
- String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
+ @Test
+ public void shouldBePidOnJigsaw()
+ {
+ assumeTrue( JAVA_RECENT.atLeast( JAVA_9 ) );
- assertThat( actualPid + "" )
- .isEqualTo( expectedPid );
- }
+ Long actualPid = SystemUtils.pidOnJava9();
+ String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
- @Test
- public void shouldBePidStatusOnLinux() throws Exception
- {
- assumeTrue( IS_OS_LINUX );
+ assertThat( actualPid + "" )
+ .isEqualTo( expectedPid );
+ }
- Long actualPid = SystemUtils.pidStatusOnLinux();
- String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
+ @Test
+ public void shouldBePidStatusOnLinux() throws Exception
+ {
+ assumeTrue( IS_OS_LINUX );
- assertThat( actualPid + "" )
- .isEqualTo( expectedPid );
- }
+ Long actualPid = SystemUtils.pidStatusOnLinux();
+ String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
- @Test
- public void shouldBeMockPidStatusOnLinux() throws Exception
- {
- String root = new File( System.getProperty( "user.dir" ), "target/test-classes" ).getAbsolutePath();
- Long actualPid = SystemUtils.pidStatusOnLinux( root );
- assertThat( actualPid )
- .isEqualTo( 48982L );
- }
+ assertThat( actualPid + "" )
+ .isEqualTo( expectedPid );
+ }
- @Test
- public void shouldBePidStatusOnBSD() throws Exception
- {
- assumeTrue( IS_OS_FREE_BSD || IS_OS_NET_BSD || IS_OS_OPEN_BSD );
+ @Test
+ public void shouldBeMockPidStatusOnLinux() throws Exception
+ {
+ String root = new File( System.getProperty( "user.dir" ), "target/test-classes" ).getAbsolutePath();
+ Long actualPid = SystemUtils.pidStatusOnLinux( root );
+ assertThat( actualPid )
+ .isEqualTo( 48982L );
+ }
- Long actualPid = SystemUtils.pidStatusOnBSD();
- String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
+ @Test
+ public void shouldBePidStatusOnBSD() throws Exception
+ {
+ assumeTrue( IS_OS_FREE_BSD || IS_OS_NET_BSD || IS_OS_OPEN_BSD );
- assertThat( actualPid + "" )
- .isEqualTo( expectedPid );
- }
+ Long actualPid = SystemUtils.pidStatusOnBSD();
+ String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
- @Test
- public void shouldBeMockPidStatusOnBSD() throws Exception
- {
- String root = new File( System.getProperty( "user.dir" ), "target/test-classes" ).getAbsolutePath();
- Long actualPid = SystemUtils.pidStatusOnBSD( root );
- assertThat( actualPid )
- .isEqualTo( 60424L );
- }
+ assertThat( actualPid + "" )
+ .isEqualTo( expectedPid );
+ }
- @Test
- public void shouldBePidOnJMX()
- {
- Long actualPid = SystemUtils.pidOnJMX();
- String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
+ @Test
+ public void shouldBeMockPidStatusOnBSD() throws Exception
+ {
+ String root = new File( System.getProperty( "user.dir" ), "target/test-classes" ).getAbsolutePath();
+ Long actualPid = SystemUtils.pidStatusOnBSD( root );
+ assertThat( actualPid )
+ .isEqualTo( 60424L );
+ }
- assertThat( actualPid + "" )
- .isEqualTo( expectedPid );
- }
+ @Test
+ public void shouldBePidOnJMX()
+ {
+ Long actualPid = SystemUtils.pidOnJMX();
+ String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
- @Test
- public void shouldBePid()
- {
- Long actualPid = SystemUtils.pid();
- String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
+ assertThat( actualPid + "" )
+ .isEqualTo( expectedPid );
+ }
- assertThat( actualPid + "" )
- .isEqualTo( expectedPid );
- }
+ @Test
+ public void shouldBePid()
+ {
+ Long actualPid = SystemUtils.pid();
+ String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
- @SuppressWarnings( "unused" )
- public static ClassLoader getPlatformClassLoader()
- {
- return ClassLoader.getSystemClassLoader();
- }
+ assertThat( actualPid + "" )
+ .isEqualTo( expectedPid );
+ }
+ @SuppressWarnings( "unused" )
+ public static ClassLoader getPlatformClassLoader()
+ {
+ return ClassLoader.getSystemClassLoader();
}
- /**
- *
- */
- @RunWith( PowerMockRunner.class )
- @PrepareForTest( SystemUtils.class )
- @PowerMockIgnore( { "org.jacoco.agent.rt.*", "com.vladium.emma.rt.*" } )
- public static class MockTest
+ @Test
+ public void shouldBeDifferentJdk9()
{
+ testIsJava9AtLeast( new File( System.getProperty( "java.home" ) ) );
+ }
- @Test
- public void shouldBeDifferentJdk9()
+ @Test
+ public void shouldBeSameJdk9()
+ {
+ if ( !JAVA_RECENT.atLeast( JAVA_9 ) )
{
- testIsJava9AtLeast( new File( System.getProperty( "java.home" ) ) );
+ testIsJava9AtLeast( new File( System.getProperty( "java.home" ) ).getParentFile() );
}
+ }
+
+ private static void testIsJava9AtLeast( File pathInJdk )
+ {
+ File path = new File( pathInJdk, "bin" + separator + "java" );
- @Test
- public void shouldBeSameJdk9()
+
+ if ( JAVA_RECENT.atLeast( JAVA_9 ) )
{
- // PowerMockJUnit44RunnerDelegateImpl does not work with Assumptions: assumeFalse
- if ( !JAVA_RECENT.atLeast( JAVA_9 ) )
- {
- testIsJava9AtLeast( new File( System.getProperty( "java.home" ) ).getParentFile() );
- }
+ assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isTrue();
}
-
- private static void testIsJava9AtLeast( File pathInJdk )
+ else
{
- File path = new File( pathInJdk, "bin" + separator + "java" );
-
- mockStatic( SystemUtils.class );
-
- when( SystemUtils.isJava9AtLeast( anyString() ) )
- .thenCallRealMethod();
-
- when( SystemUtils.toJdkHomeFromJvmExec( anyString() ) )
- .thenCallRealMethod();
-
- when( SystemUtils.toJdkHomeFromJre() )
- .thenCallRealMethod();
-
- when( SystemUtils.toJdkHomeFromJre( anyString() ) )
- .thenCallRealMethod();
-
- when( SystemUtils.isBuiltInJava9AtLeast() )
- .thenCallRealMethod();
-
- when( SystemUtils.toJdkVersionFromReleaseFile( any( File.class ) ) )
- .thenCallRealMethod();
-
- when( SystemUtils.isJava9AtLeast( any( BigDecimal.class ) ) )
- .thenCallRealMethod();
-
- if ( JAVA_RECENT.atLeast( JAVA_9 ) )
- {
- assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isTrue();
- }
- else
- {
- assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isFalse();
- }
-
- verifyStatic( SystemUtils.class, times( 0 ) );
- SystemUtils.toJdkVersionFromReleaseFile( any( File.class ) );
-
- verifyStatic( SystemUtils.class, times( 1 ) );
- SystemUtils.isBuiltInJava9AtLeast();
+ assertThat( SystemUtils.isJava9AtLeast( path.getAbsolutePath() ) ).isFalse();
}
+
+ SystemUtils.isBuiltInJava9AtLeast();
}
}