maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1292042 - /maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScmTest.java
Date Tue, 21 Feb 2012 21:36:03 GMT
Author: rfscholte
Date: Tue Feb 21 21:36:02 2012
New Revision: 1292042

URL: http://svn.apache.org/viewvc?rev=1292042&view=rev
Log:
MRELEASE-741: migrate to mockito
 

Modified:
    maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScmTest.java

Modified: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScmTest.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScmTest.java?rev=1292042&r1=1292041&r2=1292042&view=diff
==============================================================================
--- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScmTest.java
(original)
+++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScmTest.java
Tue Feb 21 21:36:02 2012
@@ -19,6 +19,13 @@ package org.apache.maven.shared.release.
  * under the License.
  */
 
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+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.io.File;
 import java.util.List;
 
@@ -33,11 +40,6 @@ 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.stubs.ScmManagerStub;
-import org.jmock.Mock;
-import org.jmock.core.Constraint;
-import org.jmock.core.constraint.IsEqual;
-import org.jmock.core.matcher.InvokeOnceMatcher;
-import org.jmock.core.stub.ReturnStub;
 
 /**
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
@@ -58,6 +60,7 @@ public class CheckoutProjectFromScmTest
     public void testExecuteStandard()
         throws Exception
     {
+        // prepare
         ReleaseDescriptor descriptor = new ReleaseDescriptor();
         File checkoutDirectory = getTestFile( "target/checkout-test/standard" );
         descriptor.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() );
@@ -66,28 +69,35 @@ public class CheckoutProjectFromScmTest
         String scmUrl = "scm:svn:" + sourceUrl;
         descriptor.setScmSourceUrl( scmUrl );
 
-        Mock scmProviderMock = new Mock( ScmProvider.class );
+        ScmProvider scmProviderMock = mock( ScmProvider.class );
         SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( sourceUrl
);
         ScmRepository repository = new ScmRepository( "svn", scmProviderRepository );
-        Constraint[] arguments =
-            new Constraint[]{new IsEqual( repository ), new IsScmFileSetEquals( new ScmFileSet(
checkoutDirectory ) ),
-                new IsScmTagEquals( new ScmTag( "release-label" ) )};
-        scmProviderMock.expects( new InvokeOnceMatcher() ).method( "checkOut" ).with( arguments
).will(
-            new ReturnStub( new CheckOutScmResult( "", null ) ) );
+        when( scmProviderMock.checkOut( eq( repository), 
+                                        argThat( new IsScmFileSetEquals( new ScmFileSet(
checkoutDirectory ) ) ), 
+                                        argThat( new IsScmTagEquals( new ScmTag( "release-label"
) ) ) ) ).thenReturn( new CheckOutScmResult( "", null ) );
 
         ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE );
-        stub.setScmProvider( (ScmProvider) scmProviderMock.proxy() );
+        stub.setScmProvider( scmProviderMock );
         stub.addScmRepositoryForUrl( scmUrl, repository );
 
         List<MavenProject> reactorProjects = createReactorProjects( "scm-commit", "/single-pom"
);
+        
+        // execute
         phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects );
 
+        // prepare
         assertEquals( "", descriptor.getScmRelativePathProjectDirectory() );
+        
+        verify( scmProviderMock ).checkOut( eq( repository), 
+                                            argThat( new IsScmFileSetEquals( new ScmFileSet(
checkoutDirectory ) ) ), 
+                                            argThat( new IsScmTagEquals( new ScmTag( "release-label"
) ) ) );
+        verifyNoMoreInteractions( scmProviderMock );
     }
 
     public void testExecuteMultiModuleWithDeepSubprojects()
         throws Exception
     {
+        // prepare
         ReleaseDescriptor descriptor = new ReleaseDescriptor();
         File checkoutDirectory = getTestFile( "target/checkout-test/multimodule-with-deep-subprojects"
);
         descriptor.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() );
@@ -96,28 +106,35 @@ public class CheckoutProjectFromScmTest
         String scmUrl = "scm:svn:" + sourceUrl;
         descriptor.setScmSourceUrl( scmUrl );
 
-        Mock scmProviderMock = new Mock( ScmProvider.class );
+        ScmProvider scmProviderMock = mock( ScmProvider.class );
         SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( sourceUrl
);
         ScmRepository repository = new ScmRepository( "svn", scmProviderRepository );
-        Constraint[] arguments =
-            new Constraint[]{new IsEqual( repository ), new IsScmFileSetEquals( new ScmFileSet(
checkoutDirectory ) ),
-                new IsScmTagEquals( new ScmTag( "release-label" ) )};
-        scmProviderMock.expects( new InvokeOnceMatcher() ).method( "checkOut" ).with( arguments
).will(
-            new ReturnStub( new CheckOutScmResult( "", null ) ) );
+        when( scmProviderMock.checkOut( eq( repository ), 
+                                        argThat( new IsScmFileSetEquals( new ScmFileSet(
checkoutDirectory ) ) ),
+                                        argThat( new IsScmTagEquals( new ScmTag( "release-label"
) ) ) ) ).thenReturn( new CheckOutScmResult( "", null ) );
 
         ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE );
-        stub.setScmProvider( (ScmProvider) scmProviderMock.proxy() );
+        stub.setScmProvider( scmProviderMock );
         stub.addScmRepositoryForUrl( scmUrl, repository );
 
         List<MavenProject> reactorProjects = createReactorProjects( "scm-commit", "/multimodule-with-deep-subprojects"
);
+        
+        // execute
         phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects );
 
+        // verify
         assertEquals( "", descriptor.getScmRelativePathProjectDirectory() );
+        
+        verify( scmProviderMock ).checkOut( eq( repository ), 
+                                            argThat( new IsScmFileSetEquals( new ScmFileSet(
checkoutDirectory ) ) ),
+                                            argThat( new IsScmTagEquals( new ScmTag( "release-label"
) ) ) );
+        verifyNoMoreInteractions( scmProviderMock );
     }
 
     public void testExecuteFlatMultiModule()
         throws Exception
     {
+        // prepare
         ReleaseDescriptor descriptor = new ReleaseDescriptor();
         File checkoutDirectory = getTestFile( "target/checkout-test/flat-multi-module" );
         descriptor.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() );
@@ -126,24 +143,30 @@ public class CheckoutProjectFromScmTest
         String scmUrl = "scm:svn:" + sourceUrl;
         descriptor.setScmSourceUrl( scmUrl );
 
-        Mock scmProviderMock = new Mock( ScmProvider.class );
+        ScmProvider scmProviderMock = mock( ScmProvider.class );
         SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( sourceUrl
);
         ScmRepository repository = new ScmRepository( "svn", scmProviderRepository );
-        Constraint[] arguments =
-            new Constraint[]{new IsEqual( repository ), new IsScmFileSetEquals( new ScmFileSet(
checkoutDirectory ) ),
-                new IsScmTagEquals( new ScmTag( "release-label" ) )};
-        scmProviderMock.expects( new InvokeOnceMatcher() ).method( "checkOut" ).with( arguments
).will(
-            new ReturnStub( new CheckOutScmResult( "", null ) ) );
+        when( scmProviderMock.checkOut( eq( repository ), 
+                                        argThat( new IsScmFileSetEquals( new ScmFileSet(
checkoutDirectory ) ) ),
+                                        argThat( new IsScmTagEquals( new ScmTag( "release-label"
) ) ) ) ).thenReturn( new CheckOutScmResult( "", null ) );
 
         ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE );
-        stub.setScmProvider( (ScmProvider) scmProviderMock.proxy() );
+        stub.setScmProvider( scmProviderMock );
         stub.addScmRepositoryForUrl( scmUrl, repository );
 
         List<MavenProject> reactorProjects = createReactorProjects( "rewrite-for-release/pom-with-parent-flat",
"/root-project" );
+        
+        // execute
         phase.execute( descriptor, new DefaultReleaseEnvironment(), reactorProjects );
 
+        // verify
         assertEquals( "not found root-project but " + descriptor.getScmRelativePathProjectDirectory(),
"root-project",
                       descriptor.getScmRelativePathProjectDirectory() );
+        
+        verify( scmProviderMock ).checkOut( eq( repository ), 
+                                            argThat( new IsScmFileSetEquals( new ScmFileSet(
checkoutDirectory ) ) ),
+                                            argThat( new IsScmTagEquals( new ScmTag( "release-label"
) ) ) );
+        verifyNoMoreInteractions( scmProviderMock );
     }
 
 }
\ No newline at end of file



Mime
View raw message