continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From batkin...@apache.org
Subject svn commit: r1659088 - /continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/ContinuumBuildExecutorTest.java
Date Wed, 11 Feb 2015 21:27:51 GMT
Author: batkinson
Date: Wed Feb 11 21:27:51 2015
New Revision: 1659088

URL: http://svn.apache.org/r1659088
Log:
Converted continuum-core test to mockito.

Modified:
    continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/ContinuumBuildExecutorTest.java

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/ContinuumBuildExecutorTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/ContinuumBuildExecutorTest.java?rev=1659088&r1=1659087&r2=1659088&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/ContinuumBuildExecutorTest.java
(original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/execution/ContinuumBuildExecutorTest.java
Wed Feb 11 21:27:51 2015
@@ -28,8 +28,6 @@ import org.apache.maven.continuum.model.
 import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.continuum.model.scm.ScmResult;
 import org.apache.maven.continuum.utils.ChrootJailWorkingDirectoryService;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
 import org.junit.Test;
 
 import java.io.File;
@@ -38,12 +36,11 @@ import java.util.List;
 import java.util.Map;
 
 import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
 
 public class ContinuumBuildExecutorTest
 {
-    protected final AbstractBuildExecutor executor = new BuildExecutorStub();
-
-    private final Mockery context = new Mockery();
+    protected AbstractBuildExecutor executor = new BuildExecutorStub();
 
     private String toSystemPath( String path )
     {
@@ -59,19 +56,11 @@ public class ContinuumBuildExecutorTest
     public void testExecuteShellCommand()
         throws Exception
     {
-        final File chrootJailFile = new File( toSystemPath( "/home" ) );
-        final File workingDirectory = new File( toSystemPath( "/dir1/dir2/workingdir" ) );
-
-        final ShellCommandHelper helper = context.mock( ShellCommandHelper.class );
-
-        ConfigurationService configurationService = new DefaultConfigurationService()
-        {
-            @Override
-            public File getWorkingDirectory()
-            {
-                return workingDirectory;
-            }
-        };
+        File chrootJailFile = new File( toSystemPath( "/home" ) );
+        File workingDirectory = new File( toSystemPath( "/dir1/dir2/workingdir" ) );
+        ShellCommandHelper helper = mock( ShellCommandHelper.class );
+        ConfigurationService configurationService = mock( DefaultConfigurationService.class
);
+        when( configurationService.getWorkingDirectory() ).thenReturn( workingDirectory );
 
         ChrootJailWorkingDirectoryService directoryService = new ChrootJailWorkingDirectoryService();
         directoryService.setConfigurationService( configurationService );
@@ -82,7 +71,7 @@ public class ContinuumBuildExecutorTest
         executor.setWorkingDirectoryService( directoryService );
         //executor.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "" ) );
 
-        final Project project = new Project();
+        Project project = new Project();
         project.setId( 7 );
         project.setGroupId( "xx" );
         ProjectGroup projectGroup = new ProjectGroup();
@@ -94,28 +83,26 @@ public class ContinuumBuildExecutorTest
                 project.getId() ), directoryService.getWorkingDirectory( project ).getPath()
);
 
         String executable = "mvn";
-        final String arguments = "-o clean install";
-        final File output = new File( "target/tmp" );
-        final Map<String, String> environments = new HashMap<String, String>();
+        String arguments = "-o clean install";
+        File output = new File( "target/tmp" );
+        Map<String, String> environments = new HashMap<String, String>();
 
-        final String cmd =
+        String cmd =
             "chroot /home/xx " + " /bin/sh -c 'cd /dir1/dir2/workingdir/" + project.getId()
+ " && " + executable +
                 " " + arguments + "'";
 
-        final ExecutionResult result = new ExecutionResult( 0 );
-
-        context.checking( new Expectations()
-        {
-            {
-                one( helper ).executeShellCommand( chrootJailFile, "sudo", toSystemPath(
cmd ), output, project.getId(),
-                                                   environments );
-                will( returnValue( result ) );
-            }
-        } );
+        ExecutionResult expectedResult = new ExecutionResult( 0 );
 
-        executor.executeShellCommand( project, executable, arguments, output, environments,
null, null );
+        when( helper.executeShellCommand( chrootJailFile, "sudo", toSystemPath( cmd ), output,
project.getId(),
+                                          environments ) ).thenReturn( expectedResult );
 
-        context.assertIsSatisfied();
+        ContinuumBuildExecutionResult result =
+            executor.executeShellCommand( project, executable, arguments, output, environments,
+                                          null, null );
+
+        assertEquals( 0, result.getExitCode() );
+        verify( helper ).executeShellCommand( chrootJailFile, "sudo", toSystemPath( cmd ),
output, project.getId(),
+                                              environments );
     }
 
     class BuildExecutorStub



Mime
View raw message