Modified: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java?rev=1744879&r1=1744878&r2=1744879&view=diff ============================================================================== --- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java (original) +++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java Sat May 21 09:08:48 2016 @@ -19,6 +19,10 @@ package org.apache.maven.shared.release. * under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.IOException; import java.util.Iterator; @@ -28,6 +32,7 @@ import org.apache.maven.project.MavenPro import org.apache.maven.shared.release.config.ReleaseDescriptor; import org.apache.maven.shared.release.env.DefaultReleaseEnvironment; import org.apache.maven.shared.release.util.ReleaseUtil; +import org.junit.Test; /** * Test the SCM modification check phase. @@ -41,7 +46,7 @@ public class RewritePomsForReleasePhaseT private static final String ALTERNATIVE_NEXT_VERSION = "2.0"; - protected void setUp() + public void setUp() throws Exception { super.setUp(); @@ -61,6 +66,7 @@ public class RewritePomsForReleasePhaseT return ReleaseUtil.readXmlFile( getTestFile( "target/test-classes/projects/rewrite-for-release/" + fileName ) ); } + @Test public void testSimulateRewrite() throws Exception { @@ -80,10 +86,11 @@ public class RewritePomsForReleasePhaseT assertEquals( "Check the transformed POM", expected, actual ); } + @Test public void testRewriteWithDashedComments() throws Exception { - List<MavenProject> reactorProjects = createReactorProjects("basic-pom-with-dashes-in-comment"); + List<MavenProject> reactorProjects = createReactorProjects( "basic-pom-with-dashes-in-comment" ); ReleaseDescriptor config = createDescriptorFromBasicPom( reactorProjects ); config.mapReleaseVersion( "groupId:artifactId", NEXT_VERSION ); @@ -99,6 +106,7 @@ public class RewritePomsForReleasePhaseT assertEquals( "Check the transformed POM", expected, actual ); } + @Test public void testClean() throws Exception { @@ -119,6 +127,7 @@ public class RewritePomsForReleasePhaseT assertFalse( testFile.exists() ); } + @Test public void testCleanNotExists() throws Exception { @@ -135,7 +144,8 @@ public class RewritePomsForReleasePhaseT assertFalse( testFile.exists() ); } - //MRELEASE-116 + // MRELEASE-116 + @Test public void testScmOverridden() throws Exception { @@ -183,6 +193,7 @@ public class RewritePomsForReleasePhaseT // nothing to do } + @Test public void testRewriteBasicPomWithCvs() throws Exception { @@ -196,6 +207,7 @@ public class RewritePomsForReleasePhaseT assertTrue( comparePomFiles( reactorProjects ) ); } + @Test public void testRewriteBasicPomWithScmExpression() throws Exception { @@ -209,6 +221,7 @@ public class RewritePomsForReleasePhaseT assertTrue( comparePomFiles( reactorProjects ) ); } + @Test public void testRewriteBasicPomWithTagBase() throws Exception { @@ -223,6 +236,7 @@ public class RewritePomsForReleasePhaseT assertTrue( comparePomFiles( reactorProjects ) ); } + @Test public void testRewriteBasicPomWithTagBaseAndVaryingScmUrls() throws Exception { @@ -236,6 +250,7 @@ public class RewritePomsForReleasePhaseT assertTrue( comparePomFiles( reactorProjects ) ); } + @Test public void testRewriteBasicPomWithCvsFromTag() throws Exception { @@ -248,6 +263,7 @@ public class RewritePomsForReleasePhaseT assertTrue( comparePomFiles( reactorProjects ) ); } + @Test public void testRewriteBasicPomWithEmptyScm() throws Exception { @@ -260,6 +276,7 @@ public class RewritePomsForReleasePhaseT assertTrue( comparePomFiles( reactorProjects ) ); } + @Test public void testRewriteInterpolatedVersions() throws Exception { @@ -271,6 +288,7 @@ public class RewritePomsForReleasePhaseT assertTrue( comparePomFiles( reactorProjects ) ); } + @Test public void testRewriteInterpolatedVersionsDifferentVersion() throws Exception { @@ -296,6 +314,7 @@ public class RewritePomsForReleasePhaseT } } + @Test public void testRewriteBasicPomWithInheritedScm() throws Exception { @@ -308,6 +327,7 @@ public class RewritePomsForReleasePhaseT assertTrue( comparePomFiles( reactorProjects ) ); } + @Test public void testRewritePomWithParentAndProperties() throws Exception { @@ -324,6 +344,7 @@ public class RewritePomsForReleasePhaseT } // MRELEASE-311 + @Test public void testRewritePomWithDependencyPropertyCoordinate() throws Exception { @@ -340,6 +361,7 @@ public class RewritePomsForReleasePhaseT } // MRELEASE-305 + @Test public void testRewritePomWithScmOfParentEndingWithASlash() throws Exception { @@ -354,6 +376,7 @@ public class RewritePomsForReleasePhaseT assertTrue( comparePomFiles( reactorProjects ) ); } + @Test public void testRewritePomWithDeepSubprojects() throws Exception { @@ -369,10 +392,12 @@ public class RewritePomsForReleasePhaseT assertTrue( comparePomFiles( reactorProjects ) ); } + @Test public void testRewritePomForFlatMultiModule() throws Exception { - List<MavenProject> reactorProjects = createReactorProjects( "rewrite-for-release/pom-with-parent-flat", "/root-project" ); + List<MavenProject> reactorProjects = + createReactorProjects( "rewrite-for-release/pom-with-parent-flat", "/root-project" ); ReleaseDescriptor config = createConfigurationForPomWithParentAlternateNextVersion( reactorProjects ); phase.execute( config, new DefaultReleaseEnvironment(), reactorProjects ); @@ -381,6 +406,7 @@ public class RewritePomsForReleasePhaseT } // MRELEASE-383 + @Test public void testRewritePomWithCDATASectionOnWindows() throws Exception { @@ -402,22 +428,24 @@ public class RewritePomsForReleasePhaseT descriptor.setScmReleaseLabel( "release-label" ); return descriptor; } - + + @Test public void testRewritePomWithExternallyReleasedParent() - throws Exception + throws Exception { List<MavenProject> reactorProjects = createReactorProjects( "pom-with-externally-released-parent" ); - + ReleaseDescriptor config = createDescriptorFromProjects( reactorProjects ); - config.mapResolvedSnapshotDependencies( "external:parent-artifactId", "1" , "2-SNAPSHOT" ); + config.mapResolvedSnapshotDependencies( "external:parent-artifactId", "1", "2-SNAPSHOT" ); config.mapReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); - + phase.execute( config, new DefaultReleaseEnvironment(), reactorProjects ); - + assertTrue( comparePomFiles( reactorProjects ) ); } // MRELEASE-454 + @Test public void testRewritePomWithImportedDependencyManagementInReactor() throws Exception { @@ -429,6 +457,7 @@ public class RewritePomsForReleasePhaseT assertTrue( comparePomFiles( reactorProjects ) ); } + @Test public void testRewritePomWithDifferentVersionsAcrossModules() throws Exception {
Modified: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmBranchPhaseTest.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmBranchPhaseTest.java?rev=1744879&r1=1744878&r2=1744879&view=diff ============================================================================== --- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmBranchPhaseTest.java (original) +++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmBranchPhaseTest.java Sat May 21 09:08:48 2016 @@ -19,6 +19,10 @@ package org.apache.maven.shared.release. * under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isA; @@ -55,6 +59,7 @@ import org.apache.maven.shared.release.s import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException; import org.apache.maven.shared.release.stubs.ScmManagerStub; import org.apache.maven.shared.release.util.ReleaseUtil; +import org.junit.Test; import org.mockito.internal.util.reflection.Whitebox; /** @@ -65,7 +70,7 @@ import org.mockito.internal.util.reflect public class ScmBranchPhaseTest extends AbstractReleaseTestCase { - protected void setUp() + public void setUp() throws Exception { super.setUp(); @@ -73,12 +78,13 @@ public class ScmBranchPhaseTest phase = (ReleasePhase) lookup( ReleasePhase.ROLE, "scm-branch" ); } - public static String getPath(File file) + public static String getPath( File file ) throws IOException { return ReleaseUtil.isSymlink( file ) ? file.getCanonicalPath() : file.getAbsolutePath(); } - + + @Test public void testBranch() throws Exception { @@ -87,20 +93,18 @@ public class ScmBranchPhaseTest List<MavenProject> reactorProjects = createReactorProjects(); descriptor.setScmSourceUrl( "scm-url" ); MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - descriptor.setWorkingDirectory( getPath(rootProject.getFile().getParentFile() ) ); + descriptor.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); descriptor.setScmReleaseLabel( "release-label" ); descriptor.setScmCommentPrefix( "[my prefix] " ); ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.branch( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ). - thenReturn( new BranchScmResult( "...", - Collections.singletonList( new ScmFile( getPath (rootProject - .getFile() ), ScmFileStatus.TAGGED ) ) ) ); + when( scmProviderMock.branch( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + eq( "release-label" ), + argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...", + Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), + ScmFileStatus.TAGGED ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -108,18 +112,19 @@ public class ScmBranchPhaseTest phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); // verify - verify( scmProviderMock ).branch( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); + verify( scmProviderMock ).branch( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + eq( "release-label" ), + argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testCommitMultiModuleDeepFolders() throws Exception { // prepare - List<MavenProject> reactorProjects = createReactorProjects( "scm-commit/", "multimodule-with-deep-subprojects" ); + List<MavenProject> reactorProjects = + createReactorProjects( "scm-commit/", "multimodule-with-deep-subprojects" ); String sourceUrl = "http://svn.example.com/repos/project/trunk/"; String scmUrl = "scm:svn:" + sourceUrl; ReleaseDescriptor descriptor = new ReleaseDescriptor(); @@ -136,12 +141,11 @@ public class ScmBranchPhaseTest scmProviderRepository.setBranchBase( "http://svn.example.com/repos/project/branches/" ); ScmRepository repository = new ScmRepository( "svn", scmProviderRepository ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.branch( eq( repository ), - argThat(new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat(new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ). - thenReturn( new BranchScmResult( "...", Collections.singletonList( new ScmFile( getPath (rootProject - .getFile() ), ScmFileStatus.TAGGED ) ) ) ) ; + when( scmProviderMock.branch( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), + eq( "release-label" ), + argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...", + Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), + ScmFileStatus.TAGGED ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -149,15 +153,15 @@ public class ScmBranchPhaseTest // execute phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); - + // verify - verify( scmProviderMock ).branch( eq( repository ), - argThat(new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat(new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify( scmProviderMock ).branch( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), + eq( "release-label" ), + argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); + verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testCommitForFlatMultiModule() throws Exception { @@ -178,15 +182,11 @@ public class ScmBranchPhaseTest SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( scmUrl ); ScmRepository repository = new ScmRepository( "svn", scmProviderRepository ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.branch( eq( repository ), - argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( - "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( - "...", - Collections.singletonList( new ScmFile( - getPath( rootProject.getFile() ), - ScmFileStatus.TAGGED ) ) ) ); + when( scmProviderMock.branch( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), + eq( "release-label" ), + argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...", + Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), + ScmFileStatus.TAGGED ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -194,15 +194,15 @@ public class ScmBranchPhaseTest // execute phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); - + // verify - verify( scmProviderMock ).branch( eq( repository ), - argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); + verify( scmProviderMock ).branch( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), + eq( "release-label" ), + argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testCommitMultiModule() throws Exception { @@ -211,18 +211,18 @@ public class ScmBranchPhaseTest List<MavenProject> reactorProjects = createReactorProjects( "scm-commit/", "multiple-poms" ); descriptor.setScmSourceUrl( "scm-url" ); MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - descriptor.setWorkingDirectory( getPath (rootProject.getFile().getParentFile() ) ); + descriptor.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); descriptor.setScmReleaseLabel( "release-label" ); descriptor.setScmCommentPrefix( "[my prefix] " ); ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.branch( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...", Collections.singletonList( new ScmFile( getPath( rootProject - .getFile() ), ScmFileStatus.TAGGED ) ) ) ); + when( scmProviderMock.branch( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + eq( "release-label" ), + argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...", + Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), + ScmFileStatus.TAGGED ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -231,13 +231,13 @@ public class ScmBranchPhaseTest phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); // verify - verify( scmProviderMock ).branch( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); + verify( scmProviderMock ).branch( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + eq( "release-label" ), + argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testBranchNoReleaseLabel() throws Exception { @@ -255,6 +255,7 @@ public class ScmBranchPhaseTest } } + @Test public void testSimulateBranch() throws Exception { @@ -262,7 +263,7 @@ public class ScmBranchPhaseTest List<MavenProject> reactorProjects = createReactorProjects(); descriptor.setScmSourceUrl( "scm-url" ); MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - descriptor.setWorkingDirectory( getPath ( rootProject.getFile().getParentFile() ) ); + descriptor.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); descriptor.setScmReleaseLabel( "release-label" ); ScmProvider scmProviderMock = mock( ScmProvider.class ); @@ -278,6 +279,7 @@ public class ScmBranchPhaseTest verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testSimulateBranchNoReleaseLabel() throws Exception { @@ -295,6 +297,7 @@ public class ScmBranchPhaseTest } } + @Test public void testNoSuchScmProviderExceptionThrown() throws Exception { @@ -320,12 +323,13 @@ public class ScmBranchPhaseTest { assertEquals( "check cause", NoSuchScmProviderException.class, e.getCause().getClass() ); } - + // verify verify( scmManagerMock ).makeScmRepository( "scm-url" ); verifyNoMoreInteractions( scmManagerMock ); } + @Test public void testScmRepositoryExceptionThrown() throws Exception { @@ -350,12 +354,13 @@ public class ScmBranchPhaseTest { assertNull( "Check no additional cause", e.getCause() ); } - + // verify verify( scmManagerMock ).makeScmRepository( "scm-url" ); verifyNoMoreInteractions( scmManagerMock ); } + @Test public void testScmExceptionThrown() throws Exception { @@ -364,10 +369,8 @@ public class ScmBranchPhaseTest ReleaseDescriptor releaseDescriptor = createReleaseDescriptor(); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.branch( isA( ScmRepository.class ), - isA( ScmFileSet.class ), - isA( String.class ), - isA( ScmBranchParameters.class ) ) ).thenThrow( new ScmException( "..." ) ); + when( scmProviderMock.branch( isA( ScmRepository.class ), isA( ScmFileSet.class ), isA( String.class ), + isA( ScmBranchParameters.class ) ) ).thenThrow( new ScmException( "..." ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -383,15 +386,14 @@ public class ScmBranchPhaseTest { assertEquals( "check cause", ScmException.class, e.getCause().getClass() ); } - + // verify - verify( scmProviderMock ).branch( isA( ScmRepository.class ), - isA( ScmFileSet.class ), - isA( String.class ), - isA( ScmBranchParameters.class ) ); + verify( scmProviderMock ).branch( isA( ScmRepository.class ), isA( ScmFileSet.class ), isA( String.class ), + isA( ScmBranchParameters.class ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testScmResultFailure() throws Exception { @@ -422,13 +424,13 @@ public class ScmBranchPhaseTest return createReactorProjects( "scm-commit/", "single-pom" ); } - private static ReleaseDescriptor createReleaseDescriptor() + private static ReleaseDescriptor createReleaseDescriptor() throws IOException { ReleaseDescriptor descriptor = new ReleaseDescriptor(); descriptor.setScmSourceUrl( "scm-url" ); descriptor.setScmReleaseLabel( "release-label" ); - descriptor.setWorkingDirectory( getPath(getTestFile( "target/test/checkout" ) ) ); + descriptor.setWorkingDirectory( getPath( getTestFile( "target/test/checkout" ) ) ); return descriptor; } } Modified: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhaseTest.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhaseTest.java?rev=1744879&r1=1744878&r2=1744879&view=diff ============================================================================== --- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhaseTest.java (original) +++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhaseTest.java Sat May 21 09:08:48 2016 @@ -19,7 +19,15 @@ package org.apache.maven.shared.release. * under the License. */ -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; import java.util.Collections; import java.util.List; @@ -37,6 +45,7 @@ import org.apache.maven.scm.repository.S import org.apache.maven.shared.release.config.ReleaseDescriptor; import org.apache.maven.shared.release.env.DefaultReleaseEnvironment; import org.apache.maven.shared.release.util.ReleaseUtil; +import org.junit.Test; /** * Test the SCM development commit phase. @@ -56,10 +65,10 @@ public class ScmCommitDevelopmentPhaseTe private MavenProject rootProject; private ReleaseDescriptor descriptor; - + private ScmProvider scmProviderMock; - protected void setUp() + public void setUp() throws Exception { super.setUp(); @@ -71,11 +80,13 @@ public class ScmCommitDevelopmentPhaseTe descriptor = createReleaseDescriptor( rootProject ); } + @Test public void testIsCorrectImplementation() { assertEquals( ScmCommitDevelopmentPhase.class, phase.getClass() ); } + @Test public void testNoCommitOrRollbackRequired() throws Exception { @@ -93,6 +104,7 @@ public class ScmCommitDevelopmentPhaseTe verifyNoCheckin(); } + @Test public void testCommitsNextVersions() throws Exception { @@ -105,13 +117,14 @@ public class ScmCommitDevelopmentPhaseTe verifyCheckin( COMMIT_MESSAGE ); } + @Test public void testCommitsRollbackPrepare() throws Exception { descriptor.setUpdateWorkingCopyVersions( false ); String message = ROLLBACK_PREFIX + descriptor.getScmReleaseLabel(); - + prepareCheckin( message ); phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); @@ -124,22 +137,21 @@ public class ScmCommitDevelopmentPhaseTe { ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), + when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), isNull( ScmVersion.class ), - eq( message ) ) ).thenReturn( new CheckInScmResult( "...", Collections.singletonList( new ScmFile( rootProject - .getFile().getPath(), ScmFileStatus.CHECKED_IN ) ) ) ); + eq( message ) ) ).thenReturn( new CheckInScmResult( "...", + Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), + ScmFileStatus.CHECKED_IN ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); } - - private void verifyCheckin( String message ) throws Exception + + private void verifyCheckin( String message ) + throws Exception { ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( message ) ); + verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + isNull( ScmVersion.class ), eq( message ) ); verifyNoMoreInteractions( scmProviderMock ); } @@ -150,7 +162,7 @@ public class ScmCommitDevelopmentPhaseTe ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); } - + private void verifyNoCheckin() { verifyNoMoreInteractions( scmProviderMock ); Modified: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitPreparationPhaseTest.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitPreparationPhaseTest.java?rev=1744879&r1=1744878&r2=1744879&view=diff ============================================================================== --- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitPreparationPhaseTest.java (original) +++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitPreparationPhaseTest.java Sat May 21 09:08:48 2016 @@ -19,6 +19,10 @@ package org.apache.maven.shared.release. * under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isA; @@ -56,6 +60,7 @@ import org.apache.maven.shared.release.s import org.apache.maven.shared.release.scm.ReleaseScmCommandException; import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException; import org.apache.maven.shared.release.util.ReleaseUtil; +import org.junit.Test; import org.mockito.internal.util.reflection.Whitebox; /** @@ -68,7 +73,7 @@ public class ScmCommitPreparationPhaseTe { private static final String PREFIX = "[maven-release-manager] prepare release "; - protected void setUp() + public void setUp() throws Exception { super.setUp(); @@ -76,17 +81,20 @@ public class ScmCommitPreparationPhaseTe phase = (ReleasePhase) lookup( ReleasePhase.ROLE, "scm-commit-release" ); } + @Test public void testIsCorrectImplementation() { assertEquals( ScmCommitPreparationPhase.class, phase.getClass() ); } + @Test public void testResolvesCorrectBranchImplementation() throws Exception { assertEquals( ScmCommitPreparationPhase.class, lookup( ReleasePhase.ROLE, "scm-commit-branch" ).getClass() ); } + @Test public void testCommit() throws Exception { @@ -101,12 +109,13 @@ public class ScmCommitPreparationPhaseTe ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), + when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), isNull( ScmVersion.class ), - eq( PREFIX + "release-label" ) ) ).thenReturn( new CheckInScmResult( "...", Collections.singletonList( new ScmFile( rootProject - .getFile().getPath(), ScmFileStatus.CHECKED_IN ) ) ) ); - + eq( PREFIX + + "release-label" ) ) ).thenReturn( new CheckInScmResult( "...", + Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), + ScmFileStatus.CHECKED_IN ) ) ) ); + ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -114,13 +123,12 @@ public class ScmCommitPreparationPhaseTe phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); // verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( PREFIX + "release-label" ) ); + verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + isNull( ScmVersion.class ), eq( PREFIX + "release-label" ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testCommitMultiModule() throws Exception { @@ -138,16 +146,15 @@ public class ScmCommitPreparationPhaseTe MavenProject project = i.next(); poms.add( project.getFile() ); } - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), poms); + ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), poms ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( PREFIX + "release-label" ) ) ).thenReturn( new CheckInScmResult( - "...", - Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), - ScmFileStatus.CHECKED_IN ) ) ) ); + when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + isNull( ScmVersion.class ), + eq( PREFIX + + "release-label" ) ) ).thenReturn( new CheckInScmResult( "...", + Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), + ScmFileStatus.CHECKED_IN ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -155,13 +162,12 @@ public class ScmCommitPreparationPhaseTe phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); // verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( PREFIX + "release-label" ) ); + verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + isNull( ScmVersion.class ), eq( PREFIX + "release-label" ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testCommitDevelopment() throws Exception { @@ -178,11 +184,11 @@ public class ScmCommitPreparationPhaseTe ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( "[maven-release-manager] prepare for next development iteration" ) ) ).thenReturn( new CheckInScmResult( "...", Collections.singletonList( new ScmFile( rootProject - .getFile().getPath(), ScmFileStatus.CHECKED_IN ) ) ) ); + when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + isNull( ScmVersion.class ), + eq( "[maven-release-manager] prepare for next development iteration" ) ) ).thenReturn( new CheckInScmResult( "...", + Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), + ScmFileStatus.CHECKED_IN ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -191,13 +197,13 @@ public class ScmCommitPreparationPhaseTe phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); // verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), + verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + isNull( ScmVersion.class ), eq( "[maven-release-manager] prepare for next development iteration" ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testCommitNoReleaseLabel() throws Exception { @@ -215,6 +221,7 @@ public class ScmCommitPreparationPhaseTe } } + @Test public void testCommitGenerateReleasePoms() throws Exception { @@ -233,11 +240,12 @@ public class ScmCommitPreparationPhaseTe ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), files ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), + when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), isNull( ScmVersion.class ), - eq( PREFIX + "release-label" ) ) ).thenReturn( new CheckInScmResult( "...", Collections.singletonList( new ScmFile( rootProject - .getFile().getPath(), ScmFileStatus.CHECKED_IN ) ) ) ); + eq( PREFIX + + "release-label" ) ) ).thenReturn( new CheckInScmResult( "...", + Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), + ScmFileStatus.CHECKED_IN ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -246,13 +254,12 @@ public class ScmCommitPreparationPhaseTe phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); // verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( PREFIX + "release-label" ) ); + verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + isNull( ScmVersion.class ), eq( PREFIX + "release-label" ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testSimulateCommit() throws Exception { @@ -264,7 +271,7 @@ public class ScmCommitPreparationPhaseTe descriptor.setScmReleaseLabel( "release-label" ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - + ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -274,6 +281,7 @@ public class ScmCommitPreparationPhaseTe verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testSimulateCommitNoReleaseLabel() throws Exception { @@ -291,6 +299,7 @@ public class ScmCommitPreparationPhaseTe } } + @Test public void testNoSuchScmProviderExceptionThrown() throws Exception { @@ -316,12 +325,13 @@ public class ScmCommitPreparationPhaseTe { assertEquals( "check cause", NoSuchScmProviderException.class, e.getCause().getClass() ); } - + // verify verify( scmManagerMock ).makeScmRepository( "scm-url" ); verifyNoMoreInteractions( scmManagerMock ); } + @Test public void testScmRepositoryExceptionThrown() throws Exception { @@ -347,12 +357,13 @@ public class ScmCommitPreparationPhaseTe { assertNull( "Check no additional cause", e.getCause() ); } - + // verify verify( scmManagerMock ).makeScmRepository( "scm-url" ); - verifyNoMoreInteractions( scmManagerMock ); + verifyNoMoreInteractions( scmManagerMock ); } + @Test public void testScmExceptionThrown() throws Exception { @@ -361,9 +372,7 @@ public class ScmCommitPreparationPhaseTe ReleaseDescriptor releaseDescriptor = createReleaseDescriptor(); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), - isA( ScmFileSet.class ), - isNull( ScmVersion.class ), + when( scmProviderMock.checkIn( isA( ScmRepository.class ), isA( ScmFileSet.class ), isNull( ScmVersion.class ), isA( String.class ) ) ).thenThrow( new ScmException( "..." ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); @@ -380,15 +389,14 @@ public class ScmCommitPreparationPhaseTe { assertEquals( "check cause", ScmException.class, e.getCause().getClass() ); } - - //verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), - isA( ScmFileSet.class ), - isNull( ScmVersion.class ), - isA( String.class ) ); + + // verify + verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), isA( ScmFileSet.class ), + isNull( ScmVersion.class ), isA( String.class ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testScmResultFailure() throws Exception { @@ -396,8 +404,8 @@ public class ScmCommitPreparationPhaseTe ReleaseDescriptor releaseDescriptor = createReleaseDescriptor(); ScmManager scmManager = (ScmManager) lookup( ScmManager.ROLE ); - ScmProviderStub providerStub = (ScmProviderStub) scmManager.getProviderByUrl( - releaseDescriptor.getScmSourceUrl() ); + ScmProviderStub providerStub = + (ScmProviderStub) scmManager.getProviderByUrl( releaseDescriptor.getScmSourceUrl() ); providerStub.setCheckInScmResult( new CheckInScmResult( "", "", "", false ) ); @@ -413,6 +421,7 @@ public class ScmCommitPreparationPhaseTe } } + @Test public void testSuppressCommitWithRemoteTaggingFails() throws Exception { @@ -423,7 +432,7 @@ public class ScmCommitPreparationPhaseTe descriptor.setSuppressCommitBeforeTagOrBranch( true ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - + ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -442,6 +451,7 @@ public class ScmCommitPreparationPhaseTe verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testSuppressCommitAfterBranch() throws Exception { @@ -453,7 +463,7 @@ public class ScmCommitPreparationPhaseTe descriptor.setSuppressCommitBeforeTagOrBranch( true ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - + ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); Modified: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmTagPhaseTest.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmTagPhaseTest.java?rev=1744879&r1=1744878&r2=1744879&view=diff ============================================================================== --- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmTagPhaseTest.java (original) +++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmTagPhaseTest.java Sat May 21 09:08:48 2016 @@ -19,6 +19,10 @@ package org.apache.maven.shared.release. * under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isA; @@ -55,6 +59,7 @@ import org.apache.maven.shared.release.s import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException; import org.apache.maven.shared.release.stubs.ScmManagerStub; import org.apache.maven.shared.release.util.ReleaseUtil; +import org.junit.Test; import org.mockito.internal.util.reflection.Whitebox; /** @@ -65,7 +70,7 @@ import org.mockito.internal.util.reflect public class ScmTagPhaseTest extends AbstractReleaseTestCase { - protected void setUp() + public void setUp() throws Exception { super.setUp(); @@ -73,12 +78,13 @@ public class ScmTagPhaseTest phase = (ReleasePhase) lookup( ReleasePhase.ROLE, "scm-tag" ); } - public static String getPath(File file) + public static String getPath( File file ) throws IOException { return ReleaseUtil.isSymlink( file ) ? file.getCanonicalPath() : file.getAbsolutePath(); } - + + @Test public void testTag() throws Exception { @@ -87,20 +93,18 @@ public class ScmTagPhaseTest List<MavenProject> reactorProjects = createReactorProjects(); descriptor.setScmSourceUrl( "scm-url" ); MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - descriptor.setWorkingDirectory( getPath(rootProject.getFile().getParentFile() ) ); + descriptor.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); descriptor.setScmReleaseLabel( "release-label" ); descriptor.setScmCommentPrefix( "[my prefix] " ); ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.tag( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ) ). - thenReturn( new TagScmResult( "...", - Collections.singletonList( new ScmFile( getPath (rootProject - .getFile() ), ScmFileStatus.TAGGED ) ) ) ); + when( scmProviderMock.tag( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + eq( "release-label" ), + argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ) ).thenReturn( new TagScmResult( "...", + Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), + ScmFileStatus.TAGGED ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -108,18 +112,19 @@ public class ScmTagPhaseTest phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); // verify - verify( scmProviderMock ).tag( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), + verify( scmProviderMock ).tag( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), + eq( "release-label" ), argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testCommitMultiModuleDeepFolders() throws Exception { // prepare - List<MavenProject> reactorProjects = createReactorProjects( "scm-commit/", "multimodule-with-deep-subprojects" ); + List<MavenProject> reactorProjects = + createReactorProjects( "scm-commit/", "multimodule-with-deep-subprojects" ); String sourceUrl = "http://svn.example.com/repos/project/trunk/"; String scmUrl = "scm:svn:" + sourceUrl; ReleaseDescriptor descriptor = new ReleaseDescriptor(); @@ -136,12 +141,11 @@ public class ScmTagPhaseTest scmProviderRepository.setTagBase( "http://svn.example.com/repos/project/releases/" ); ScmRepository repository = new ScmRepository( "svn", scmProviderRepository ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.tag( eq( repository ), - argThat(new IsScmFileSetEquals( fileSet ) ), + when( scmProviderMock.tag( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), eq( "release-label" ), - argThat(new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ) ). - thenReturn( new TagScmResult( "...", Collections.singletonList( new ScmFile( getPath (rootProject - .getFile() ), ScmFileStatus.TAGGED ) ) ) ) ; + argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ) ).thenReturn( new TagScmResult( "...", + Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), + ScmFileStatus.TAGGED ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -149,15 +153,15 @@ public class ScmTagPhaseTest // execute phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); - + // verify - verify( scmProviderMock ).tag( eq( repository ), - argThat(new IsScmFileSetEquals( fileSet ) ), + verify( scmProviderMock ).tag( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), eq( "release-label" ), - argThat(new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ); + verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testCommitForFlatMultiModule() throws Exception { @@ -178,15 +182,11 @@ public class ScmTagPhaseTest SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( scmUrl ); ScmRepository repository = new ScmRepository( "svn", scmProviderRepository ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.tag( eq( repository ), - argThat( new IsScmFileSetEquals( fileSet ) ), + when( scmProviderMock.tag( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), eq( "release-label" ), - argThat( new IsScmTagParametersEquals( new ScmTagParameters( - "[my prefix] copy for tag release-label" ) ) ) ) ).thenReturn( new TagScmResult( - "...", - Collections.singletonList( new ScmFile( - getPath( rootProject.getFile() ), - ScmFileStatus.TAGGED ) ) ) ); + argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ) ).thenReturn( new TagScmResult( "...", + Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), + ScmFileStatus.TAGGED ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -194,15 +194,15 @@ public class ScmTagPhaseTest // execute phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); - + // verify - verify( scmProviderMock ).tag( eq( repository ), - argThat( new IsScmFileSetEquals( fileSet ) ), + verify( scmProviderMock ).tag( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), eq( "release-label" ), argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testCommitMultiModule() throws Exception { @@ -211,18 +211,18 @@ public class ScmTagPhaseTest List<MavenProject> reactorProjects = createReactorProjects( "scm-commit/", "multiple-poms" ); descriptor.setScmSourceUrl( "scm-url" ); MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - descriptor.setWorkingDirectory( getPath (rootProject.getFile().getParentFile() ) ); + descriptor.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); descriptor.setScmReleaseLabel( "release-label" ); descriptor.setScmCommentPrefix( "[my prefix] " ); ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.tag( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), + when( scmProviderMock.tag( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), eq( "release-label" ), - argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ) ).thenReturn( new TagScmResult( "...", Collections.singletonList( new ScmFile( getPath( rootProject - .getFile() ), ScmFileStatus.TAGGED ) ) ) ); + argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ) ).thenReturn( new TagScmResult( "...", + Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), + ScmFileStatus.TAGGED ) ) ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); stub.setScmProvider( scmProviderMock ); @@ -231,13 +231,13 @@ public class ScmTagPhaseTest phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects ); // verify - verify( scmProviderMock ).tag( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), + verify( scmProviderMock ).tag( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), eq( "release-label" ), argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testTagNoReleaseLabel() throws Exception { @@ -255,6 +255,7 @@ public class ScmTagPhaseTest } } + @Test public void testSimulateTag() throws Exception { @@ -262,7 +263,7 @@ public class ScmTagPhaseTest List<MavenProject> reactorProjects = createReactorProjects(); descriptor.setScmSourceUrl( "scm-url" ); MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - descriptor.setWorkingDirectory( getPath ( rootProject.getFile().getParentFile() ) ); + descriptor.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); descriptor.setScmReleaseLabel( "release-label" ); ScmProvider scmProviderMock = mock( ScmProvider.class ); @@ -278,6 +279,7 @@ public class ScmTagPhaseTest verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testSimulateTagNoReleaseLabel() throws Exception { @@ -295,6 +297,7 @@ public class ScmTagPhaseTest } } + @Test public void testNoSuchScmProviderExceptionThrown() throws Exception { @@ -320,12 +323,13 @@ public class ScmTagPhaseTest { assertEquals( "check cause", NoSuchScmProviderException.class, e.getCause().getClass() ); } - + // verify verify( scmManagerMock ).makeScmRepository( "scm-url" ); verifyNoMoreInteractions( scmManagerMock ); } + @Test public void testScmRepositoryExceptionThrown() throws Exception { @@ -350,12 +354,13 @@ public class ScmTagPhaseTest { assertNull( "Check no additional cause", e.getCause() ); } - + // verify verify( scmManagerMock ).makeScmRepository( "scm-url" ); verifyNoMoreInteractions( scmManagerMock ); } + @Test public void testScmExceptionThrown() throws Exception { @@ -364,9 +369,7 @@ public class ScmTagPhaseTest ReleaseDescriptor releaseDescriptor = createReleaseDescriptor(); ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.tag( isA( ScmRepository.class ), - isA( ScmFileSet.class ), - isA( String.class ), + when( scmProviderMock.tag( isA( ScmRepository.class ), isA( ScmFileSet.class ), isA( String.class ), isA( ScmTagParameters.class ) ) ).thenThrow( new ScmException( "..." ) ); ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE ); @@ -383,15 +386,14 @@ public class ScmTagPhaseTest { assertEquals( "check cause", ScmException.class, e.getCause().getClass() ); } - + // verify - verify( scmProviderMock ).tag( isA( ScmRepository.class ), - isA( ScmFileSet.class ), - isA( String.class ), + verify( scmProviderMock ).tag( isA( ScmRepository.class ), isA( ScmFileSet.class ), isA( String.class ), isA( ScmTagParameters.class ) ); verifyNoMoreInteractions( scmProviderMock ); } + @Test public void testScmResultFailure() throws Exception { @@ -422,13 +424,13 @@ public class ScmTagPhaseTest return createReactorProjects( "scm-commit/", "single-pom" ); } - private static ReleaseDescriptor createReleaseDescriptor() + private static ReleaseDescriptor createReleaseDescriptor() throws IOException { ReleaseDescriptor descriptor = new ReleaseDescriptor(); descriptor.setScmSourceUrl( "scm-url" ); descriptor.setScmReleaseLabel( "release-label" ); - descriptor.setWorkingDirectory( getPath(getTestFile( "target/test/checkout" ) ) ); + descriptor.setWorkingDirectory( getPath( getTestFile( "target/test/checkout" ) ) ); return descriptor; } }
