Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump plexus-components from 6.5 to 6.6 and upgrade to junit5 #157

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions plexus-compiler-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
package org.codehaus.plexus.compiler;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Iterator;
import java.util.Map;

import junit.framework.TestCase;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class CompilerConfigurationTest
extends TestCase
{
private CompilerConfiguration configuration;

@Override

@BeforeEach
protected void setUp()
throws Exception
{
configuration = new CompilerConfiguration();
}


@Test
public void testCustomArguments()
{
configuration.addCompilerCustomArgument( "--add-exports", "FROM-MOD/package1=OTHER-MOD" );
configuration.addCompilerCustomArgument( "--add-exports", "FROM-MOD/package2=OTHER-MOD" );

assertEquals( 1, configuration.getCustomCompilerArgumentsAsMap().size() );
assertEquals( "FROM-MOD/package2=OTHER-MOD", configuration.getCustomCompilerArgumentsAsMap().get( "--add-exports" ) );
assertEquals( 2, configuration.getCustomCompilerArgumentsEntries().size() );
assertThat(configuration.getCustomCompilerArgumentsAsMap().size(), is( 1 ));
assertThat( configuration.getCustomCompilerArgumentsAsMap().get( "--add-exports" ), is( "FROM-MOD/package2=OTHER-MOD" ) );

assertThat( configuration.getCustomCompilerArgumentsEntries().size(), is( 2 ) );
Iterator<Map.Entry<String,String>> entries = configuration.getCustomCompilerArgumentsEntries().iterator();
Map.Entry<String,String> entry;

entry = entries.next();
assertEquals( "--add-exports", entry.getKey() );
assertEquals( "FROM-MOD/package1=OTHER-MOD", entry.getValue() );
assertThat( entry.getKey(), is( "--add-exports" ) );
assertThat( entry.getValue(), is( "FROM-MOD/package1=OTHER-MOD" ) );
entry = entries.next();
assertEquals( "--add-exports", entry.getKey() );
assertEquals( "FROM-MOD/package2=OTHER-MOD", entry.getValue() );
assertThat( entry.getKey(), is( "--add-exports" ));
assertThat( entry.getValue(), is( "FROM-MOD/package2=OTHER-MOD") );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@
import java.net.URL;
import java.util.Set;

import junit.framework.TestCase;

import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
import org.codehaus.plexus.util.IOUtil;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.io.FileMatchers.anExistingFile;

/**
* Tests for all the implementations of <code>SourceInclusionScanner</code>
*
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
*/
public abstract class AbstractSourceInclusionScannerTest
extends TestCase
{

private static final String TESTFILE_DEST_MARKER_FILE =
SourceInclusionScanner.class.getName().replace( '.', '/' ) + "-testMarker.txt";

protected SourceInclusionScanner scanner;

@Test
public void testGetIncludedSources()
throws Exception
{
Expand All @@ -59,11 +62,11 @@ public void testGetIncludedSources()

Set<File> includedSources = scanner.getIncludedSources( base, base );

assertTrue( "no sources were included", !includedSources.isEmpty() );
assertThat( "no sources were included", includedSources, not( empty() ) );

for ( File file : includedSources )
{
assertTrue( "file included does not exist", file.exists() );
assertThat( "file included does not exist", file, anExistingFile() );
}
}

Expand Down Expand Up @@ -100,24 +103,18 @@ protected File getTestBaseDir()
protected void writeFile( File file )
throws IOException
{
FileWriter fWriter = null;
try
{
File parent = file.getParentFile();
if ( !parent.exists() )
{
parent.mkdirs();
}

file.deleteOnExit();
File parent = file.getParentFile();
if ( !parent.exists() )
{
parent.mkdirs();
}

fWriter = new FileWriter( file );
file.deleteOnExit();

fWriter.write( "This is just a test file." );
}
finally
try (FileWriter fWriter = new FileWriter( file ))
{
IOUtil.close( fWriter );
fWriter.write( "This is just a test file." );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* limitations under the License.
*/

import org.junit.jupiter.api.BeforeEach;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -32,11 +34,10 @@ public class SimpleSourceInclusionScannerTest

private Set<String> includes, excludes;

protected void setUp()
@BeforeEach
public void setUp()
throws Exception
{
super.setUp();

includes = Collections.singleton( "*.java" );
excludes = new HashSet<>();
scanner = new SimpleSourceInclusionScanner( includes, excludes );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
import org.codehaus.plexus.compiler.util.scan.mapping.SingleTargetSourceMapping;
import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping;
import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;

/**
* @author jdcasey
Expand All @@ -32,14 +41,14 @@ public class StaleSourceScannerTest
extends AbstractSourceInclusionScannerTest
{

protected void setUp()
@BeforeEach
public void setUp()
throws Exception
{
super.setUp();
scanner = new StaleSourceScanner();
}

// test 1.
@Test
public void testWithDefaultConstructorShouldFindOneStaleSource()
throws Exception
{
Expand All @@ -65,12 +74,12 @@ public void testWithDefaultConstructorShouldFindOneStaleSource()

Set<File> result = scanner.getIncludedSources( base, base );

assertEquals( "wrong number of stale sources returned.", 1, result.size() );
assertThat( "wrong number of stale sources returned.", result.size(), is( 1) );

assertTrue( "expected stale source file not found in result", result.contains( sourceFile ) );
assertThat( "expected stale source file not found in result", result, Matchers.contains( sourceFile ) );
}

// test 2.
@Test
public void testWithDefaultConstructorShouldNotFindStaleSources()
throws Exception
{
Expand All @@ -96,12 +105,12 @@ public void testWithDefaultConstructorShouldNotFindStaleSources()

Set<File> result = scanner.getIncludedSources( base, base );

assertEquals( "wrong number of stale sources returned.", 0, result.size() );
assertThat( "wrong number of stale sources returned.", result.size(), is( 0 ) );

assertFalse( "expected stale source file not found in result", result.contains( sourceFile ) );
assertThat( "expected stale source file not found in result", result, empty( ) );
}

// test 3.
@Test
public void testWithDefaultConstructorShouldFindStaleSourcesBecauseOfMissingTargetFile()
throws Exception
{
Expand All @@ -117,12 +126,12 @@ public void testWithDefaultConstructorShouldFindStaleSourcesBecauseOfMissingTarg

Set<File> result = scanner.getIncludedSources( base, base );

assertEquals( "wrong number of stale sources returned.", 1, result.size() );
assertThat( "wrong number of stale sources returned.", result.size(), is( 1) );

assertTrue( "expected stale source file not found in result", result.contains( sourceFile ) );
assertThat( "expected stale source file not found in result", result, contains( sourceFile ) );
}

// test 4.
@Test
public void testWithDefaultConstructorShouldFindStaleSourcesOneBecauseOfMissingTargetAndOneBecauseOfStaleTarget()
throws Exception
{
Expand Down Expand Up @@ -152,14 +161,13 @@ public void testWithDefaultConstructorShouldFindStaleSourcesOneBecauseOfMissingT

Set<File> result = scanner.getIncludedSources( base, base );

assertEquals( "wrong number of stale sources returned.", 2, result.size() );
assertThat( "wrong number of stale sources returned.", result.size(), is( 2) );

assertTrue( "expected stale source file not found in result", result.contains( sourceFile ) );
assertThat( "expected stale source file not found in result", result, containsInAnyOrder( sourceFile, sourceFile2 ) );

assertTrue( "expected stale source file not found in result", result.contains( sourceFile2 ) );
}

// test 5.
@Test
public void testWithDefaultConstructorShouldFindOneStaleSourcesWithStaleTargetAndOmitUpToDateSource()
throws Exception
{
Expand Down Expand Up @@ -207,12 +215,12 @@ public void testWithDefaultConstructorShouldFindOneStaleSourcesWithStaleTargetAn

Set<File> result = scanner.getIncludedSources( base, base );

assertEquals( "wrong number of stale sources returned.", 1, result.size() );
assertThat( "wrong number of stale sources returned.", result.size(), is( 1 ) );

assertTrue( "expected stale source file not found in result", result.contains( sourceFile ) );
assertThat( "expected stale source file not found in result", result, contains( sourceFile ) );
}

// test 6.
@Test
public void testConstructedWithMsecsShouldReturnOneSourceFileOfTwoDueToLastMod()
throws Exception
{
Expand Down Expand Up @@ -255,14 +263,12 @@ public void testConstructedWithMsecsShouldReturnOneSourceFileOfTwoDueToLastMod()

Set<File> result = scanner.getIncludedSources( base, base );

assertEquals( "wrong number of stale sources returned.", 1, result.size() );

assertTrue( "expected stale source file not found in result", result.contains( sourceFile2 ) );
assertThat( "wrong number of stale sources returned.", result.size(), is( 1 ) );

assertFalse( "expected stale source file not found in result", result.contains( sourceFile ) );
assertThat( "expected stale source file not found in result", result, contains( sourceFile2 ) );
}

// test 7.
@Test
public void testConstructedWithMsecsIncludesAndExcludesShouldReturnOneSourceFileOfThreeDueToIncludePattern()
throws Exception
{
Expand Down Expand Up @@ -318,16 +324,12 @@ public void testConstructedWithMsecsIncludesAndExcludesShouldReturnOneSourceFile

Set<File> result = scanner.getIncludedSources( base, base );

assertEquals( "wrong number of stale sources returned.", 1, result.size() );

assertFalse( "expected stale source file not found in result", result.contains( sourceFile ) );

assertFalse( "unexpected stale source file found in result", result.contains( sourceFile2 ) );
assertThat( "wrong number of stale sources returned.", result.size(), is( 1 ) );

assertTrue( "unexpected stale source file found in result", result.contains( sourceFile3 ) );
assertThat( "expected stale source file not found in result", result, contains( sourceFile3 ) );
}

// test 8.
@Test
public void testConstructedWithMsecsIncludesAndExcludesShouldReturnTwoSourceFilesOfThreeDueToExcludePattern()
throws Exception
{
Expand Down Expand Up @@ -383,16 +385,13 @@ public void testConstructedWithMsecsIncludesAndExcludesShouldReturnTwoSourceFile

Set<File> result = scanner.getIncludedSources( base, base );

assertEquals( "wrong number of stale sources returned.", 2, result.size() );
assertThat( "wrong number of stale sources returned.", result.size(), is( 2 ) );

assertFalse( "unexpected stale source file found in result", result.contains( sourceFile ) );
assertThat( "expected stale source file not found in result", result, containsInAnyOrder( sourceFile2, sourceFile3 ) );

assertTrue( "expected stale source not file found in result", result.contains( sourceFile2 ) );

assertTrue( "expected stale source not file found in result", result.contains( sourceFile3 ) );
}

// test 9.
@Test
public void testSingleFileSourceMapping()
throws Exception
{
Expand Down Expand Up @@ -420,9 +419,9 @@ public void testSingleFileSourceMapping()

Set<File> result = scanner.getIncludedSources( src, target );

assertEquals( 1, result.size() );
assertThat( result.size(), is( 1 ) );

assertTrue( result.contains( fooCs ) );
assertThat( result, contains( fooCs ) );

// ----------------------------------------------------------------------
// Add another source file
Expand All @@ -436,11 +435,11 @@ public void testSingleFileSourceMapping()

result = scanner.getIncludedSources( src, target );

assertEquals( 2, result.size() );
assertThat( result.size(), is( 2 ) );

assertThat( result, containsInAnyOrder( fooCs, barCs ) );

assertTrue( result.contains( fooCs ) );

assertTrue( result.contains( barCs ) );

// ----------------------------------------------------------------------
// Now add the result file
Expand All @@ -454,7 +453,8 @@ public void testSingleFileSourceMapping()

result = scanner.getIncludedSources( src, target );

assertEquals( 0, result.size() );
assertThat( result, empty() );


// ----------------------------------------------------------------------
// Make Application.exe older than the Foo.cs
Expand All @@ -464,9 +464,9 @@ public void testSingleFileSourceMapping()

result = scanner.getIncludedSources( src, target );

assertEquals( 1, result.size() );
assertThat( result.size(), is( 1 ) );

assertTrue( result.contains( fooCs ) );
assertThat( result, contains( fooCs ) );
}

}
Loading