From 101faad71a93445359600abb8557ce99cbf1e30b Mon Sep 17 00:00:00 2001 From: iofit Date: Mon, 17 Oct 2022 17:40:39 -0700 Subject: [PATCH 1/6] [MSHARED-1152] - Migrate tests to JUnit5 --- pom.xml | 17 ++- .../shared/invoker/DefaultInvokerTest.java | 17 ++- .../invoker/MavenCommandLineBuilderTest.java | 131 ++++++++---------- .../shared/invoker/SystemOutHandlerTest.java | 2 +- .../shared/invoker/SystemOutLoggerTest.java | 6 +- 5 files changed, 85 insertions(+), 88 deletions(-) diff --git a/pom.xml b/pom.xml index 5ba5774..58d07e3 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,18 @@ under the License. 2022-04-05T18:45:23Z + + + + org.junit + junit-bom + 5.9.1 + pom + import + + + + org.apache.maven.shared @@ -84,9 +96,8 @@ under the License. 1 - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter test diff --git a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java index 8f59e2a..f21327f 100644 --- a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java @@ -19,8 +19,11 @@ * under the License. */ +import org.apache.maven.shared.utils.Os; +import org.apache.maven.shared.utils.StringUtils; +import org.junit.jupiter.api.Test; + import java.io.File; -import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -28,11 +31,7 @@ import java.util.Collections; import java.util.Properties; -import org.apache.maven.shared.utils.Os; -import org.apache.maven.shared.utils.StringUtils; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class DefaultInvokerTest { @@ -121,7 +120,7 @@ public void testSpacePom() request.setDebug( true ); request.setGoals( Collections.singletonList( "clean" ) ); request.setProperties( getProperties() ); - + InvocationResult result = invoker.execute( request ); assertEquals( 0, result.getExitCode() ); @@ -344,7 +343,7 @@ private void logTestStart() System.out.println( "Starting: " + element.getMethodName() ); } - + private Properties getProperties() { Properties properties = new Properties(); @@ -353,7 +352,7 @@ private Properties getProperties() properties.put( "maven.compiler.source", "1.7" ); properties.put( "maven.compiler.target", "1.7" ); } - + String httpProtocols = System.getProperty( "https.protocols" ); if ( httpProtocols != null ) { diff --git a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java index 7a6c7dc..b4f507e 100644 --- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java @@ -19,45 +19,34 @@ * under the License. */ +import org.apache.maven.shared.utils.Os; +import org.apache.maven.shared.utils.cli.Commandline; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Properties; -import java.util.Set; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; -import org.apache.maven.shared.utils.Os; -import org.apache.maven.shared.utils.cli.Commandline; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeThat; +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.assumingThat; public class MavenCommandLineBuilderTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @TempDir + public Path temporaryFolder; private Properties sysProps; private File lrd; private MavenCommandLineBuilder mclb = new MavenCommandLineBuilder(); private Commandline cli = new Commandline(); - @Before + @BeforeEach public void setUp() throws IOException { sysProps = System.getProperties(); @@ -65,11 +54,11 @@ public void setUp() throws IOException System.setProperties( p ); - lrd = temporaryFolder.newFile(); + lrd = Files.createTempFile(temporaryFolder, "", "").toFile(); } - @After + @AfterEach public void tearDown() { System.setProperties( sysProps ); @@ -109,7 +98,7 @@ public void testShouldFailToSetLocalRepoLocationFromRequestWhenItIsAFile() @Test public void testShouldSetLocalRepoLocationGlobally() throws IOException { - File lrd = temporaryFolder.newFolder( "workdir" ).getCanonicalFile(); + File lrd = Files.createDirectory(temporaryFolder.resolve("workdir")).toFile().getCanonicalFile(); mclb.setLocalRepositoryDirectory( lrd ); mclb.setLocalRepository( newRequest(), cli ); @@ -120,7 +109,7 @@ public void testShouldSetLocalRepoLocationGlobally() throws IOException public void testShouldSetLocalRepoLocationFromRequest() throws Exception { - File lrd = temporaryFolder.newFolder( "workdir" ).getCanonicalFile(); + File lrd = Files.createDirectory(temporaryFolder.resolve("workdir")).toFile().getCanonicalFile(); mclb.setLocalRepository( newRequest().setLocalRepositoryDirectory( lrd ), cli ); assertArgumentsPresentInOrder( cli, "-D", "maven.repo.local=" + lrd.getPath() ); @@ -130,8 +119,8 @@ public void testShouldSetLocalRepoLocationFromRequest() public void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() throws Exception { - File lrd = temporaryFolder.newFolder( "workdir" ).getCanonicalFile(); - File glrd = temporaryFolder.newFolder( "global-workdir" ).getCanonicalFile(); + File lrd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile().getCanonicalFile(); + File glrd = Files.createDirectory(temporaryFolder.resolve( "global-workdir" )).toFile().getCanonicalFile(); mclb.setLocalRepositoryDirectory( glrd ); mclb.setLocalRepository( newRequest().setLocalRepositoryDirectory( lrd ), cli ); @@ -143,7 +132,7 @@ public void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() public void testShouldSetWorkingDirectoryGlobally() throws Exception { - File wd = temporaryFolder.newFolder( "workdir" ); + File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); mclb.setBaseDirectory( wd ); Commandline commandline = mclb.build( newRequest() ); @@ -155,7 +144,7 @@ public void testShouldSetWorkingDirectoryGlobally() public void testShouldSetWorkingDirectoryFromRequest() throws Exception { - File wd = temporaryFolder.newFolder( "workdir" ); + File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); InvocationRequest req = newRequest(); req.setBaseDirectory( wd ); @@ -169,8 +158,8 @@ public void testShouldSetWorkingDirectoryFromRequest() public void testRequestProvidedWorkingDirectoryShouldOverrideGlobal() throws Exception { - File wd = temporaryFolder.newFolder( "workdir" ); - File gwd = temporaryFolder.newFolder( "global-workdir" ); + File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); + File gwd = Files.createDirectory(temporaryFolder.resolve( "global-workdir" )).toFile(); mclb.setBaseDirectory( gwd ); @@ -200,7 +189,7 @@ private File setupTempMavenHomeIfMissing( boolean forceDummy ) if ( forceDummy || ( mavenHome == null ) || !new File( mavenHome ).exists() ) { - appDir = temporaryFolder.newFolder( "invoker-tests", "maven-home" ); + appDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "maven-home" )).toFile(); File binDir = new File( appDir, "bin" ); binDir.mkdirs(); @@ -246,7 +235,7 @@ public void testShouldFailIfLoggerSetToNull() public void testShouldFindDummyMavenExecutable() throws Exception { - File dummyMavenHomeBin = temporaryFolder.newFolder( "invoker-tests", "dummy-maven-home", "bin" ); + File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -268,7 +257,7 @@ public void testShouldFindDummyMavenExecutable() public void testShouldFindDummyPS1MavenExecutable() throws Exception { - File dummyMavenHomeBin = temporaryFolder.newFolder( "invoker-tests", "dummy-maven-home", "bin" ); + File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -285,7 +274,7 @@ public void testShouldFindDummyPS1MavenExecutable() public void testShouldFindDummyMavenExecutableWithMavenHomeFromRequest() throws Exception { - File dummyMavenHomeBin = temporaryFolder.newFolder( "invoker-tests", "dummy-maven-home", "bin" ); + File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -531,7 +520,7 @@ public void testShouldSetNoTransferProgressFlagFromRequest() public void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() throws Exception { - File projectDir = temporaryFolder.newFolder( "invoker-tests", "file-option-nonstd-pom-file-location" ); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "file-option-nonstd-pom-file-location" )).toFile(); File pomFile = createDummyFile( projectDir, "non-standard-pom.xml" ).getCanonicalFile(); @@ -553,7 +542,7 @@ public void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() public void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() throws Exception { - File projectDir = temporaryFolder.newFolder( "invoker-tests", "std-pom-file-location" ); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-pom-file-location" )).toFile(); File pomFile = createDummyFile( projectDir, "pom.xml" ).getCanonicalFile(); @@ -575,9 +564,9 @@ public void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() public void testShouldSetPomForOutsideWorkspace() throws Exception { - File projectDir = temporaryFolder.newFolder( "invoker-tests", "std-pom-file-location" ); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-pom-file-location" )).toFile(); - File outsidePom = temporaryFolder.newFile( "pom.xml" ); + File outsidePom = Files.createFile(temporaryFolder.resolve( "pom.xml" )).toFile(); InvocationRequest req = newRequest() @@ -599,7 +588,7 @@ public void testShouldSetPomForOutsideWorkspace() public void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() throws Exception { - File projectDir = temporaryFolder.newFolder( "invoker-tests", "std-basedir-is-pom-file" ); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-is-pom-file" )).toFile(); File basedir = createDummyFile( projectDir, "pom.xml" ).getCanonicalFile(); @@ -621,7 +610,7 @@ public void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() public void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() throws Exception { - File projectDir = temporaryFolder.newFolder( "invoker-tests", "std-basedir-no-pom-filename" ); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-no-pom-filename" )).toFile(); InvocationRequest req = newRequest().setBaseDirectory( projectDir ); @@ -641,7 +630,7 @@ public void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() public void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() throws Exception { - File projectDir = temporaryFolder.newFolder( "invoker-tests", "std-basedir-with-pom-filename" ); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-with-pom-filename" )).toFile(); InvocationRequest req = newRequest().setBaseDirectory( projectDir ).setPomFileName( "non-standard-pom.xml" ); @@ -660,7 +649,7 @@ public void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() public void testShouldSpecifyCustomUserSettingsLocationFromRequest() throws Exception { - File projectDir = temporaryFolder.newFolder( "invoker-tests", "custom-settings" ); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-settings" )).toFile(); File settingsFile = createDummyFile( projectDir, "settings.xml" ); @@ -678,7 +667,7 @@ public void testShouldSpecifyCustomUserSettingsLocationFromRequest() public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() throws Exception { - File projectDir = temporaryFolder.newFolder( "invoker-tests", "custom-settings" ).getCanonicalFile(); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-settings" )).toFile().getCanonicalFile(); File settingsFile = createDummyFile( projectDir, "settings.xml" ); @@ -696,7 +685,7 @@ public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() public void testShouldSpecifyCustomToolchainsLocationFromRequest() throws Exception { - File projectDir = temporaryFolder.newFolder( "invoker-tests", "custom-toolchains" ); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-toolchains" )).toFile(); File toolchainsFile = createDummyFile( projectDir, "toolchains.xml" ); @@ -787,7 +776,7 @@ public void testBuildTypicalMavenInvocationEndToEnd() InvocationRequest request = newRequest(); - File projectDir = temporaryFolder.newFolder( "invoker-tests", "typical-end-to-end-cli-build" ); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "typical-end-to-end-cli-build" )).toFile(); request.setBaseDirectory( projectDir ); @@ -857,46 +846,46 @@ public void testShouldInsertActivatedProfiles() public void testMvnExecutableFromInvoker() throws Exception { - assumeThat( "Test only works when maven.home is set", - System.getProperty( "maven.home" ), is(notNullValue())); + assumingThat( Objects.nonNull(System.getProperty( "maven.home" )), + () -> System.out.println("Test only works when maven.home is set")); File mavenExecutable = new File( "mvnDebug" ); mclb.setMavenExecutable( mavenExecutable ); mclb.build( newRequest() ); - assertTrue( "Expected executable to exist", mclb.getMavenExecutable().exists() ); - assertTrue( "Expected executable to be absolute", mclb.getMavenExecutable().isAbsolute() ); - assertTrue( "Expected mvnDebug as command mvnDebug", mclb.getMavenExecutable().getName().contains( "mvnDebug" ) ); + assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); + assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); + assertTrue(mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command mvnDebug"); } @Test public void testMvnExecutableFormRequest() throws Exception { - assumeThat( "Test only works when maven.home is set", - System.getProperty( "maven.home" ), is(notNullValue())); + assumingThat( Objects.nonNull(System.getProperty( "maven.home" )), + () -> System.out.println("Test only works when maven.home is set")); File mavenExecutable = new File( "mvnDebug" ); mclb.build( newRequest().setMavenExecutable( mavenExecutable ) ); - assertTrue( "Expected executable to exist", mclb.getMavenExecutable().exists() ); - assertTrue( "Expected executable to be absolute", mclb.getMavenExecutable().isAbsolute() ); - assertTrue( "Expected mvnDebug as command", mclb.getMavenExecutable().getName().contains( "mvnDebug" ) ); + assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); + assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); + assertTrue(mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command"); } @Test public void testDefaultMavenCommand() throws Exception { - assumeThat( "Test only works when maven.home is set", - System.getProperty( "maven.home" ), is(notNullValue())); + assumingThat(Objects.nonNull(System.getProperty( "maven.home" )), + () -> System.out.println("Test only works when maven.home is set")); mclb.build( newRequest() ); - assertTrue( "Expected executable to exist", mclb.getMavenExecutable().exists() ); - assertTrue( "Expected executable to be absolute", mclb.getMavenExecutable().isAbsolute() ); + assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); + assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); } @Test @@ -928,8 +917,8 @@ private void assertEnvironmentVariablePresent( Commandline cli, String varName, String expectedDeclaration = varName + "=" + varValue; - assertTrue( "Environment variable setting: '" + expectedDeclaration + "' is mssing in " - + environmentVariables, environmentVariables.contains( expectedDeclaration ) ); + assertTrue(environmentVariables.contains( expectedDeclaration ), "Environment variable setting: '" + expectedDeclaration + "' is mssing in " + + environmentVariables); } private void assertArgumentsPresentInOrder( Commandline cli, String... expected ) @@ -951,8 +940,8 @@ private void assertArgumentsPresentInOrder( Commandline cli, List expect } } - assertEquals( "Arguments: " + expected + " were not found or are in the wrong order: " - + Arrays.asList( arguments ), expected.size(), expectedCounter ); + assertEquals(expected.size(), expectedCounter, "Arguments: " + expected + " were not found or are in the wrong order: " + + Arrays.asList( arguments )); } private void assertArgumentsPresent( Commandline cli, Set requiredArgs ) @@ -962,7 +951,7 @@ private void assertArgumentsPresent( Commandline cli, Set requiredArgs ) for ( String arg : requiredArgs ) { - assertTrue( "Command-line argument: '" + arg + "' is missing in " + args, args.contains( arg ) ); + assertTrue(args.contains( arg ), "Command-line argument: '" + arg + "' is missing in " + args); } } @@ -973,7 +962,7 @@ private void assertArgumentsNotPresent( Commandline cli, Set bannedArgs for ( String arg : bannedArgs ) { - assertFalse( "Command-line argument: '" + arg + "' should not be present.", args.contains( arg ) ); + assertFalse(args.contains( arg ), "Command-line argument: '" + arg + "' should not be present."); } } diff --git a/src/test/java/org/apache/maven/shared/invoker/SystemOutHandlerTest.java b/src/test/java/org/apache/maven/shared/invoker/SystemOutHandlerTest.java index 3870955..ddc5e72 100644 --- a/src/test/java/org/apache/maven/shared/invoker/SystemOutHandlerTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/SystemOutHandlerTest.java @@ -19,7 +19,7 @@ * under the License. */ -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SystemOutHandlerTest { diff --git a/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java b/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java index f936ba9..4ac9287 100644 --- a/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java @@ -19,13 +19,11 @@ * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import org.junit.jupiter.api.Test; import java.net.MalformedURLException; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; public class SystemOutLoggerTest { From 8d0c48e439cefa98e8a0c1699c6a6fc9bba9bf53 Mon Sep 17 00:00:00 2001 From: iofit Date: Tue, 18 Oct 2022 14:18:58 -0700 Subject: [PATCH 2/6] [MSHARED-1152] - Address formatting in compliance with code style definition --- .../shared/invoker/DefaultInvokerTest.java | 8 +- .../invoker/MavenCommandLineBuilderTest.java | 115 ++++++++++-------- 2 files changed, 68 insertions(+), 55 deletions(-) diff --git a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java index f21327f..2f4c518 100644 --- a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java @@ -19,10 +19,6 @@ * under the License. */ -import org.apache.maven.shared.utils.Os; -import org.apache.maven.shared.utils.StringUtils; -import org.junit.jupiter.api.Test; - import java.io.File; import java.net.URI; import java.net.URISyntaxException; @@ -31,6 +27,10 @@ import java.util.Collections; import java.util.Properties; +import org.apache.maven.shared.utils.Os; +import org.apache.maven.shared.utils.StringUtils; +import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.assertEquals; public class DefaultInvokerTest diff --git a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java index b4f507e..cb3192a 100644 --- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java @@ -19,13 +19,6 @@ * under the License. */ -import org.apache.maven.shared.utils.Os; -import org.apache.maven.shared.utils.cli.Commandline; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; - import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -33,6 +26,13 @@ import java.nio.file.Path; import java.util.*; +import org.apache.maven.shared.utils.Os; +import org.apache.maven.shared.utils.cli.Commandline; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assumptions.assumingThat; @@ -54,7 +54,7 @@ public void setUp() throws IOException System.setProperties( p ); - lrd = Files.createTempFile(temporaryFolder, "", "").toFile(); + lrd = Files.createTempFile( temporaryFolder, "", "" ).toFile(); } @@ -98,7 +98,7 @@ public void testShouldFailToSetLocalRepoLocationFromRequestWhenItIsAFile() @Test public void testShouldSetLocalRepoLocationGlobally() throws IOException { - File lrd = Files.createDirectory(temporaryFolder.resolve("workdir")).toFile().getCanonicalFile(); + File lrd = Files.createDirectory( temporaryFolder.resolve( "workdir" )).toFile().getCanonicalFile(); mclb.setLocalRepositoryDirectory( lrd ); mclb.setLocalRepository( newRequest(), cli ); @@ -109,7 +109,7 @@ public void testShouldSetLocalRepoLocationGlobally() throws IOException public void testShouldSetLocalRepoLocationFromRequest() throws Exception { - File lrd = Files.createDirectory(temporaryFolder.resolve("workdir")).toFile().getCanonicalFile(); + File lrd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile().getCanonicalFile(); mclb.setLocalRepository( newRequest().setLocalRepositoryDirectory( lrd ), cli ); assertArgumentsPresentInOrder( cli, "-D", "maven.repo.local=" + lrd.getPath() ); @@ -119,8 +119,8 @@ public void testShouldSetLocalRepoLocationFromRequest() public void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() throws Exception { - File lrd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile().getCanonicalFile(); - File glrd = Files.createDirectory(temporaryFolder.resolve( "global-workdir" )).toFile().getCanonicalFile(); + File lrd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile().getCanonicalFile(); + File glrd = Files.createDirectory( temporaryFolder.resolve( "global-workdir" ) ).toFile().getCanonicalFile(); mclb.setLocalRepositoryDirectory( glrd ); mclb.setLocalRepository( newRequest().setLocalRepositoryDirectory( lrd ), cli ); @@ -132,7 +132,7 @@ public void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() public void testShouldSetWorkingDirectoryGlobally() throws Exception { - File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); + File wd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile(); mclb.setBaseDirectory( wd ); Commandline commandline = mclb.build( newRequest() ); @@ -144,7 +144,7 @@ public void testShouldSetWorkingDirectoryGlobally() public void testShouldSetWorkingDirectoryFromRequest() throws Exception { - File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); + File wd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile(); InvocationRequest req = newRequest(); req.setBaseDirectory( wd ); @@ -158,8 +158,8 @@ public void testShouldSetWorkingDirectoryFromRequest() public void testRequestProvidedWorkingDirectoryShouldOverrideGlobal() throws Exception { - File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); - File gwd = Files.createDirectory(temporaryFolder.resolve( "global-workdir" )).toFile(); + File wd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile(); + File gwd = Files.createDirectory( temporaryFolder.resolve( "global-workdir" ) ).toFile(); mclb.setBaseDirectory( gwd ); @@ -189,7 +189,7 @@ private File setupTempMavenHomeIfMissing( boolean forceDummy ) if ( forceDummy || ( mavenHome == null ) || !new File( mavenHome ).exists() ) { - appDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "maven-home" )).toFile(); + appDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ).resolve( "maven-home" ) ).toFile(); File binDir = new File( appDir, "bin" ); binDir.mkdirs(); @@ -235,7 +235,8 @@ public void testShouldFailIfLoggerSetToNull() public void testShouldFindDummyMavenExecutable() throws Exception { - File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); + File dummyMavenHomeBin = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "dummy-maven-home" ).resolve( "bin" ) ).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -257,7 +258,8 @@ public void testShouldFindDummyMavenExecutable() public void testShouldFindDummyPS1MavenExecutable() throws Exception { - File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); + File dummyMavenHomeBin = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "dummy-maven-home" ).resolve( "bin" ) ).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -274,7 +276,8 @@ public void testShouldFindDummyPS1MavenExecutable() public void testShouldFindDummyMavenExecutableWithMavenHomeFromRequest() throws Exception { - File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); + File dummyMavenHomeBin = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "dummy-maven-home" ).resolve( "bin" ) ).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -520,7 +523,8 @@ public void testShouldSetNoTransferProgressFlagFromRequest() public void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "file-option-nonstd-pom-file-location" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "file-option-nonstd-pom-file-location" ) ).toFile(); File pomFile = createDummyFile( projectDir, "non-standard-pom.xml" ).getCanonicalFile(); @@ -542,7 +546,8 @@ public void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() public void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-pom-file-location" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "std-pom-file-location" ) ).toFile(); File pomFile = createDummyFile( projectDir, "pom.xml" ).getCanonicalFile(); @@ -564,9 +569,10 @@ public void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() public void testShouldSetPomForOutsideWorkspace() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-pom-file-location" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "std-pom-file-location" ) ).toFile(); - File outsidePom = Files.createFile(temporaryFolder.resolve( "pom.xml" )).toFile(); + File outsidePom = Files.createFile( temporaryFolder.resolve( "pom.xml" ) ).toFile(); InvocationRequest req = newRequest() @@ -588,7 +594,8 @@ public void testShouldSetPomForOutsideWorkspace() public void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-is-pom-file" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "std-basedir-is-pom-file" ) ).toFile(); File basedir = createDummyFile( projectDir, "pom.xml" ).getCanonicalFile(); @@ -610,7 +617,8 @@ public void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() public void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-no-pom-filename" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "std-basedir-no-pom-filename" ) ).toFile(); InvocationRequest req = newRequest().setBaseDirectory( projectDir ); @@ -630,7 +638,8 @@ public void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() public void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-with-pom-filename" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "std-basedir-with-pom-filename" ) ).toFile(); InvocationRequest req = newRequest().setBaseDirectory( projectDir ).setPomFileName( "non-standard-pom.xml" ); @@ -649,7 +658,8 @@ public void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() public void testShouldSpecifyCustomUserSettingsLocationFromRequest() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-settings" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "custom-settings" ) ).toFile(); File settingsFile = createDummyFile( projectDir, "settings.xml" ); @@ -667,7 +677,8 @@ public void testShouldSpecifyCustomUserSettingsLocationFromRequest() public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-settings" )).toFile().getCanonicalFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "custom-settings" ) ).toFile().getCanonicalFile(); File settingsFile = createDummyFile( projectDir, "settings.xml" ); @@ -685,7 +696,8 @@ public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() public void testShouldSpecifyCustomToolchainsLocationFromRequest() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-toolchains" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "custom-toolchains" ) ).toFile(); File toolchainsFile = createDummyFile( projectDir, "toolchains.xml" ); @@ -776,7 +788,8 @@ public void testBuildTypicalMavenInvocationEndToEnd() InvocationRequest request = newRequest(); - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "typical-end-to-end-cli-build" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "typical-end-to-end-cli-build" ) ).toFile(); request.setBaseDirectory( projectDir ); @@ -846,46 +859,46 @@ public void testShouldInsertActivatedProfiles() public void testMvnExecutableFromInvoker() throws Exception { - assumingThat( Objects.nonNull(System.getProperty( "maven.home" )), - () -> System.out.println("Test only works when maven.home is set")); + assumingThat( Objects.nonNull( System.getProperty( "maven.home" ) ), + () -> System.out.println( "Test only works when maven.home is set" ) ); File mavenExecutable = new File( "mvnDebug" ); mclb.setMavenExecutable( mavenExecutable ); mclb.build( newRequest() ); - assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); - assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); - assertTrue(mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command mvnDebug"); + assertTrue( mclb.getMavenExecutable().exists(), "Expected executable to exist" ); + assertTrue( mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute" ); + assertTrue( mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command mvnDebug" ); } @Test public void testMvnExecutableFormRequest() throws Exception { - assumingThat( Objects.nonNull(System.getProperty( "maven.home" )), - () -> System.out.println("Test only works when maven.home is set")); + assumingThat( Objects.nonNull( System.getProperty( "maven.home" ) ), + () -> System.out.println( "Test only works when maven.home is set" ) ); File mavenExecutable = new File( "mvnDebug" ); mclb.build( newRequest().setMavenExecutable( mavenExecutable ) ); - assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); - assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); - assertTrue(mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command"); + assertTrue( mclb.getMavenExecutable().exists(), "Expected executable to exist" ); + assertTrue( mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute" ); + assertTrue( mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command" ); } @Test public void testDefaultMavenCommand() throws Exception { - assumingThat(Objects.nonNull(System.getProperty( "maven.home" )), - () -> System.out.println("Test only works when maven.home is set")); + assumingThat(Objects.nonNull( System.getProperty( "maven.home" ) ), + () -> System.out.println( "Test only works when maven.home is set" ) ); mclb.build( newRequest() ); - assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); - assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); + assertTrue( mclb.getMavenExecutable().exists(), "Expected executable to exist" ); + assertTrue( mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute" ); } @Test @@ -917,8 +930,8 @@ private void assertEnvironmentVariablePresent( Commandline cli, String varName, String expectedDeclaration = varName + "=" + varValue; - assertTrue(environmentVariables.contains( expectedDeclaration ), "Environment variable setting: '" + expectedDeclaration + "' is mssing in " - + environmentVariables); + assertTrue( environmentVariables.contains( expectedDeclaration ), "Environment variable setting: '" + + expectedDeclaration + "' is missing in " + environmentVariables ); } private void assertArgumentsPresentInOrder( Commandline cli, String... expected ) @@ -940,8 +953,8 @@ private void assertArgumentsPresentInOrder( Commandline cli, List expect } } - assertEquals(expected.size(), expectedCounter, "Arguments: " + expected + " were not found or are in the wrong order: " - + Arrays.asList( arguments )); + assertEquals( expected.size(), expectedCounter, "Arguments: " + expected + " were not found or are in the wrong order: " + + Arrays.asList( arguments ) ); } private void assertArgumentsPresent( Commandline cli, Set requiredArgs ) @@ -951,7 +964,7 @@ private void assertArgumentsPresent( Commandline cli, Set requiredArgs ) for ( String arg : requiredArgs ) { - assertTrue(args.contains( arg ), "Command-line argument: '" + arg + "' is missing in " + args); + assertTrue( args.contains( arg ), "Command-line argument: '" + arg + "' is missing in " + args ); } } @@ -962,7 +975,7 @@ private void assertArgumentsNotPresent( Commandline cli, Set bannedArgs for ( String arg : bannedArgs ) { - assertFalse(args.contains( arg ), "Command-line argument: '" + arg + "' should not be present."); + assertFalse( args.contains( arg ), "Command-line argument: '" + arg + "' should not be present." ); } } From f7e6799f811f756ec7801afbbf31d147d7937de8 Mon Sep 17 00:00:00 2001 From: iofit Date: Tue, 18 Oct 2022 14:18:58 -0700 Subject: [PATCH 3/6] [MSHARED-1152] - Address formatting in compliance with code style definition --- .../invoker/MavenCommandLineBuilderTest.java | 107 ++++++++---------- 1 file changed, 49 insertions(+), 58 deletions(-) diff --git a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java index cb3192a..d526e44 100644 --- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java @@ -33,7 +33,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assumptions.assumingThat; public class MavenCommandLineBuilderTest @@ -54,7 +58,7 @@ public void setUp() throws IOException System.setProperties( p ); - lrd = Files.createTempFile( temporaryFolder, "", "" ).toFile(); + lrd = Files.createTempFile(temporaryFolder, "", "").toFile(); } @@ -98,7 +102,7 @@ public void testShouldFailToSetLocalRepoLocationFromRequestWhenItIsAFile() @Test public void testShouldSetLocalRepoLocationGlobally() throws IOException { - File lrd = Files.createDirectory( temporaryFolder.resolve( "workdir" )).toFile().getCanonicalFile(); + File lrd = Files.createDirectory(temporaryFolder.resolve("workdir")).toFile().getCanonicalFile(); mclb.setLocalRepositoryDirectory( lrd ); mclb.setLocalRepository( newRequest(), cli ); @@ -109,7 +113,7 @@ public void testShouldSetLocalRepoLocationGlobally() throws IOException public void testShouldSetLocalRepoLocationFromRequest() throws Exception { - File lrd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile().getCanonicalFile(); + File lrd = Files.createDirectory(temporaryFolder.resolve("workdir")).toFile().getCanonicalFile(); mclb.setLocalRepository( newRequest().setLocalRepositoryDirectory( lrd ), cli ); assertArgumentsPresentInOrder( cli, "-D", "maven.repo.local=" + lrd.getPath() ); @@ -119,8 +123,8 @@ public void testShouldSetLocalRepoLocationFromRequest() public void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() throws Exception { - File lrd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile().getCanonicalFile(); - File glrd = Files.createDirectory( temporaryFolder.resolve( "global-workdir" ) ).toFile().getCanonicalFile(); + File lrd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile().getCanonicalFile(); + File glrd = Files.createDirectory(temporaryFolder.resolve( "global-workdir" )).toFile().getCanonicalFile(); mclb.setLocalRepositoryDirectory( glrd ); mclb.setLocalRepository( newRequest().setLocalRepositoryDirectory( lrd ), cli ); @@ -132,7 +136,7 @@ public void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() public void testShouldSetWorkingDirectoryGlobally() throws Exception { - File wd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile(); + File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); mclb.setBaseDirectory( wd ); Commandline commandline = mclb.build( newRequest() ); @@ -144,7 +148,7 @@ public void testShouldSetWorkingDirectoryGlobally() public void testShouldSetWorkingDirectoryFromRequest() throws Exception { - File wd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile(); + File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); InvocationRequest req = newRequest(); req.setBaseDirectory( wd ); @@ -158,8 +162,8 @@ public void testShouldSetWorkingDirectoryFromRequest() public void testRequestProvidedWorkingDirectoryShouldOverrideGlobal() throws Exception { - File wd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile(); - File gwd = Files.createDirectory( temporaryFolder.resolve( "global-workdir" ) ).toFile(); + File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); + File gwd = Files.createDirectory(temporaryFolder.resolve( "global-workdir" )).toFile(); mclb.setBaseDirectory( gwd ); @@ -189,7 +193,7 @@ private File setupTempMavenHomeIfMissing( boolean forceDummy ) if ( forceDummy || ( mavenHome == null ) || !new File( mavenHome ).exists() ) { - appDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ).resolve( "maven-home" ) ).toFile(); + appDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "maven-home" )).toFile(); File binDir = new File( appDir, "bin" ); binDir.mkdirs(); @@ -235,8 +239,7 @@ public void testShouldFailIfLoggerSetToNull() public void testShouldFindDummyMavenExecutable() throws Exception { - File dummyMavenHomeBin = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "dummy-maven-home" ).resolve( "bin" ) ).toFile(); + File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -258,8 +261,7 @@ public void testShouldFindDummyMavenExecutable() public void testShouldFindDummyPS1MavenExecutable() throws Exception { - File dummyMavenHomeBin = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "dummy-maven-home" ).resolve( "bin" ) ).toFile(); + File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -276,8 +278,7 @@ public void testShouldFindDummyPS1MavenExecutable() public void testShouldFindDummyMavenExecutableWithMavenHomeFromRequest() throws Exception { - File dummyMavenHomeBin = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "dummy-maven-home" ).resolve( "bin" ) ).toFile(); + File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -523,8 +524,7 @@ public void testShouldSetNoTransferProgressFlagFromRequest() public void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() throws Exception { - File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "file-option-nonstd-pom-file-location" ) ).toFile(); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "file-option-nonstd-pom-file-location" )).toFile(); File pomFile = createDummyFile( projectDir, "non-standard-pom.xml" ).getCanonicalFile(); @@ -546,8 +546,7 @@ public void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() public void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() throws Exception { - File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "std-pom-file-location" ) ).toFile(); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-pom-file-location" )).toFile(); File pomFile = createDummyFile( projectDir, "pom.xml" ).getCanonicalFile(); @@ -569,10 +568,9 @@ public void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() public void testShouldSetPomForOutsideWorkspace() throws Exception { - File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "std-pom-file-location" ) ).toFile(); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-pom-file-location" )).toFile(); - File outsidePom = Files.createFile( temporaryFolder.resolve( "pom.xml" ) ).toFile(); + File outsidePom = Files.createFile(temporaryFolder.resolve( "pom.xml" )).toFile(); InvocationRequest req = newRequest() @@ -594,8 +592,7 @@ public void testShouldSetPomForOutsideWorkspace() public void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() throws Exception { - File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "std-basedir-is-pom-file" ) ).toFile(); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-is-pom-file" )).toFile(); File basedir = createDummyFile( projectDir, "pom.xml" ).getCanonicalFile(); @@ -617,8 +614,7 @@ public void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() public void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() throws Exception { - File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "std-basedir-no-pom-filename" ) ).toFile(); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-no-pom-filename" )).toFile(); InvocationRequest req = newRequest().setBaseDirectory( projectDir ); @@ -638,8 +634,7 @@ public void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() public void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() throws Exception { - File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "std-basedir-with-pom-filename" ) ).toFile(); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-with-pom-filename" )).toFile(); InvocationRequest req = newRequest().setBaseDirectory( projectDir ).setPomFileName( "non-standard-pom.xml" ); @@ -658,8 +653,7 @@ public void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() public void testShouldSpecifyCustomUserSettingsLocationFromRequest() throws Exception { - File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "custom-settings" ) ).toFile(); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-settings" )).toFile(); File settingsFile = createDummyFile( projectDir, "settings.xml" ); @@ -677,8 +671,7 @@ public void testShouldSpecifyCustomUserSettingsLocationFromRequest() public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() throws Exception { - File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "custom-settings" ) ).toFile().getCanonicalFile(); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-settings" )).toFile().getCanonicalFile(); File settingsFile = createDummyFile( projectDir, "settings.xml" ); @@ -696,8 +689,7 @@ public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() public void testShouldSpecifyCustomToolchainsLocationFromRequest() throws Exception { - File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "custom-toolchains" ) ).toFile(); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-toolchains" )).toFile(); File toolchainsFile = createDummyFile( projectDir, "toolchains.xml" ); @@ -788,8 +780,7 @@ public void testBuildTypicalMavenInvocationEndToEnd() InvocationRequest request = newRequest(); - File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) - .resolve( "typical-end-to-end-cli-build" ) ).toFile(); + File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "typical-end-to-end-cli-build" )).toFile(); request.setBaseDirectory( projectDir ); @@ -859,46 +850,46 @@ public void testShouldInsertActivatedProfiles() public void testMvnExecutableFromInvoker() throws Exception { - assumingThat( Objects.nonNull( System.getProperty( "maven.home" ) ), - () -> System.out.println( "Test only works when maven.home is set" ) ); + assumingThat( Objects.nonNull(System.getProperty( "maven.home" )), + () -> System.out.println("Test only works when maven.home is set")); File mavenExecutable = new File( "mvnDebug" ); mclb.setMavenExecutable( mavenExecutable ); mclb.build( newRequest() ); - assertTrue( mclb.getMavenExecutable().exists(), "Expected executable to exist" ); - assertTrue( mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute" ); - assertTrue( mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command mvnDebug" ); + assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); + assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); + assertTrue(mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command mvnDebug"); } @Test public void testMvnExecutableFormRequest() throws Exception { - assumingThat( Objects.nonNull( System.getProperty( "maven.home" ) ), - () -> System.out.println( "Test only works when maven.home is set" ) ); + assumingThat( Objects.nonNull(System.getProperty( "maven.home" )), + () -> System.out.println("Test only works when maven.home is set")); File mavenExecutable = new File( "mvnDebug" ); mclb.build( newRequest().setMavenExecutable( mavenExecutable ) ); - assertTrue( mclb.getMavenExecutable().exists(), "Expected executable to exist" ); - assertTrue( mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute" ); - assertTrue( mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command" ); + assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); + assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); + assertTrue(mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command"); } @Test public void testDefaultMavenCommand() throws Exception { - assumingThat(Objects.nonNull( System.getProperty( "maven.home" ) ), - () -> System.out.println( "Test only works when maven.home is set" ) ); + assumingThat(Objects.nonNull(System.getProperty( "maven.home" )), + () -> System.out.println("Test only works when maven.home is set")); mclb.build( newRequest() ); - assertTrue( mclb.getMavenExecutable().exists(), "Expected executable to exist" ); - assertTrue( mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute" ); + assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); + assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); } @Test @@ -930,8 +921,8 @@ private void assertEnvironmentVariablePresent( Commandline cli, String varName, String expectedDeclaration = varName + "=" + varValue; - assertTrue( environmentVariables.contains( expectedDeclaration ), "Environment variable setting: '" - + expectedDeclaration + "' is missing in " + environmentVariables ); + assertTrue(environmentVariables.contains( expectedDeclaration ), "Environment variable setting: '" + expectedDeclaration + "' is mssing in " + + environmentVariables); } private void assertArgumentsPresentInOrder( Commandline cli, String... expected ) @@ -953,8 +944,8 @@ private void assertArgumentsPresentInOrder( Commandline cli, List expect } } - assertEquals( expected.size(), expectedCounter, "Arguments: " + expected + " were not found or are in the wrong order: " - + Arrays.asList( arguments ) ); + assertEquals(expected.size(), expectedCounter, "Arguments: " + expected + " were not found or are in the wrong order: " + + Arrays.asList( arguments )); } private void assertArgumentsPresent( Commandline cli, Set requiredArgs ) @@ -964,7 +955,7 @@ private void assertArgumentsPresent( Commandline cli, Set requiredArgs ) for ( String arg : requiredArgs ) { - assertTrue( args.contains( arg ), "Command-line argument: '" + arg + "' is missing in " + args ); + assertTrue(args.contains( arg ), "Command-line argument: '" + arg + "' is missing in " + args); } } @@ -975,7 +966,7 @@ private void assertArgumentsNotPresent( Commandline cli, Set bannedArgs for ( String arg : bannedArgs ) { - assertFalse( args.contains( arg ), "Command-line argument: '" + arg + "' should not be present." ); + assertFalse(args.contains( arg ), "Command-line argument: '" + arg + "' should not be present."); } } From 8de1151d2d563e2a26d364e4c290e4cca44ecfc7 Mon Sep 17 00:00:00 2001 From: iofit Date: Tue, 18 Oct 2022 14:41:58 -0700 Subject: [PATCH 4/6] [MSHARED-1152] - Class by class import and respect spaces in functions --- .../invoker/MavenCommandLineBuilderTest.java | 109 ++++++++++-------- .../shared/invoker/SystemOutLoggerTest.java | 4 +- 2 files changed, 67 insertions(+), 46 deletions(-) diff --git a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java index d526e44..9a616c0 100644 --- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java @@ -24,7 +24,14 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; import org.apache.maven.shared.utils.Os; import org.apache.maven.shared.utils.cli.Commandline; @@ -58,7 +65,7 @@ public void setUp() throws IOException System.setProperties( p ); - lrd = Files.createTempFile(temporaryFolder, "", "").toFile(); + lrd = Files.createTempFile( temporaryFolder, "", "" ).toFile(); } @@ -102,7 +109,7 @@ public void testShouldFailToSetLocalRepoLocationFromRequestWhenItIsAFile() @Test public void testShouldSetLocalRepoLocationGlobally() throws IOException { - File lrd = Files.createDirectory(temporaryFolder.resolve("workdir")).toFile().getCanonicalFile(); + File lrd = Files.createDirectory( temporaryFolder.resolve( "workdir" )).toFile().getCanonicalFile(); mclb.setLocalRepositoryDirectory( lrd ); mclb.setLocalRepository( newRequest(), cli ); @@ -113,7 +120,7 @@ public void testShouldSetLocalRepoLocationGlobally() throws IOException public void testShouldSetLocalRepoLocationFromRequest() throws Exception { - File lrd = Files.createDirectory(temporaryFolder.resolve("workdir")).toFile().getCanonicalFile(); + File lrd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile().getCanonicalFile(); mclb.setLocalRepository( newRequest().setLocalRepositoryDirectory( lrd ), cli ); assertArgumentsPresentInOrder( cli, "-D", "maven.repo.local=" + lrd.getPath() ); @@ -123,8 +130,8 @@ public void testShouldSetLocalRepoLocationFromRequest() public void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() throws Exception { - File lrd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile().getCanonicalFile(); - File glrd = Files.createDirectory(temporaryFolder.resolve( "global-workdir" )).toFile().getCanonicalFile(); + File lrd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile().getCanonicalFile(); + File glrd = Files.createDirectory( temporaryFolder.resolve( "global-workdir" ) ).toFile().getCanonicalFile(); mclb.setLocalRepositoryDirectory( glrd ); mclb.setLocalRepository( newRequest().setLocalRepositoryDirectory( lrd ), cli ); @@ -136,7 +143,7 @@ public void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() public void testShouldSetWorkingDirectoryGlobally() throws Exception { - File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); + File wd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile(); mclb.setBaseDirectory( wd ); Commandline commandline = mclb.build( newRequest() ); @@ -148,7 +155,7 @@ public void testShouldSetWorkingDirectoryGlobally() public void testShouldSetWorkingDirectoryFromRequest() throws Exception { - File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); + File wd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile(); InvocationRequest req = newRequest(); req.setBaseDirectory( wd ); @@ -162,8 +169,8 @@ public void testShouldSetWorkingDirectoryFromRequest() public void testRequestProvidedWorkingDirectoryShouldOverrideGlobal() throws Exception { - File wd = Files.createDirectory(temporaryFolder.resolve( "workdir" )).toFile(); - File gwd = Files.createDirectory(temporaryFolder.resolve( "global-workdir" )).toFile(); + File wd = Files.createDirectory( temporaryFolder.resolve( "workdir" ) ).toFile(); + File gwd = Files.createDirectory( temporaryFolder.resolve( "global-workdir" ) ).toFile(); mclb.setBaseDirectory( gwd ); @@ -193,7 +200,7 @@ private File setupTempMavenHomeIfMissing( boolean forceDummy ) if ( forceDummy || ( mavenHome == null ) || !new File( mavenHome ).exists() ) { - appDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "maven-home" )).toFile(); + appDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ).resolve( "maven-home" ) ).toFile(); File binDir = new File( appDir, "bin" ); binDir.mkdirs(); @@ -239,7 +246,7 @@ public void testShouldFailIfLoggerSetToNull() public void testShouldFindDummyMavenExecutable() throws Exception { - File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); + File dummyMavenHomeBin = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" ) ).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -261,7 +268,8 @@ public void testShouldFindDummyMavenExecutable() public void testShouldFindDummyPS1MavenExecutable() throws Exception { - File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); + File dummyMavenHomeBin = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "dummy-maven-home" ).resolve( "bin" ) ).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -278,7 +286,8 @@ public void testShouldFindDummyPS1MavenExecutable() public void testShouldFindDummyMavenExecutableWithMavenHomeFromRequest() throws Exception { - File dummyMavenHomeBin = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" )).toFile(); + File dummyMavenHomeBin = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "dummy-maven-home" ).resolve( "bin" ) ).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) @@ -524,7 +533,8 @@ public void testShouldSetNoTransferProgressFlagFromRequest() public void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "file-option-nonstd-pom-file-location" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "file-option-nonstd-pom-file-location" ) ).toFile(); File pomFile = createDummyFile( projectDir, "non-standard-pom.xml" ).getCanonicalFile(); @@ -546,7 +556,8 @@ public void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() public void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-pom-file-location" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "std-pom-file-location" ) ).toFile(); File pomFile = createDummyFile( projectDir, "pom.xml" ).getCanonicalFile(); @@ -568,9 +579,10 @@ public void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() public void testShouldSetPomForOutsideWorkspace() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-pom-file-location" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "std-pom-file-location" ) ).toFile(); - File outsidePom = Files.createFile(temporaryFolder.resolve( "pom.xml" )).toFile(); + File outsidePom = Files.createFile( temporaryFolder.resolve( "pom.xml" ) ).toFile(); InvocationRequest req = newRequest() @@ -592,7 +604,8 @@ public void testShouldSetPomForOutsideWorkspace() public void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-is-pom-file" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "std-basedir-is-pom-file" ) ).toFile(); File basedir = createDummyFile( projectDir, "pom.xml" ).getCanonicalFile(); @@ -614,7 +627,8 @@ public void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() public void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-no-pom-filename" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "std-basedir-no-pom-filename" ) ).toFile(); InvocationRequest req = newRequest().setBaseDirectory( projectDir ); @@ -634,7 +648,8 @@ public void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() public void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "std-basedir-with-pom-filename" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "std-basedir-with-pom-filename" ) ).toFile(); InvocationRequest req = newRequest().setBaseDirectory( projectDir ).setPomFileName( "non-standard-pom.xml" ); @@ -653,7 +668,8 @@ public void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() public void testShouldSpecifyCustomUserSettingsLocationFromRequest() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-settings" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "custom-settings" ) ).toFile(); File settingsFile = createDummyFile( projectDir, "settings.xml" ); @@ -671,7 +687,8 @@ public void testShouldSpecifyCustomUserSettingsLocationFromRequest() public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-settings" )).toFile().getCanonicalFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "custom-settings" ) ).toFile().getCanonicalFile(); File settingsFile = createDummyFile( projectDir, "settings.xml" ); @@ -689,7 +706,8 @@ public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() public void testShouldSpecifyCustomToolchainsLocationFromRequest() throws Exception { - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "custom-toolchains" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "custom-toolchains" ) ).toFile(); File toolchainsFile = createDummyFile( projectDir, "toolchains.xml" ); @@ -780,7 +798,8 @@ public void testBuildTypicalMavenInvocationEndToEnd() InvocationRequest request = newRequest(); - File projectDir = Files.createDirectories(temporaryFolder.resolve( "invoker-tests" ).resolve( "typical-end-to-end-cli-build" )).toFile(); + File projectDir = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "typical-end-to-end-cli-build" ) ).toFile(); request.setBaseDirectory( projectDir ); @@ -850,46 +869,46 @@ public void testShouldInsertActivatedProfiles() public void testMvnExecutableFromInvoker() throws Exception { - assumingThat( Objects.nonNull(System.getProperty( "maven.home" )), - () -> System.out.println("Test only works when maven.home is set")); + assumingThat( Objects.nonNull( System.getProperty( "maven.home" ) ), + () -> System.out.println( "Test only works when maven.home is set" ) ); File mavenExecutable = new File( "mvnDebug" ); mclb.setMavenExecutable( mavenExecutable ); mclb.build( newRequest() ); - assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); - assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); - assertTrue(mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command mvnDebug"); + assertTrue( mclb.getMavenExecutable().exists(), "Expected executable to exist" ); + assertTrue( mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute" ); + assertTrue( mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command mvnDebug" ); } @Test public void testMvnExecutableFormRequest() throws Exception { - assumingThat( Objects.nonNull(System.getProperty( "maven.home" )), - () -> System.out.println("Test only works when maven.home is set")); + assumingThat( Objects.nonNull( System.getProperty( "maven.home" ) ), + () -> System.out.println( "Test only works when maven.home is set" ) ); File mavenExecutable = new File( "mvnDebug" ); mclb.build( newRequest().setMavenExecutable( mavenExecutable ) ); - assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); - assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); - assertTrue(mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command"); + assertTrue( mclb.getMavenExecutable().exists(), "Expected executable to exist" ); + assertTrue( mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute" ); + assertTrue( mclb.getMavenExecutable().getName().contains( "mvnDebug" ), "Expected mvnDebug as command" ); } @Test public void testDefaultMavenCommand() throws Exception { - assumingThat(Objects.nonNull(System.getProperty( "maven.home" )), - () -> System.out.println("Test only works when maven.home is set")); + assumingThat(Objects.nonNull( System.getProperty( "maven.home" ) ), + () -> System.out.println( "Test only works when maven.home is set" ) ); mclb.build( newRequest() ); - assertTrue(mclb.getMavenExecutable().exists(), "Expected executable to exist"); - assertTrue(mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute"); + assertTrue( mclb.getMavenExecutable().exists(), "Expected executable to exist" ); + assertTrue( mclb.getMavenExecutable().isAbsolute(), "Expected executable to be absolute" ); } @Test @@ -921,8 +940,8 @@ private void assertEnvironmentVariablePresent( Commandline cli, String varName, String expectedDeclaration = varName + "=" + varValue; - assertTrue(environmentVariables.contains( expectedDeclaration ), "Environment variable setting: '" + expectedDeclaration + "' is mssing in " - + environmentVariables); + assertTrue( environmentVariables.contains( expectedDeclaration ), "Environment variable setting: '" + + expectedDeclaration + "' is missing in " + environmentVariables ); } private void assertArgumentsPresentInOrder( Commandline cli, String... expected ) @@ -944,8 +963,8 @@ private void assertArgumentsPresentInOrder( Commandline cli, List expect } } - assertEquals(expected.size(), expectedCounter, "Arguments: " + expected + " were not found or are in the wrong order: " - + Arrays.asList( arguments )); + assertEquals( expected.size(), expectedCounter, "Arguments: " + expected + " were not found or are in the wrong order: " + + Arrays.asList( arguments ) ); } private void assertArgumentsPresent( Commandline cli, Set requiredArgs ) @@ -955,7 +974,7 @@ private void assertArgumentsPresent( Commandline cli, Set requiredArgs ) for ( String arg : requiredArgs ) { - assertTrue(args.contains( arg ), "Command-line argument: '" + arg + "' is missing in " + args); + assertTrue( args.contains( arg ), "Command-line argument: '" + arg + "' is missing in " + args ); } } @@ -966,7 +985,7 @@ private void assertArgumentsNotPresent( Commandline cli, Set bannedArgs for ( String arg : bannedArgs ) { - assertFalse(args.contains( arg ), "Command-line argument: '" + arg + "' should not be present."); + assertFalse( args.contains( arg ), "Command-line argument: '" + arg + "' should not be present." ); } } diff --git a/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java b/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java index 4ac9287..1238843 100644 --- a/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java @@ -23,7 +23,9 @@ import java.net.MalformedURLException; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class SystemOutLoggerTest { From 24c0a32826c2e2796bea561ca8625274224fa02d Mon Sep 17 00:00:00 2001 From: iofit Date: Tue, 18 Oct 2022 14:47:47 -0700 Subject: [PATCH 5/6] [MSHARED-1152] - Wrap line within 120 characters length --- .../maven/shared/invoker/MavenCommandLineBuilderTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java index 9a616c0..0dd7491 100644 --- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java @@ -246,7 +246,8 @@ public void testShouldFailIfLoggerSetToNull() public void testShouldFindDummyMavenExecutable() throws Exception { - File dummyMavenHomeBin = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ).resolve( "dummy-maven-home" ).resolve( "bin" ) ).toFile(); + File dummyMavenHomeBin = Files.createDirectories( temporaryFolder.resolve( "invoker-tests" ) + .resolve( "dummy-maven-home" ).resolve( "bin" ) ).toFile(); File check; if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) From 2ee29b2e5cb5df1191d7cfa0c3d5cd717a52e9c6 Mon Sep 17 00:00:00 2001 From: iofit Date: Thu, 20 Oct 2022 21:57:45 -0700 Subject: [PATCH 6/6] [MSHARED-1152] - Use assumeTrue to abort(skip) the test since assumingThat does not do that --- .../shared/invoker/MavenCommandLineBuilderTest.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java index 0dd7491..f0dc319 100644 --- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java @@ -45,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumingThat; +import static org.junit.jupiter.api.Assumptions.assumeTrue; public class MavenCommandLineBuilderTest { @@ -870,8 +870,7 @@ public void testShouldInsertActivatedProfiles() public void testMvnExecutableFromInvoker() throws Exception { - assumingThat( Objects.nonNull( System.getProperty( "maven.home" ) ), - () -> System.out.println( "Test only works when maven.home is set" ) ); + assumeTrue( Objects.nonNull( System.getProperty( "maven.home" ) ), "Test only works when maven.home is set" ); File mavenExecutable = new File( "mvnDebug" ); @@ -887,8 +886,7 @@ public void testMvnExecutableFromInvoker() public void testMvnExecutableFormRequest() throws Exception { - assumingThat( Objects.nonNull( System.getProperty( "maven.home" ) ), - () -> System.out.println( "Test only works when maven.home is set" ) ); + assumeTrue( Objects.nonNull( System.getProperty( "maven.home" ) ), "Test only works when maven.home is set" ); File mavenExecutable = new File( "mvnDebug" ); @@ -903,8 +901,7 @@ public void testMvnExecutableFormRequest() public void testDefaultMavenCommand() throws Exception { - assumingThat(Objects.nonNull( System.getProperty( "maven.home" ) ), - () -> System.out.println( "Test only works when maven.home is set" ) ); + assumeTrue(Objects.nonNull( System.getProperty( "maven.home" ) ), "Test only works when maven.home is set" ); mclb.build( newRequest() );