Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[MSHARED-1152] - Address formatting in compliance with code style def…
…inition
  • Loading branch information
iofit committed Oct 18, 2022
commit f7e6799f811f756ec7801afbbf31d147d7937de8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,7 +58,7 @@ public void setUp() throws IOException

System.setProperties( p );

lrd = Files.createTempFile( temporaryFolder, "", "" ).toFile();
lrd = Files.createTempFile(temporaryFolder, "", "").toFile();

}

Expand Down Expand Up @@ -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 );

Expand All @@ -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() );
Expand All @@ -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 );
Expand All @@ -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() );
Expand All @@ -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 );
Expand All @@ -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 );

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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()
Expand All @@ -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();

Expand All @@ -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 );
Expand All @@ -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" );

Expand All @@ -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" );

Expand All @@ -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" );

Expand All @@ -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" );

Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand All @@ -953,8 +944,8 @@ private void assertArgumentsPresentInOrder( Commandline cli, List<String> 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<String> requiredArgs )
Expand All @@ -964,7 +955,7 @@ private void assertArgumentsPresent( Commandline cli, Set<String> 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);
}
}

Expand All @@ -975,7 +966,7 @@ private void assertArgumentsNotPresent( Commandline cli, Set<String> 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.");
}
}

Expand Down