You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/10/13 13:33:56 UTC
[maven] 01/01: Rewrite assertTrue to assertThat to get more
meaningful messages
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch unittests-refactor
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 3f3d775edee00f81ee5e66511c4bec6118e7cf4d
Author: rfscholte <rf...@apache.org>
AuthorDate: Sun Oct 13 15:33:42 2019 +0200
Rewrite assertTrue to assertThat to get more meaningful messages
---
maven-core/pom.xml | 5 ++
.../maven/ProjectDependenciesResolverTest.java | 5 +-
.../maven/execution/DefaultMavenExecutionTest.java | 16 ++++--
.../lifecycle/internal/ProjectBuildListTest.java | 13 +++--
.../project/AbstractMavenProjectTestCase.java | 4 +-
.../project/DefaultMavenProjectBuilderTest.java | 18 +++---
.../project/ExtensionDescriptorBuilderTest.java | 8 ++-
.../apache/maven/project/PomConstructionTest.java | 35 ++++++-----
.../apache/maven/project/ProjectBuilderTest.java | 12 +++-
.../maven/project/ProjectModelResolverTest.java | 13 ++---
.../apache/maven/project/ProjectSorterTest.java | 67 ++++++++++++----------
.../maven/toolchain/DefaultToolchainTest.java | 24 ++++----
pom.xml | 12 ++++
13 files changed, 141 insertions(+), 91 deletions(-)
diff --git a/maven-core/pom.xml b/maven-core/pom.xml
index 1c47046..73c53c4 100644
--- a/maven-core/pom.xml
+++ b/maven-core/pom.xml
@@ -136,6 +136,11 @@ under the License.
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java
index ca75c3f..0bc2978 100644
--- a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java
+++ b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java
@@ -15,6 +15,9 @@ package org.apache.maven;
* the License.
*/
+import static org.hamcrest.Matchers.endsWith;
+import static org.junit.Assert.assertThat;
+
import java.io.File;
import java.util.Collections;
import java.util.List;
@@ -109,6 +112,6 @@ public class ProjectDependenciesResolverTest
@SuppressWarnings( "deprecation" )
List<Artifact> artifacts = project.getCompileArtifacts();
assertEquals( 1, artifacts.size() );
- assertTrue( artifacts.get( 0 ).getFile().getName().endsWith( "tools.jar" ) );
+ assertThat( artifacts.get( 0 ).getFile().getName(), endsWith( "tools.jar" ) );
}
}
diff --git a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionTest.java b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionTest.java
index fbb8b90..237362e 100644
--- a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionTest.java
+++ b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionTest.java
@@ -18,20 +18,23 @@ package org.apache.maven.execution;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.project.MavenProject;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertThat;
import java.util.List;
-import junit.framework.TestCase;
+import org.apache.maven.project.MavenProject;
+import org.junit.Test;
/**
* @author Benjamin Bentmann
*/
public class DefaultMavenExecutionTest
- extends TestCase
{
-
+ @Test
public void testCopyDefault()
{
MavenExecutionRequest original = new DefaultMavenExecutionRequest();
@@ -40,13 +43,14 @@ public class DefaultMavenExecutionTest
assertNotSame( copy, original );
}
+ @Test
public void testResultWithNullTopologicallySortedProjectsIsEmptyList()
{
MavenExecutionResult result = new DefaultMavenExecutionResult();
result.setTopologicallySortedProjects( null );
List<MavenProject> projects = result.getTopologicallySortedProjects();
assertNotNull( projects );
- assertTrue( projects.isEmpty() );
+ assertThat( projects, is( empty() ) );
}
}
diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java
index fd1baf7..a321e09 100644
--- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java
+++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java
@@ -15,24 +15,29 @@ package org.apache.maven.lifecycle.internal;
* the License.
*/
-import junit.framework.TestCase;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
+import org.junit.Test;
/**
* @author Kristian Rosenvold
*/
public class ProjectBuildListTest
- extends TestCase
{
-
+ @Test
public void testGetByTaskSegment()
throws Exception
{
final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
ProjectBuildList projectBuildList = ProjectDependencyGraphStub.getProjectBuildList( session );
TaskSegment taskSegment = projectBuildList.get( 0 ).getTaskSegment();
- assertTrue( "This test assumes there are at least 6 elements in projectBuilds", projectBuildList.size() >= 6 );
+ assertThat( "This test assumes there are at least 6 elements in projectBuilds",
+ projectBuildList.size(), is( greaterThanOrEqualTo( 6 ) ) );
final ProjectBuildList byTaskSegment = projectBuildList.getByTaskSegment( taskSegment );
assertEquals( projectBuildList.size(),
diff --git a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
index 71616fa..9f836c2 100644
--- a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
+++ b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
@@ -86,9 +86,7 @@ public abstract class AbstractMavenProjectTestCase
@Override
protected String getCustomConfigurationName()
{
- String name = AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml";
- System.out.println( name );
- return name;
+ return AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml";
}
// ----------------------------------------------------------------------
diff --git a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
index f82800b..008c6d3 100644
--- a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
@@ -18,16 +18,18 @@ package org.apache.maven.project;
* specific language governing permissions and limitations
* under the License.
*/
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.util.FileUtils;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
public class DefaultMavenProjectBuilderTest
extends AbstractMavenProjectTestCase
{
@@ -287,7 +289,7 @@ public class DefaultMavenProjectBuilderTest
catch ( final ProjectBuildingException e )
{
assertNotNull( e.getMessage() );
- assertTrue( e.getMessage().contains( "Version must be a constant" ) );
+ assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
}
}
@@ -310,7 +312,7 @@ public class DefaultMavenProjectBuilderTest
catch ( final ProjectBuildingException e )
{
assertNotNull( e.getMessage() );
- assertTrue( e.getMessage().contains( "Version must be a constant" ) );
+ assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
}
}
@@ -352,7 +354,7 @@ public class DefaultMavenProjectBuilderTest
catch ( final ProjectBuildingException e )
{
assertNotNull( e.getMessage() );
- assertTrue( e.getMessage().contains( "Version must be a constant" ) );
+ assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
}
}
@@ -375,7 +377,7 @@ public class DefaultMavenProjectBuilderTest
catch ( final ProjectBuildingException e )
{
assertNotNull( e.getMessage() );
- assertTrue( e.getMessage().contains( "Version must be a constant" ) );
+ assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
}
}
diff --git a/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java
index 6872701..7a5e55d 100644
--- a/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java
@@ -19,6 +19,10 @@ package org.apache.maven.project;
* under the License.
*/
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@@ -76,9 +80,9 @@ public class ExtensionDescriptorBuilderTest
assertNotNull( ed );
assertNotNull( ed.getExportedPackages() );
- assertTrue( ed.getExportedPackages().isEmpty() );
+ assertThat( ed.getExportedPackages(), is( empty() ) );
assertNotNull( ed.getExportedArtifacts() );
- assertTrue( ed.getExportedArtifacts().isEmpty() );
+ assertThat( ed.getExportedArtifacts(), is( empty() ) );
}
public void testCompleteDescriptor()
diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
index 33b8968..9e16ebc 100644
--- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
@@ -19,6 +19,11 @@ package org.apache.maven.project;
* under the License.
*/
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.lessThan;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertThat;
+
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
@@ -726,8 +731,8 @@ public class PomConstructionTest
assertEquals( "parent", pom.getValue( "properties/parentArtifactId" ) );
assertEquals( "1.0", pom.getValue( "properties/parentVersion" ) );
- assertTrue( pom.getValue( "properties/projectBuildOut" ).toString().endsWith( "bin" ) );
- assertTrue( pom.getValue( "properties/projectSiteOut" ).toString().endsWith( "doc" ) );
+ assertThat( pom.getValue( "properties/projectBuildOut" ).toString(), endsWith( "bin" ) );
+ assertThat( pom.getValue( "properties/projectSiteOut" ).toString(), endsWith( "doc" ) );
}
public void testInterpolationWithBasedirAlignedDirectories()
@@ -936,13 +941,13 @@ public class PomConstructionTest
PomTestWrapper pom = buildPom( "merged-filter-order/sub" );
assertEquals( 7, ( (List<?>) pom.getValue( "build/filters" ) ).size() );
- assertTrue( pom.getValue( "build/filters[1]" ).toString().endsWith( "child-a.properties" ) );
- assertTrue( pom.getValue( "build/filters[2]" ).toString().endsWith( "child-c.properties" ) );
- assertTrue( pom.getValue( "build/filters[3]" ).toString().endsWith( "child-b.properties" ) );
- assertTrue( pom.getValue( "build/filters[4]" ).toString().endsWith( "child-d.properties" ) );
- assertTrue( pom.getValue( "build/filters[5]" ).toString().endsWith( "parent-c.properties" ) );
- assertTrue( pom.getValue( "build/filters[6]" ).toString().endsWith( "parent-b.properties" ) );
- assertTrue( pom.getValue( "build/filters[7]" ).toString().endsWith( "parent-d.properties" ) );
+ assertThat( pom.getValue( "build/filters[1]" ).toString(), endsWith( "child-a.properties" ) );
+ assertThat( pom.getValue( "build/filters[2]" ).toString(), endsWith( "child-c.properties" ) );
+ assertThat( pom.getValue( "build/filters[3]" ).toString(), endsWith( "child-b.properties" ) );
+ assertThat( pom.getValue( "build/filters[4]" ).toString(), endsWith( "child-d.properties" ) );
+ assertThat( pom.getValue( "build/filters[5]" ).toString(), endsWith( "parent-c.properties" ) );
+ assertThat( pom.getValue( "build/filters[6]" ).toString(), endsWith( "parent-b.properties" ) );
+ assertThat( pom.getValue( "build/filters[7]" ).toString(), endsWith( "parent-d.properties" ) );
}
/** MNG-4027*/
@@ -1097,7 +1102,7 @@ public class PomConstructionTest
PomTestWrapper pom = buildPom( "baseuri-interpolation/pom.xml" );
String prop1 = pom.getValue( "properties/prop1" ).toString();
assertEquals( pom.getBasedir().toPath().toUri().toASCIIString(), prop1 );
- assertTrue( prop1.startsWith( "file:///" ) );
+ assertThat( prop1, startsWith( "file:///" ) );
}
/* MNG-3811*/
@@ -1408,8 +1413,8 @@ public class PomConstructionTest
throws Exception
{
PomTestWrapper pom = buildPom( "boolean-interpolation" );
- assertTrue ((Boolean) pom.getValue( "repositories[1]/releases/enabled" ) );
- assertTrue((Boolean) pom.getValue( "build/resources[1]/filtering" ) );
+ assertEquals(true, pom.getValue( "repositories[1]/releases/enabled" ) );
+ assertEquals(true, pom.getValue( "build/resources[1]/filtering" ) );
}
@@ -1734,16 +1739,16 @@ public class PomConstructionTest
Plugin plugin = plugins.get( i );
if ( "maven-resources-plugin".equals( plugin.getArtifactId() ) )
{
- assertTrue( resourcesPlugin < 0 );
+ assertThat( resourcesPlugin, lessThan( 0 ) );
resourcesPlugin = i;
}
else if ( "maven-it-plugin-log-file".equals( plugin.getArtifactId() ) )
{
- assertTrue( customPlugin < 0 );
+ assertThat( customPlugin, lessThan( 0 ) );
customPlugin = i;
}
}
- assertTrue( plugins.toString(), customPlugin == resourcesPlugin - 1 );
+ assertEquals( plugins.toString(), customPlugin, resourcesPlugin - 1 );
}
/** MNG-4415 */
diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
index c9fe27d..4833b00 100644
--- a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
@@ -19,6 +19,12 @@ package org.apache.maven.project;
* under the License.
*/
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@@ -155,7 +161,7 @@ public class ProjectBuilderTest
FileUtils.fileWrite( parent, "UTF-8", parentContent );
// re-build pom with modified parent
ProjectBuildingResult result = projectBuilder.build( child, configuration );
- assertTrue( result.getProject().getProperties().containsKey( "addedProperty" ) );
+ assertThat( result.getProject().getProperties(), hasKey( (Object) "addedProperty" ) );
}
finally
{
@@ -229,7 +235,7 @@ public class ProjectBuilderTest
}
catch ( InvalidArtifactRTException iarte )
{
- assertTrue( iarte.getMessage().contains( "The groupId cannot be empty." ) );
+ assertThat( iarte.getMessage(), containsString( "The groupId cannot be empty." ) );
}
// multi projects build entry point
@@ -301,7 +307,7 @@ public class ProjectBuilderTest
{
for ( ProjectBuildingResult result : results )
{
- assertTrue( result.getProblems().isEmpty() );
+ assertThat( result.getProblems(), is( empty() ) );
assertNotNull( result.getProject() );
}
}
diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java
index 6302a82..fb1c642 100644
--- a/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java
@@ -19,6 +19,9 @@ package org.apache.maven.project;
* under the License.
*/
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertThat;
+
import java.io.File;
import java.util.Collections;
import java.util.List;
@@ -34,12 +37,6 @@ import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.impl.RemoteRepositoryManager;
import org.eclipse.aether.repository.RemoteRepository;
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertNotNull;
-import static junit.framework.TestCase.assertTrue;
-import static junit.framework.TestCase.fail;
-import static org.codehaus.plexus.PlexusTestCase.getBasedir;
-
/**
* Test cases for the project {@code ModelResolver} implementation.
*
@@ -72,7 +69,7 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase
catch ( final UnresolvableModelException e )
{
assertNotNull( e.getMessage() );
- assertTrue( e.getMessage().startsWith( "Could not find artifact org.apache:apache:pom:0 in central" ) );
+ assertThat( e.getMessage(), startsWith( "Could not find artifact org.apache:apache:pom:0 in central" ) );
}
}
@@ -153,7 +150,7 @@ public class ProjectModelResolverTest extends AbstractMavenProjectTestCase
catch ( final UnresolvableModelException e )
{
assertNotNull( e.getMessage() );
- assertTrue( e.getMessage().startsWith( "Could not find artifact org.apache:apache:pom:0 in central" ) );
+ assertThat( e.getMessage(), startsWith( "Could not find artifact org.apache:apache:pom:0 in central" ) );
}
}
diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectSorterTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectSorterTest.java
index c145ee0..cae60cf 100644
--- a/maven-core/src/test/java/org/apache/maven/project/ProjectSorterTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/ProjectSorterTest.java
@@ -19,12 +19,14 @@ package org.apache.maven.project;
* under the License.
*/
+import static org.hamcrest.Matchers.hasItem;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Extension;
@@ -32,7 +34,9 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
-import org.codehaus.plexus.util.dag.CycleDetectedException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
/**
* Test sorting projects by dependencies.
@@ -40,8 +44,9 @@ import org.codehaus.plexus.util.dag.CycleDetectedException;
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class ProjectSorterTest
- extends TestCase
{
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
private Parent createParent( MavenProject project )
{
@@ -104,8 +109,9 @@ public class ProjectSorterTest
return new MavenProject( model );
}
+ @Test
public void testShouldNotFailWhenPluginDepReferencesCurrentProject()
- throws CycleDetectedException, DuplicateProjectException
+ throws Exception
{
MavenProject project = createProject( "group", "artifact", "1.0" );
@@ -122,8 +128,9 @@ public class ProjectSorterTest
new ProjectSorter( Collections.singletonList( project ) );
}
+ @Test
public void testShouldNotFailWhenManagedPluginDepReferencesCurrentProject()
- throws CycleDetectedException, DuplicateProjectException
+ throws Exception
{
MavenProject project = createProject( "group", "artifact", "1.0" );
@@ -144,8 +151,9 @@ public class ProjectSorterTest
new ProjectSorter( Collections.singletonList( project ) );
}
+ @Test
public void testShouldNotFailWhenProjectReferencesNonExistentProject()
- throws CycleDetectedException, DuplicateProjectException
+ throws Exception
{
MavenProject project = createProject( "group", "artifact", "1.0" );
@@ -158,8 +166,9 @@ public class ProjectSorterTest
new ProjectSorter( Collections.singletonList( project ) );
}
+ @Test
public void testMatchingArtifactIdsDifferentGroupIds()
- throws CycleDetectedException, DuplicateProjectException
+ throws Exception
{
List<MavenProject> projects = new ArrayList<>();
MavenProject project1 = createProject( "groupId1", "artifactId", "1.0" );
@@ -174,8 +183,9 @@ public class ProjectSorterTest
assertEquals( project1, projects.get( 1 ) );
}
+ @Test
public void testMatchingGroupIdsDifferentArtifactIds()
- throws CycleDetectedException, DuplicateProjectException
+ throws Exception
{
List<MavenProject> projects = new ArrayList<>();
MavenProject project1 = createProject( "groupId", "artifactId1", "1.0" );
@@ -190,29 +200,25 @@ public class ProjectSorterTest
assertEquals( project1, projects.get( 1 ) );
}
+ @Test
public void testMatchingIdsAndVersions()
- throws CycleDetectedException
+ throws Exception
{
List<MavenProject> projects = new ArrayList<>();
MavenProject project1 = createProject( "groupId", "artifactId", "1.0" );
projects.add( project1 );
MavenProject project2 = createProject( "groupId", "artifactId", "1.0" );
projects.add( project2 );
+
+ expectedException.expect( DuplicateProjectException.class );
+ expectedException.reportMissingExceptionWithMessage( "Duplicate projects should fail" );
- try
- {
- projects = new ProjectSorter( projects ).getSortedProjects();
- fail( "Duplicate projects should fail" );
- }
- catch ( DuplicateProjectException e )
- {
- // expected
- assertTrue( true );
- }
+ new ProjectSorter( projects ).getSortedProjects();
}
+ @Test
public void testMatchingIdsAndDifferentVersions()
- throws CycleDetectedException, DuplicateProjectException
+ throws Exception
{
List<MavenProject> projects = new ArrayList<>();
MavenProject project1 = createProject( "groupId", "artifactId", "1.0" );
@@ -225,6 +231,7 @@ public class ProjectSorterTest
assertEquals( project2, projects.get( 1 ) );
}
+ @Test
public void testPluginDependenciesInfluenceSorting()
throws Exception
{
@@ -261,13 +268,14 @@ public class ProjectSorterTest
assertEquals( parentProject, projects.get( 0 ) );
// the order of these two is non-deterministic, based on when they're added to the reactor.
- assertTrue( projects.contains( pluginProject ) );
- assertTrue( projects.contains( pluginLevelDepProject ) );
+ assertThat( projects, hasItem( pluginProject ) );
+ assertThat( projects, hasItem( pluginLevelDepProject ) );
// the declaring project MUST be listed after the plugin and its plugin-level dep, though.
assertEquals( declaringProject, projects.get( 3 ) );
}
+ @Test
public void testPluginDependenciesInfluenceSorting_DeclarationInParent()
throws Exception
{
@@ -296,15 +304,14 @@ public class ProjectSorterTest
projects = new ProjectSorter( projects ).getSortedProjects();
- System.out.println( projects );
-
assertEquals( parentProject, projects.get( 0 ) );
// the order of these two is non-deterministic, based on when they're added to the reactor.
- assertTrue( projects.contains( pluginProject ) );
- assertTrue( projects.contains( pluginLevelDepProject ) );
+ assertThat( projects, hasItem( pluginProject ) );
+ assertThat( projects, hasItem( pluginLevelDepProject ) );
}
+ @Test
public void testPluginVersionsAreConsidered()
throws Exception
{
@@ -320,10 +327,11 @@ public class ProjectSorterTest
projects = new ProjectSorter( projects ).getSortedProjects();
- assertTrue( projects.contains( pluginProjectA ) );
- assertTrue( projects.contains( pluginProjectB ) );
+ assertThat( projects, hasItem( pluginProjectA ) );
+ assertThat( projects, hasItem( pluginProjectB ) );
}
+ @Test
public void testDependencyPrecedesProjectThatUsesSpecificDependencyVersion()
throws Exception
{
@@ -342,6 +350,7 @@ public class ProjectSorterTest
assertEquals( usingProject, projects.get( 1 ) );
}
+ @Test
public void testDependencyPrecedesProjectThatUsesUnresolvedDependencyVersion()
throws Exception
{
diff --git a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java
index eeb07cf..3b75455 100644
--- a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java
+++ b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java
@@ -19,6 +19,14 @@ package org.apache.maven.toolchain;
* under the License.
*/
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.mockito.Mockito.verify;
+
+import java.io.InputStream;
+import java.util.Collections;
+
import org.apache.maven.toolchain.java.DefaultJavaToolChain;
import org.apache.maven.toolchain.model.PersistedToolchains;
import org.apache.maven.toolchain.model.ToolchainModel;
@@ -29,14 +37,6 @@ import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import java.io.InputStream;
-import java.util.Collections;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.verify;
-
public class DefaultToolchainTest
{
@Mock
@@ -141,10 +141,10 @@ public class DefaultToolchainTest
DefaultToolchain tc1 = new DefaultJavaToolChain( jdks.getToolchains().get( 0 ), null );
DefaultToolchain tc2 = new DefaultJavaToolChain( jdksExtra.getToolchains().get( 0 ), null );
- assertTrue( tc1.equals( tc1 ) );
- assertFalse( tc1.equals( tc2 ) );
- assertFalse( tc2.equals( tc1 ) );
- assertTrue( tc2.equals( tc2 ) );
+ assertEquals( tc1, tc1 );
+ assertNotEquals( tc1, tc2 );
+ assertNotEquals( tc2, tc1 );
+ assertEquals( tc2, tc2 );
}
}
}
diff --git a/pom.xml b/pom.xml
index c1c3125..c7ac485 100644
--- a/pom.xml
+++ b/pom.xml
@@ -424,6 +424,18 @@ under the License.
<artifactId>powermock-reflect</artifactId>
<version>${powermockVersion}</version>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<!--bootstrap-start-comment-->
</dependencyManagement>