From 3f3d775edee00f81ee5e66511c4bec6118e7cf4d Mon Sep 17 00:00:00 2001 From: rfscholte Date: Sun, 13 Oct 2019 15:33:42 +0200 Subject: [PATCH] Rewrite assertTrue to assertThat to get more meaningful messages --- maven-core/pom.xml | 5 ++ .../ProjectDependenciesResolverTest.java | 5 +- .../execution/DefaultMavenExecutionTest.java | 16 +++-- .../internal/ProjectBuildListTest.java | 13 ++-- .../project/AbstractMavenProjectTestCase.java | 4 +- .../DefaultMavenProjectBuilderTest.java | 18 ++--- .../ExtensionDescriptorBuilderTest.java | 8 ++- .../maven/project/PomConstructionTest.java | 35 +++++----- .../maven/project/ProjectBuilderTest.java | 12 +++- .../project/ProjectModelResolverTest.java | 13 ++-- .../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 1c47046725..73c53c4e98 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -136,6 +136,11 @@ under the License. mockito-core test + + org.hamcrest + hamcrest-library + test + 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 ca75c3f115..0bc2978a66 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 @@ * 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 void testSystemScopeDependencyIsPresentInTheCompileClasspathElements() @SuppressWarnings( "deprecation" ) List 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 fbb8b9003a..237362e451 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 @@ * 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 void testCopyDefault() assertNotSame( copy, original ); } + @Test public void testResultWithNullTopologicallySortedProjectsIsEmptyList() { MavenExecutionResult result = new DefaultMavenExecutionResult(); result.setTopologicallySortedProjects( null ); List 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 fd1baf79f6..a321e09078 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 @@ * 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 71616fa63f..9f836c28e6 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 @@ protected ProjectBuilder getProjectBuilder() @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 f82800bd4d..008c6d3bdc 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 @@ * 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 void testBuildParentVersionRangeLocallyWithoutChildVersion() throws Excep 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 void testBuildParentVersionRangeLocallyWithChildVersionExpression() throw 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 void testBuildParentVersionRangeExternallyWithoutChildVersion() throws Ex 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 void testBuildParentVersionRangeExternallyWithChildVersionExpression() th 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 68727013a6..7a5e55d1eb 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 @@ * 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 void testEmptyDescriptor() 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 33b8968cc6..9e16ebc594 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 @@ * 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 void testInterpolationOfLegacyExpressionsThatDontIncludeTheProjectPrefix( 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 void testMergedFilterOrder() 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 void testInterpolationOfRfc3986BaseUri() 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 void testBooleanInterpolation() 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 void testPluginDeclarationsRetainPomOrderAfterInjectionOfDefaultPlugins() 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 c9fe27d13f..4833b00351 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 @@ * 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 void testReadModifiedPoms() throws Exception { 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 void testReadInvalidPom() } 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 @@ private void assertResultShowNoError(List results) { 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 6302a82a99..fb1c642382 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 @@ * 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.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 void testResolveParentThrowsUnresolvableModelExceptionWhenNotFound() thro 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 void testResolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() 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 c145ee00bb..cae60cf393 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 @@ * 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.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 @@ * @author Brett Porter */ public class ProjectSorterTest - extends TestCase { + @Rule + public ExpectedException expectedException = ExpectedException.none(); private Parent createParent( MavenProject project ) { @@ -104,8 +109,9 @@ private static MavenProject createProject( String groupId, String artifactId, St 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 void testShouldNotFailWhenPluginDepReferencesCurrentProject() 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 void testShouldNotFailWhenManagedPluginDepReferencesCurrentProject() 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 void testShouldNotFailWhenProjectReferencesNonExistentProject() new ProjectSorter( Collections.singletonList( project ) ); } + @Test public void testMatchingArtifactIdsDifferentGroupIds() - throws CycleDetectedException, DuplicateProjectException + throws Exception { List projects = new ArrayList<>(); MavenProject project1 = createProject( "groupId1", "artifactId", "1.0" ); @@ -174,8 +183,9 @@ public void testMatchingArtifactIdsDifferentGroupIds() assertEquals( project1, projects.get( 1 ) ); } + @Test public void testMatchingGroupIdsDifferentArtifactIds() - throws CycleDetectedException, DuplicateProjectException + throws Exception { List projects = new ArrayList<>(); MavenProject project1 = createProject( "groupId", "artifactId1", "1.0" ); @@ -190,29 +200,25 @@ public void testMatchingGroupIdsDifferentArtifactIds() assertEquals( project1, projects.get( 1 ) ); } + @Test public void testMatchingIdsAndVersions() - throws CycleDetectedException + throws Exception { List 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 projects = new ArrayList<>(); MavenProject project1 = createProject( "groupId", "artifactId", "1.0" ); @@ -225,6 +231,7 @@ public void testMatchingIdsAndDifferentVersions() assertEquals( project2, projects.get( 1 ) ); } + @Test public void testPluginDependenciesInfluenceSorting() throws Exception { @@ -261,13 +268,14 @@ public void testPluginDependenciesInfluenceSorting() 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 void testPluginDependenciesInfluenceSorting_DeclarationInParent() 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 void testPluginVersionsAreConsidered() 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 void testDependencyPrecedesProjectThatUsesSpecificDependencyVersion() 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 eeb07cfcac..3b75455851 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 @@ * 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.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 void testEquals() 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 c1c31252df..c7ac485bbb 100644 --- a/pom.xml +++ b/pom.xml @@ -424,6 +424,18 @@ under the License. powermock-reflect ${powermockVersion} + + org.hamcrest + hamcrest-core + 1.3 + test + + + org.hamcrest + hamcrest-library + 1.3 + test +