continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From batkin...@apache.org
Subject svn commit: r1659082 - /continuum/trunk/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java
Date Wed, 11 Feb 2015 21:27:27 GMT
Author: batkinson
Date: Wed Feb 11 21:27:26 2015
New Revision: 1659082

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

Modified:
    continuum/trunk/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java?rev=1659082&r1=1659081&r2=1659082&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java (original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java Wed Feb 11 21:27:26 2015
@@ -39,10 +39,6 @@ import org.codehaus.plexus.taskqueue.Tas
 import org.codehaus.plexus.taskqueue.TaskQueue;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
 import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit3.JUnit3Mockery;
-import org.jmock.lib.legacy.ClassImposteriser;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -51,6 +47,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static org.mockito.Mockito.*;
+
 /**
  * ParallelBuildsManagerTest
  *
@@ -61,8 +59,6 @@ public class ParallelBuildsManagerTest
 {
     private ParallelBuildsManager buildsManager;
 
-    private Mockery context;
-
     private BuildDefinitionDao buildDefinitionDao;
 
     private ProjectDao projectDao;
@@ -93,36 +89,21 @@ public class ParallelBuildsManagerTest
 
         buildsManager = (ParallelBuildsManager) lookup( BuildsManager.class, "parallel" );
 
-        context = new JUnit3Mockery();
-        context.setImposteriser( ClassImposteriser.INSTANCE );
-
-        buildDefinitionDao = context.mock( BuildDefinitionDao.class );
+        buildDefinitionDao = mock( BuildDefinitionDao.class );
+        configurationService = mock( ConfigurationService.class );
+        prepareBuildTaskQueueExecutor = mock( TaskQueueExecutor.class, "prepare-build-task-queue" );
+        buildQueue = mock( TaskQueue.class, "build-queue" );
+        checkoutQueue = mock( TaskQueue.class, "checkout-queue" );
+        prepareBuildQueue = mock( TaskQueue.class, "prepare-build-queue" );
+        projectDao = mock( ProjectDao.class );
+        buildTaskQueueExecutor = mock( TaskQueueExecutor.class, "build-task-queue" );
+        checkoutTaskQueueExecutor = mock( TaskQueueExecutor.class, "checkout-task-queue" );
+        BuildQueueService buildQueueService = mock( BuildQueueService.class );
 
         buildsManager.setBuildDefinitionDao( buildDefinitionDao );
-
-        configurationService = context.mock( ConfigurationService.class );
-
         buildsManager.setConfigurationService( configurationService );
-
-        BuildQueueService buildQueueService = context.mock( BuildQueueService.class );
-
         buildsManager.setBuildQueueService( buildQueueService );
-
-        buildQueue = context.mock( TaskQueue.class, "build-queue" );
-
-        checkoutQueue = context.mock( TaskQueue.class, "checkout-queue" );
-
-        prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" );
-
-        projectDao = context.mock( ProjectDao.class );
-
         buildsManager.setProjectDao( projectDao );
-
-        buildTaskQueueExecutor = context.mock( TaskQueueExecutor.class, "build-task-queue" );
-
-        checkoutTaskQueueExecutor = context.mock( TaskQueueExecutor.class, "checkout-task-queue" );
-
-        prepareBuildTaskQueueExecutor = context.mock( TaskQueueExecutor.class, "prepare-build-task-queue" );
     }
 
     @Override
@@ -130,7 +111,6 @@ public class ParallelBuildsManagerTest
         throws Exception
     {
         super.tearDown();
-
         buildsManager = null;
     }
 
@@ -173,7 +153,7 @@ public class ParallelBuildsManagerTest
     {
         Map<Integer, OverallBuildQueue> overallBuildQueues = Collections.synchronizedMap(
             new HashMap<Integer, OverallBuildQueue>() );
-        overallBuildQueue = context.mock( OverallBuildQueue.class );
+        overallBuildQueue = mock( OverallBuildQueue.class );
         for ( int i = 1; i <= 5; i++ )
         {
             overallBuildQueues.put( i, overallBuildQueue );
@@ -183,187 +163,64 @@ public class ParallelBuildsManagerTest
     }
 
     // build project recordings
-    private void recordStartOfBuildProjectSequence()
+    private void setupStartOfBuildProjectSequence()
         throws TaskQueueException, ContinuumStoreException
     {
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 5 ).of( overallBuildQueue ).isInBuildQueue( with( any( int.class ) ) );
-                will( returnValue( false ) );
-
-                exactly( 5 ).of( buildTaskQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( projectDao ).getProjectsInGroup( with( any( int.class ) ) );
-                will( returnValue( projects ) );
-
-                one( configurationService ).getNumberOfBuildsInParallel();
-                will( returnValue( 2 ) );
-
-                exactly( 2 ).of( overallBuildQueue ).getBuildQueue();
-                will( returnValue( buildQueue ) );
-
-                exactly( 7 ).of( overallBuildQueue ).getBuildTaskQueueExecutor();
-                will( returnValue( buildTaskQueueExecutor ) );
-            }
-        } );
+        when( overallBuildQueue.isInBuildQueue( anyInt() ) ).thenReturn( false );
+        when( buildTaskQueueExecutor.getCurrentTask() ).thenReturn( null );
+        when( projectDao.getProjectsInGroup( anyInt() ) ).thenReturn( projects );
+        when( configurationService.getNumberOfBuildsInParallel() ).thenReturn( 2 );
+        when( overallBuildQueue.getBuildQueue() ).thenReturn( buildQueue );
+        when( overallBuildQueue.getBuildTaskQueueExecutor() ).thenReturn( buildTaskQueueExecutor );
     }
 
-    private void recordBuildProjectBuildQueuesAreEmpty()
+    private void setupBuildProjectBuildQueuesAreEmpty()
         throws TaskQueueException, ContinuumStoreException
     {
         // shouldn't only the build queues attached to the schedule be checked?
-        recordStartOfBuildProjectSequence();
+        setupStartOfBuildProjectSequence();
 
-        final List<Task> tasks = new ArrayList<Task>();
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 2 ).of( buildQueue ).getQueueSnapshot();
-                will( returnValue( tasks ) );
-
-                exactly( 2 ).of( buildTaskQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_2" ) );
-            }
-        } );
-
-        recordAddToBuildQueue();
-    }
-
-    private void recordAddToBuildQueue()
-        throws TaskQueueException
-    {
-        context.checking( new Expectations()
-        {
-            {
-                one( overallBuildQueue ).addToBuildQueue( with( any( BuildProjectTask.class ) ) );
-            }
-        } );
+        List<Task> tasks = new ArrayList<Task>();
+        when( buildQueue.getQueueSnapshot() ).thenReturn( tasks );
+        when( buildTaskQueueExecutor.getCurrentTask() ).thenReturn( null );
+        when( overallBuildQueue.getName() ).thenReturn( "BUILD_QUEUE_2" );
     }
 
     // checkout project recordings
     private void recordStartOfCheckoutProjectSequence()
         throws TaskQueueException
     {
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 5 ).of( overallBuildQueue ).isInCheckoutQueue( with( any( int.class ) ) );
-                will( returnValue( false ) );
-
-                one( configurationService ).getNumberOfBuildsInParallel();
-                will( returnValue( 2 ) );
-
-                exactly( 2 ).of( overallBuildQueue ).getCheckoutQueue();
-                will( returnValue( checkoutQueue ) );
-
-                exactly( 2 ).of( overallBuildQueue ).getCheckoutTaskQueueExecutor();
-                will( returnValue( checkoutTaskQueueExecutor ) );
-            }
-        } );
-
+        when( overallBuildQueue.isInCheckoutQueue( anyInt() ) ).thenReturn( false );
+        when( configurationService.getNumberOfBuildsInParallel() ).thenReturn( 2 );
+        when( overallBuildQueue.getCheckoutQueue() ).thenReturn( checkoutQueue );
+        when( overallBuildQueue.getCheckoutTaskQueueExecutor() ).thenReturn( checkoutTaskQueueExecutor );
     }
 
-    private void recordCheckoutProjectBuildQueuesAreEmpty()
+    private void setupCheckoutProjectBuildQueuesAreEmpty()
         throws TaskQueueException
     {
-        recordStartOfCheckoutProjectSequence();
-
-        final List<Task> tasks = new ArrayList<Task>();
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 2 ).of( checkoutQueue ).getQueueSnapshot();
-                will( returnValue( tasks ) );
-
-                exactly( 2 ).of( checkoutTaskQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_2" ) );
-            }
-        } );
-
-        recordAddToCheckoutQueue();
-    }
-
-    private void recordAddToCheckoutQueue()
-        throws TaskQueueException
-    {
-        context.checking( new Expectations()
-        {
-            {
-                one( overallBuildQueue ).addToCheckoutQueue( with( any( CheckOutTask.class ) ) );
-            }
-        } );
+        when( overallBuildQueue.isInCheckoutQueue( anyInt() ) ).thenReturn( false );
+        when( configurationService.getNumberOfBuildsInParallel() ).thenReturn( 2 );
+        when( overallBuildQueue.getCheckoutQueue() ).thenReturn( checkoutQueue );
+        when( overallBuildQueue.getCheckoutTaskQueueExecutor() ).thenReturn( checkoutTaskQueueExecutor );
+        when( checkoutQueue.getQueueSnapshot() ).thenReturn( new ArrayList<Task>() );
+        when( checkoutTaskQueueExecutor.getCurrentTask() ).thenReturn( null );
+        when( overallBuildQueue.getName() ).thenReturn( "BUILD_QUEUE_2" );
     }
 
     // prepare build project recordings
-    private void recordStartOfPrepareBuildProjectSequence()
+    private void setupStartOfPrepareBuildProjectSequence()
         throws TaskQueueException, ContinuumStoreException
     {
         final BuildDefinition buildDef = new BuildDefinition();
         buildDef.setId( 1 );
         buildDef.setSchedule( getSchedule( 1, 1, 2 ) );
 
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 5 ).of( overallBuildQueue ).isInPrepareBuildQueue( with( any( int.class ) ), with( any(
-                    int.class ) ) );
-                will( returnValue( false ) );
-
-                one( buildDefinitionDao ).getBuildDefinition( 1 );
-                will( returnValue( buildDef ) );
-
-                one( configurationService ).getNumberOfBuildsInParallel();
-                will( returnValue( 2 ) );
-
-                exactly( 2 ).of( overallBuildQueue ).getPrepareBuildQueue();
-                will( returnValue( prepareBuildQueue ) );
-
-                exactly( 2 ).of( overallBuildQueue ).getPrepareBuildTaskQueueExecutor();
-                will( returnValue( prepareBuildTaskQueueExecutor ) );
-            }
-        } );
-    }
-
-    private void recordPrepareBuildProjectPrepareBuildQueuesAreEmpty()
-        throws TaskQueueException, ContinuumStoreException
-    {
-        recordStartOfPrepareBuildProjectSequence();
-
-        final List<Task> tasks = new ArrayList<Task>();
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 2 ).of( prepareBuildQueue ).getQueueSnapshot();
-                will( returnValue( tasks ) );
-
-                exactly( 2 ).of( prepareBuildTaskQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_2" ) );
-            }
-        } );
-
-        recordAddToPrepareBuildQueue();
-    }
-
-    private void recordAddToPrepareBuildQueue()
-        throws TaskQueueException
-    {
-        context.checking( new Expectations()
-        {
-            {
-                one( overallBuildQueue ).addToPrepareBuildQueue( with( any( PrepareBuildProjectsTask.class ) ) );
-            }
-        } );
+        when( overallBuildQueue.isInPrepareBuildQueue( anyInt(), anyInt() ) ).thenReturn( false );
+        when( buildDefinitionDao.getBuildDefinition( 1 ) ).thenReturn( buildDef );
+        when( configurationService.getNumberOfBuildsInParallel() ).thenReturn( 2 );
+        when( overallBuildQueue.getPrepareBuildQueue() ).thenReturn( prepareBuildQueue );
+        when( overallBuildQueue.getPrepareBuildTaskQueueExecutor() ).thenReturn( prepareBuildTaskQueueExecutor );
     }
 
     // start of test cases..
@@ -372,10 +229,8 @@ public class ParallelBuildsManagerTest
         throws Exception
     {
         buildsManager.setContainer( getContainer() );
-
         buildsManager.isProjectInAnyCurrentBuild( 1 );
-
-        assertTrue( true );
+        assertTrue( true ); // why is this necessary?
     }
 
     public void testBuildProjectNoProjectQueuedInAnyOverallBuildQueues()
@@ -387,12 +242,12 @@ public class ParallelBuildsManagerTest
         buildDef.setId( 1 );
         buildDef.setSchedule( getSchedule( 1, 1, 2 ) );
 
-        recordBuildProjectBuildQueuesAreEmpty();
+        setupBuildProjectBuildQueuesAreEmpty();
 
         buildsManager.buildProject( 1, buildDef, "continuum-project-test-1", new BuildTrigger( 1, "test-user" ), null,
                                     1 );
 
-        context.assertIsSatisfied();
+        verify( overallBuildQueue ).addToBuildQueue( any( BuildProjectTask.class ) );
     }
 
     public void testBuildProjectProjectsAreAlreadyQueuedInOverallBuildQueues()
@@ -404,14 +259,16 @@ public class ParallelBuildsManagerTest
         buildDef.setId( 1 );
         buildDef.setSchedule( getSchedule( 1, 1, 2 ) );
 
-        recordBuildProjectBuildQueuesAreEmpty();
+        setupBuildProjectBuildQueuesAreEmpty();
 
         buildsManager.buildProject( 1, buildDef, "continuum-project-test-1", new BuildTrigger( 1, "test-user" ), null,
                                     1 );
-        context.assertIsSatisfied();
 
-        //queue second project - 1st queue is not empty, 2nd queue is empty 
-        recordStartOfBuildProjectSequence();
+        verify( overallBuildQueue ).addToBuildQueue( any( BuildProjectTask.class ) );
+
+        //queue second project - 1st queue is not empty, 2nd queue is empty
+        reset( overallBuildQueue );
+        setupStartOfBuildProjectSequence();
 
         // the first build queue already has a task queued
         final List<Task> tasks = new ArrayList<Task>();
@@ -419,92 +276,53 @@ public class ParallelBuildsManagerTest
         tasksOfFirstBuildQueue.add( new BuildProjectTask( 2, 1, new BuildTrigger( 1, "test-user" ),
                                                           "continuum-project-test-2", buildDef.getDescription(), null,
                                                           2 ) );
-        context.checking( new Expectations()
-        {
-            {
-                one( buildQueue ).getQueueSnapshot();
-                will( returnValue( tasksOfFirstBuildQueue ) );
 
-                // the second build queue has no tasks queued, so it should return 0
-                one( buildQueue ).getQueueSnapshot();
-                will( returnValue( tasks ) );
-
-                exactly( 2 ).of( buildTaskQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_3" ) );
-            }
-        } );
-
-        recordAddToBuildQueue();
+        when( buildQueue.getQueueSnapshot() ).thenReturn( tasksOfFirstBuildQueue, tasks );
+        when( buildTaskQueueExecutor.getCurrentTask() ).thenReturn( null );
+        when( overallBuildQueue.getName() ).thenReturn( "BUILD_QUEUE_3" );
 
         buildsManager.buildProject( 2, buildDef, "continuum-project-test-2", new BuildTrigger( 1, "test-user" ), null,
                                     2 );
-        context.assertIsSatisfied();
 
-        // queue third project - both queues have 1 task queued each
-        recordStartOfBuildProjectSequence();
-
-        // both queues have 1 task each        
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 2 ).of( buildQueue ).getQueueSnapshot();
-                will( returnValue( tasksOfFirstBuildQueue ) );
+        verify( overallBuildQueue ).addToBuildQueue( any( BuildProjectTask.class ) );
 
-                exactly( 2 ).of( buildTaskQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_2" ) );
-            }
-        } );
+        // queue third project - both queues have 1 task queued each
+        reset( overallBuildQueue );
+        setupStartOfBuildProjectSequence();
 
-        recordAddToBuildQueue();
+        // both queues have 1 task each
+        when( buildQueue.getQueueSnapshot() ).thenReturn( tasksOfFirstBuildQueue, tasksOfFirstBuildQueue );
+        when( buildTaskQueueExecutor.getCurrentTask() ).thenReturn( null );
+        when( overallBuildQueue.getName() ).thenReturn( "BUILD_QUEUE_2" );
 
         buildsManager.buildProject( 3, buildDef, "continuum-project-test-3", new BuildTrigger( 1, "test-user" ), null,
                                     3 );
-        context.assertIsSatisfied();
+
+        verify( overallBuildQueue ).addToBuildQueue( any( BuildProjectTask.class ) );
     }
 
     public void testRemoveProjectFromBuildQueue()
         throws Exception
     {
         setupMockOverallBuildQueues();
-
-        context.checking( new Expectations()
-        {
-            {
-                one( overallBuildQueue ).isInBuildQueue( 1 );
-                will( returnValue( true ) );
-
-                one( overallBuildQueue ).removeProjectFromBuildQueue( 1 );
-            }
-        } );
+        when( overallBuildQueue.isInBuildQueue( 1 ) ).thenReturn( true );
 
         buildsManager.removeProjectFromBuildQueue( 1 );
-        context.assertIsSatisfied();
+
+        verify( overallBuildQueue ).removeProjectFromBuildQueue( 1 );
     }
 
     public void testRemoveProjectsFromBuildQueue()
         throws Exception
     {
         setupMockOverallBuildQueues();
-        int[] projectIds = new int[]{1, 2, 3};
-
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 3 ).of( overallBuildQueue ).isInBuildQueue( with( any( int.class ) ) );
-                will( returnValue( true ) );
-
-                exactly( 3 ).of( overallBuildQueue ).removeProjectFromBuildQueue( with( any( int.class ) ) );
-            }
-        } );
+        when( overallBuildQueue.isInBuildQueue( anyInt() ) ).thenReturn( true );
 
+        int[] projectIds = new int[] { 1, 2, 3 };
         buildsManager.removeProjectsFromBuildQueue( projectIds );
-        context.assertIsSatisfied();
+
+        for ( int projectId : projectIds )
+            verify( overallBuildQueue ).removeProjectFromBuildQueue( projectId );
     }
 
     public void testCheckoutProjectSingle()
@@ -516,12 +334,13 @@ public class ParallelBuildsManagerTest
         buildDef.setId( 1 );
         buildDef.setSchedule( getSchedule( 1, 1, 2 ) );
 
-        recordCheckoutProjectBuildQueuesAreEmpty();
+        setupCheckoutProjectBuildQueuesAreEmpty();
 
-        buildsManager.checkoutProject( 1, "continuum-project-test-1", new File( getBasedir(),
-                                                                                "/target/test-working-dir/1" ), null,
+        buildsManager.checkoutProject( 1, "continuum-project-test-1",
+                                       new File( getBasedir(), "/target/test-working-dir/1" ), null,
                                        "dummy", "dummypass", buildDef, null );
-        context.assertIsSatisfied();
+
+        verify( overallBuildQueue ).addToCheckoutQueue( any( CheckOutTask.class ) );
     }
 
     public void testCheckoutProjectMultiple()
@@ -533,148 +352,95 @@ public class ParallelBuildsManagerTest
         buildDef.setId( 1 );
         buildDef.setSchedule( getSchedule( 1, 1, 2 ) );
 
-        recordCheckoutProjectBuildQueuesAreEmpty();
+        setupCheckoutProjectBuildQueuesAreEmpty();
 
-        buildsManager.checkoutProject( 1, "continuum-project-test-1", new File( getBasedir(),
-                                                                                "/target/test-working-dir/1" ), null,
+        buildsManager.checkoutProject( 1, "continuum-project-test-1",
+                                       new File( getBasedir(), "/target/test-working-dir/1" ), null,
                                        "dummy", "dummypass", buildDef, null );
-        context.assertIsSatisfied();
 
-        // queue second project - 1st queue has 1 task while 2nd queue is empty; project should be queued in
-        //      2nd queue
-        recordStartOfCheckoutProjectSequence();
+        verify( overallBuildQueue ).addToCheckoutQueue( any( CheckOutTask.class ) );
 
-        final List<Task> tasks = new ArrayList<Task>();
+        // queue second project - 1st queue has 1 task while 2nd queue is empty; project should be queued in 2nd queue
+        reset( overallBuildQueue );
+        recordStartOfCheckoutProjectSequence();
 
-        final List<Task> tasksInFirstCheckoutQueue = new ArrayList<Task>();
-        tasksInFirstCheckoutQueue.add( new CheckOutTask( 1, new File( getBasedir(), "/target/test-working-dir/1" ),
+        List<Task> tasks = new ArrayList<Task>();
+        List<Task> tasksInFirstCheckoutQueue = new ArrayList<Task>();
+        tasksInFirstCheckoutQueue.add( new CheckOutTask( 1,
+                                                         new File( getBasedir(), "/target/test-working-dir/1" ),
                                                          "continuum-project-test-1", "dummy", "dummypass", null,
                                                          null ) );
 
-        context.checking( new Expectations()
-        {
-            {
-                one( checkoutQueue ).getQueueSnapshot();
-                will( returnValue( tasksInFirstCheckoutQueue ) );
-
-                one( checkoutQueue ).getQueueSnapshot();
-                will( returnValue( tasks ) );
-
-                exactly( 2 ).of( checkoutTaskQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_3" ) );
-            }
-        } );
-
-        recordAddToCheckoutQueue();
+        when( checkoutQueue.getQueueSnapshot() ).thenReturn( tasksInFirstCheckoutQueue, tasks );
+        when( checkoutTaskQueueExecutor.getCurrentTask() ).thenReturn( null );
+        when( overallBuildQueue.getName() ).thenReturn( "BUILD_QUEUE_3" );
 
         buildsManager.checkoutProject( 2, "continuum-project-test-2", new File( getBasedir(),
                                                                                 "/target/test-working-dir/1" ), null,
                                        "dummy", "dummypass", buildDef, null );
-        context.assertIsSatisfied();
-
-        // queue third project - both queues have 1 task queued each; third project should be queued in 1st queue
-        recordStartOfCheckoutProjectSequence();
-
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 2 ).of( checkoutQueue ).getQueueSnapshot();
-                will( returnValue( tasksInFirstCheckoutQueue ) );
 
-                exactly( 2 ).of( checkoutTaskQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
+        verify( overallBuildQueue ).addToCheckoutQueue( any( CheckOutTask.class ) );
 
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_2" ) );
-            }
-        } );
+        reset( overallBuildQueue );
+        recordStartOfCheckoutProjectSequence();
 
-        recordAddToCheckoutQueue();
+        // queue third project - both queues have 1 task queued each; third project should be queued in 1st queue
+        when( checkoutQueue.getQueueSnapshot() ).thenReturn( tasksInFirstCheckoutQueue );
+        when( checkoutTaskQueueExecutor.getCurrentTask() ).thenReturn( null );
+        when( overallBuildQueue.getName() ).thenReturn( "BUILD_QUEUE_2" );
 
-        buildsManager.checkoutProject( 3, "continuum-project-test-3", new File( getBasedir(),
-                                                                                "/target/test-working-dir/1" ), null,
+        buildsManager.checkoutProject( 3, "continuum-project-test-3",
+                                       new File( getBasedir(), "/target/test-working-dir/1" ), null,
                                        "dummy", "dummypass", buildDef, null );
-        context.assertIsSatisfied();
+
+        verify( overallBuildQueue ).addToCheckoutQueue( any( CheckOutTask.class ) );
     }
 
     public void testRemoveProjectFromCheckoutQueue()
         throws Exception
     {
         setupMockOverallBuildQueues();
-
-        context.checking( new Expectations()
-        {
-            {
-                one( overallBuildQueue ).isInCheckoutQueue( 1 );
-                will( returnValue( true ) );
-
-                one( overallBuildQueue ).removeProjectFromCheckoutQueue( 1 );
-            }
-        } );
+        when( overallBuildQueue.isInCheckoutQueue( 1 ) ).thenReturn( true );
 
         buildsManager.removeProjectFromCheckoutQueue( 1 );
-        context.assertIsSatisfied();
+
+        verify( overallBuildQueue ).removeProjectFromCheckoutQueue( 1 );
     }
 
     public void testRemoveProjectsFromCheckoutQueue()
         throws Exception
     {
         setupMockOverallBuildQueues();
+        when( overallBuildQueue.isInCheckoutQueue( anyInt() ) ).thenReturn( true );
 
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 3 ).of( overallBuildQueue ).isInCheckoutQueue( with( any( int.class ) ) );
-                will( returnValue( true ) );
-
-                exactly( 3 ).of( overallBuildQueue ).removeProjectFromCheckoutQueue( with( any( int.class ) ) );
-            }
-        } );
-
-        int[] projectIds = new int[]{1, 2, 3};
-
+        int[] projectIds = new int[] { 1, 2, 3 };
         buildsManager.removeProjectsFromCheckoutQueue( projectIds );
-        context.assertIsSatisfied();
+
+        for ( int projectId : projectIds )
+            verify( overallBuildQueue ).removeProjectFromCheckoutQueue( projectId );
     }
 
     public void testRemoveProjectFromCheckoutQueueProjectNotFound()
         throws Exception
     {
         setupMockOverallBuildQueues();
+        when( overallBuildQueue.isInCheckoutQueue( 1 ) ).thenReturn( false );
 
         // shouldn't only the project's build queues be checked instead of all the overall build queues?
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 5 ).of( overallBuildQueue ).isInCheckoutQueue( 1 );
-                will( returnValue( false ) );
-            }
-        } );
-
         buildsManager.removeProjectFromCheckoutQueue( 1 );
-        context.assertIsSatisfied();
+
+        verify( overallBuildQueue, never() ).removeProjectFromCheckoutQueue( 1 );
     }
 
     public void testRemoveDefaultOverallBuildQueue()
         throws Exception
     {
         setupMockOverallBuildQueues();
+        when( overallBuildQueue.getName() ).thenReturn( ConfigurationService.DEFAULT_BUILD_QUEUE_NAME );
 
         try
         {
-            context.checking( new Expectations()
-            {
-                {
-                    one( overallBuildQueue ).getName();
-                    will( returnValue( ConfigurationService.DEFAULT_BUILD_QUEUE_NAME ) );
-                }
-            } );
-
             buildsManager.removeOverallBuildQueue( 1 );
-            context.assertIsSatisfied();
             fail( "An exception should have been thrown." );
         }
         catch ( BuildManagerException e )
@@ -689,195 +455,81 @@ public class ParallelBuildsManagerTest
         // queued tasks (both checkout & build tasks) must be transferred to the other queues!
         setupMockOverallBuildQueues();
 
-        final BuildDefinition buildDef = new BuildDefinition();
+        BuildDefinition buildDef = new BuildDefinition();
         buildDef.setId( 1 );
         buildDef.setSchedule( getSchedule( 1, 1, 2 ) );
 
-        final TaskQueueExecutor buildQueueExecutor = context.mock( TaskQueueExecutor.class, "build-queue-executor" );
-        final TaskQueueExecutor checkoutQueueExecutor = context.mock( TaskQueueExecutor.class,
-                                                                      "checkout-queue-executor" );
-        final TaskQueueExecutor prepareBuildQueueExecutor = context.mock( TaskQueueExecutor.class,
-                                                                          "prepare-build-queue-executor" );
-
-        final List<Task> buildTasks = new ArrayList<Task>();
+        List<BuildProjectTask> buildTasks = new ArrayList<BuildProjectTask>();
         buildTasks.add( new BuildProjectTask( 2, 1, new BuildTrigger( 1, "test-user" ), "continuum-project-test-2",
                                               "BUILD_DEF", null, 2 ) );
 
-        final List<CheckOutTask> checkoutTasks = new ArrayList<CheckOutTask>();
+        List<CheckOutTask> checkoutTasks = new ArrayList<CheckOutTask>();
         checkoutTasks.add( new CheckOutTask( 2, new File( getBasedir(), "/target/test-working-dir/1" ),
                                              "continuum-project-test-2", "dummy", "dummypass", null, null ) );
 
-        final List<Task> prepareBuildTasks = new ArrayList<Task>();
-        final Map<Integer, Integer> map = new HashMap<Integer, Integer>();
+        List<PrepareBuildProjectsTask> prepareBuildTasks = new ArrayList<PrepareBuildProjectsTask>();
+        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
         map.put( 1, 1 );
         prepareBuildTasks.add( new PrepareBuildProjectsTask( map, new BuildTrigger( 1, "test-user" ), 1,
                                                              "Project Group A", "http://scm.root.address", 2 ) );
 
-        final ParallelBuildsThreadedTaskQueueExecutor buildTaskQueueExecutor = context.mock(
+        ParallelBuildsThreadedTaskQueueExecutor buildTaskQueueExecutor = mock(
             ParallelBuildsThreadedTaskQueueExecutor.class, "parallel-build-task-executor" );
-        final ParallelBuildsThreadedTaskQueueExecutor checkoutTaskQueueExecutor = context.mock(
+        ParallelBuildsThreadedTaskQueueExecutor checkoutTaskQueueExecutor = mock(
             ParallelBuildsThreadedTaskQueueExecutor.class, "parallel-checkout-task-executor" );
-        final ParallelBuildsThreadedTaskQueueExecutor prepareBuildTaskQueueExecutor = context.mock(
+        ParallelBuildsThreadedTaskQueueExecutor prepareBuildTaskQueueExecutor = mock(
             ParallelBuildsThreadedTaskQueueExecutor.class, "parallel-prepare-build-task-executor" );
 
-        final List<Task> tasks = new ArrayList<Task>();
-
-        context.checking( new Expectations()
-        {
-            {
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_5" ) );
-
-                // check if there is any build task currently being executed
-                one( overallBuildQueue ).getBuildTaskQueueExecutor();
-                will( returnValue( buildQueueExecutor ) );
-                one( buildQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-                //will( returnValue( buildTask ) );
-
-                // check if there is any checkout task currently being executed
-                one( overallBuildQueue ).getCheckoutTaskQueueExecutor();
-                will( returnValue( checkoutQueueExecutor ) );
-                one( checkoutQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-                //will( returnValue( checkoutTask ) );
-
-                // check if there is any prepare build task currently being executed
-                one( overallBuildQueue ).getPrepareBuildTaskQueueExecutor();
-                will( returnValue( prepareBuildQueueExecutor ) );
-                one( prepareBuildQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                // get all queued build tasks & remove them
-                one( overallBuildQueue ).getProjectsInBuildQueue();
-                will( returnValue( buildTasks ) );
-                one( overallBuildQueue ).getBuildQueue();
-                will( returnValue( buildQueue ) );
-                one( buildQueue ).removeAll( buildTasks );
-
-                // get all queued checkout tasks & remove them
-                one( overallBuildQueue ).getProjectsInCheckoutQueue();
-                will( returnValue( checkoutTasks ) );
-                one( overallBuildQueue ).getCheckoutQueue();
-                will( returnValue( checkoutQueue ) );
-                one( checkoutQueue ).removeAll( checkoutTasks );
-
-                // get all queued prepare build tasks & remove them
-                one( overallBuildQueue ).getProjectsInPrepareBuildQueue();
-                will( returnValue( prepareBuildTasks ) );
-                one( overallBuildQueue ).getPrepareBuildQueue();
-                will( returnValue( prepareBuildQueue ) );
-                one( prepareBuildQueue ).removeAll( prepareBuildTasks );
-
-                // stop the build & checkout task queue executors
-                one( overallBuildQueue ).getBuildTaskQueueExecutor();
-                will( returnValue( buildTaskQueueExecutor ) );
-                one( overallBuildQueue ).getCheckoutTaskQueueExecutor();
-                will( returnValue( checkoutTaskQueueExecutor ) );
-                one( overallBuildQueue ).getPrepareBuildTaskQueueExecutor();
-                will( returnValue( prepareBuildTaskQueueExecutor ) );
-
-                one( buildTaskQueueExecutor ).stop();
-                one( checkoutTaskQueueExecutor ).stop();
-                one( prepareBuildTaskQueueExecutor ).stop();
-
-                // TODO: test scenario when there are no longer build queues configured aside from the one removed?
-                //      - the behaviour should be that the default build queue will be used!
-
-                // re-queue projects in the build queue of the deleted overall build queue
-                one( buildDefinitionDao ).getBuildDefinition( 1 );
-                will( returnValue( buildDef ) );
-
-                // queue to other build queue
-                exactly( 4 ).of( overallBuildQueue ).isInBuildQueue( with( any( int.class ) ) );
-                will( returnValue( false ) );
-
-                exactly( 4 ).of( buildQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( projectDao ).getProjectsInGroup( with( any( int.class ) ) );
-                will( returnValue( projects ) );
-
-                one( configurationService ).getNumberOfBuildsInParallel();
-                will( returnValue( 2 ) );
-
-                exactly( 2 ).of( overallBuildQueue ).getBuildQueue();
-                will( returnValue( buildQueue ) );
-
-                exactly( 6 ).of( overallBuildQueue ).getBuildTaskQueueExecutor();
-                will( returnValue( buildQueueExecutor ) );
-
-                exactly( 2 ).of( buildQueue ).getQueueSnapshot();
-                will( returnValue( tasks ) );
-
-                exactly( 2 ).of( buildQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_2" ) );
-
-                recordAddToBuildQueue();
-
-                // re-queue projects in the checkout queue of the deleted overall build queue
-                one( buildDefinitionDao ).getDefaultBuildDefinition( 2 );
-                will( returnValue( buildDef ) );
-
-                // queue to other checkout queues
-                exactly( 4 ).of( overallBuildQueue ).isInCheckoutQueue( with( any( int.class ) ) );
-                will( returnValue( false ) );
-
-                one( configurationService ).getNumberOfBuildsInParallel();
-                will( returnValue( 2 ) );
-
-                exactly( 2 ).of( overallBuildQueue ).getCheckoutQueue();
-                will( returnValue( checkoutQueue ) );
-
-                exactly( 2 ).of( overallBuildQueue ).getCheckoutTaskQueueExecutor();
-                will( returnValue( checkoutQueueExecutor ) );
-
-                exactly( 2 ).of( checkoutQueue ).getQueueSnapshot();
-                will( returnValue( tasks ) );
-
-                exactly( 2 ).of( checkoutQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_2" ) );
-
-                recordAddToCheckoutQueue();
-
-                // re-queue projects in the prepare build queue of the deleted overall build queue
-                exactly( 4 ).of( overallBuildQueue ).isInPrepareBuildQueue( with( any( int.class ) ), with( any(
-                    int.class ) ) );
-                will( returnValue( false ) );
-
-                one( buildDefinitionDao ).getBuildDefinition( 1 );
-                will( returnValue( buildDef ) );
-
-                one( configurationService ).getNumberOfBuildsInParallel();
-                will( returnValue( 2 ) );
+        List<Task> tasks = new ArrayList<Task>();
 
-                exactly( 2 ).of( overallBuildQueue ).getPrepareBuildQueue();
-                will( returnValue( prepareBuildQueue ) );
+        when( configurationService.getNumberOfBuildsInParallel() ).thenReturn( 2 );
 
-                exactly( 2 ).of( overallBuildQueue ).getPrepareBuildTaskQueueExecutor();
-                will( returnValue( prepareBuildQueueExecutor ) );
+        when( overallBuildQueue.getName() ).thenReturn( "BUILD_QUEUE_5", "BUILD_QUEUE_2" );
 
-                exactly( 2 ).of( prepareBuildQueue ).getQueueSnapshot();
-                will( returnValue( tasks ) );
-
-                exactly( 2 ).of( prepareBuildQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_2" ) );
-
-                recordAddToPrepareBuildQueue();
-            }
-        } );
+        // get all queued build tasks & remove them
+        when( overallBuildQueue.getProjectsInBuildQueue() ).thenReturn( buildTasks );
+        when( overallBuildQueue.getBuildQueue() ).thenReturn( buildQueue );
+        when( buildQueue.getQueueSnapshot() ).thenReturn( tasks );
+
+        // get all queued checkout tasks & remove them
+        when( overallBuildQueue.getProjectsInCheckoutQueue() ).thenReturn( checkoutTasks );
+        when( overallBuildQueue.getCheckoutQueue() ).thenReturn( checkoutQueue );
+        when( checkoutQueue.getQueueSnapshot() ).thenReturn( tasks );
+
+        // get all queued prepare build tasks & remove them
+        when( overallBuildQueue.getProjectsInPrepareBuildQueue() ).thenReturn( prepareBuildTasks );
+        when( overallBuildQueue.getPrepareBuildQueue() ).thenReturn( prepareBuildQueue );
+        when( prepareBuildQueue.getQueueSnapshot() ).thenReturn( tasks );
+
+        // stop the build & checkout task queue executors
+        when( overallBuildQueue.getBuildTaskQueueExecutor() ).thenReturn( buildTaskQueueExecutor );
+        when( overallBuildQueue.getCheckoutTaskQueueExecutor() ).thenReturn( checkoutTaskQueueExecutor );
+        when( overallBuildQueue.getPrepareBuildTaskQueueExecutor() ).thenReturn( prepareBuildTaskQueueExecutor );
+
+        // TODO: test scenario when there are no longer build queues configured aside from the one removed?
+        //      - the behaviour should be that the default build queue will be used!
+
+        when( projectDao.getProjectsInGroup( anyInt() ) ).thenReturn( projects );
+        when( buildDefinitionDao.getBuildDefinition( 1 ) ).thenReturn( buildDef );
+        when( buildDefinitionDao.getDefaultBuildDefinition( 2 ) ).thenReturn( buildDef );
+
+        when( overallBuildQueue.isInBuildQueue( anyInt() ) ).thenReturn( false );
+        when( overallBuildQueue.isInCheckoutQueue( anyInt() ) ).thenReturn( false );
+        when( overallBuildQueue.isInPrepareBuildQueue( anyInt(), anyInt() ) ).thenReturn( false );
 
         buildsManager.removeOverallBuildQueue( 5 );
-        context.assertIsSatisfied();
+
+        verify( buildQueue ).removeAll( buildTasks );
+        verify( checkoutQueue ).removeAll( checkoutTasks );
+        verify( prepareBuildQueue ).removeAll( prepareBuildTasks );
+
+        verify( buildTaskQueueExecutor ).stop();
+        verify( checkoutTaskQueueExecutor ).stop();
+        verify( prepareBuildTaskQueueExecutor ).stop();
+
+        verify( overallBuildQueue ).addToBuildQueue( any( BuildProjectTask.class ) );
+        verify( overallBuildQueue ).addToCheckoutQueue( any( CheckOutTask.class ) );
+        verify( overallBuildQueue ).addToPrepareBuildQueue( any( PrepareBuildProjectsTask.class ) );
 
         Map<Integer, OverallBuildQueue> overallBuildQueues = buildsManager.getOverallBuildQueues();
         assertNull( overallBuildQueues.get( 5 ) );
@@ -888,40 +540,29 @@ public class ParallelBuildsManagerTest
     {
         setupMockOverallBuildQueues();
 
-        final BuildDefinition buildDef = new BuildDefinition();
+        BuildDefinition buildDef = new BuildDefinition();
         buildDef.setId( 1 );
         buildDef.setSchedule( getSchedule( 1, 1, 2 ) );
 
-        final TaskQueueExecutor buildQueueExecutor = context.mock( TaskQueueExecutor.class, "build-queue-executor" );
-        final Task buildTask = new BuildProjectTask( 1, 1, new BuildTrigger( 1, "test-user" ),
-                                                     "continuum-project-test-1", "BUILD_DEF", null, 1 );
+        TaskQueueExecutor buildQueueExecutor = mock( TaskQueueExecutor.class, "build-queue-executor" );
+        Task buildTask = new BuildProjectTask( 1, 1, new BuildTrigger( 1, "test-user" ),
+                                               "continuum-project-test-1", "BUILD_DEF", null, 1 );
 
-        final List<BuildProjectTask> buildTasks = new ArrayList<BuildProjectTask>();
+        List<BuildProjectTask> buildTasks = new ArrayList<BuildProjectTask>();
         buildTasks.add( new BuildProjectTask( 2, 1, new BuildTrigger( 1, "test-user" ), "continuum-project-test-2",
                                               "BUILD_DEF", null, 2 ) );
 
-        final List<CheckOutTask> checkoutTasks = new ArrayList<CheckOutTask>();
+        List<CheckOutTask> checkoutTasks = new ArrayList<CheckOutTask>();
         checkoutTasks.add( new CheckOutTask( 2, new File( getBasedir(), "/target/test-working-dir/1" ),
                                              "continuum-project-test-2", "dummy", "dummypass", null, null ) );
 
+        when( overallBuildQueue.getName() ).thenReturn( "BUILD_QUEUE_5" );
+        when( overallBuildQueue.getBuildTaskQueueExecutor() ).thenReturn( buildQueueExecutor );
+        when( buildQueueExecutor.getCurrentTask() ).thenReturn( buildTask );
+
         try
         {
-            context.checking( new Expectations()
-            {
-                {
-                    one( overallBuildQueue ).getName();
-                    will( returnValue( "BUILD_QUEUE_5" ) );
-
-                    // check if there is any build task currently being executed
-                    one( overallBuildQueue ).getBuildTaskQueueExecutor();
-                    will( returnValue( buildQueueExecutor ) );
-                    one( buildQueueExecutor ).getCurrentTask();
-                    will( returnValue( buildTask ) );
-                }
-            } );
-
             buildsManager.removeOverallBuildQueue( 5 );
-            context.assertIsSatisfied();
             fail( "An exception should have been thrown." );
         }
         catch ( BuildManagerException e )
@@ -933,12 +574,10 @@ public class ParallelBuildsManagerTest
     public void testNoBuildQueuesConfigured()
         throws Exception
     {
-        overallBuildQueue = context.mock( OverallBuildQueue.class );
-
-        Map<Integer, OverallBuildQueue> overallBuildQueues = Collections.synchronizedMap(
-            new HashMap<Integer, OverallBuildQueue>() );
+        Map<Integer, OverallBuildQueue> overallBuildQueues =
+            Collections.synchronizedMap( new HashMap<Integer, OverallBuildQueue>() );
+        overallBuildQueue = mock( OverallBuildQueue.class );
         overallBuildQueues.put( 1, overallBuildQueue );
-
         buildsManager.setOverallBuildQueues( overallBuildQueues );
 
         Schedule schedule = new Schedule();
@@ -952,34 +591,17 @@ public class ParallelBuildsManagerTest
         buildDef.setId( 1 );
         buildDef.setSchedule( schedule );
 
-        context.checking( new Expectations()
-        {
-            {
-                one( overallBuildQueue ).isInBuildQueue( with( any( int.class ) ) );
-                will( returnValue( false ) );
-
-                one( overallBuildQueue ).getBuildTaskQueueExecutor();
-                will( returnValue( buildTaskQueueExecutor ) );
-
-                one( buildTaskQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( projectDao ).getProjectsInGroup( with( any( int.class ) ) );
-                will( returnValue( projects ) );
-
-                one( configurationService ).getNumberOfBuildsInParallel();
-                will( returnValue( 2 ) );
-
-                exactly( 2 ).of( overallBuildQueue ).getName();
-                will( returnValue( ConfigurationService.DEFAULT_BUILD_QUEUE_NAME ) );
-
-                one( overallBuildQueue ).addToBuildQueue( with( any( BuildProjectTask.class ) ) );
-            }
-        } );
+        when( overallBuildQueue.isInBuildQueue( anyInt() ) ).thenReturn( false );
+        when( overallBuildQueue.getBuildTaskQueueExecutor() ).thenReturn( buildTaskQueueExecutor );
+        when( buildTaskQueueExecutor.getCurrentTask() ).thenReturn( null );
+        when( projectDao.getProjectsInGroup( anyInt() ) ).thenReturn( projects );
+        when( configurationService.getNumberOfBuildsInParallel() ).thenReturn( 2 );
+        when( overallBuildQueue.getName() ).thenReturn( ConfigurationService.DEFAULT_BUILD_QUEUE_NAME );
 
         buildsManager.buildProject( 1, buildDef, "continuum-project-test-1", new BuildTrigger( 1, "test-user" ), null,
                                     1 );
-        context.assertIsSatisfied();
+
+        verify( overallBuildQueue ).addToBuildQueue( any( BuildProjectTask.class ) );
     }
 
     public void testGetProjectsInBuildQueue()
@@ -987,23 +609,20 @@ public class ParallelBuildsManagerTest
     {
         setupMockOverallBuildQueues();
 
-        final List<Task> tasks = new ArrayList<Task>();
-        tasks.add( new BuildProjectTask( 2, 1, new BuildTrigger( 1, "test-user" ), "continuum-project-test-2",
-                                         "BUILD_DEF", null, 2 ) );
-
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 5 ).of( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE" ) );
-
-                exactly( 5 ).of( overallBuildQueue ).getProjectsInBuildQueue();
-                will( returnValue( tasks ) );
-            }
-        } );
-
-        buildsManager.getProjectsInBuildQueues();
-        context.assertIsSatisfied();
+        List<BuildProjectTask> tasks = new ArrayList<BuildProjectTask>();
+        tasks.add(
+            new BuildProjectTask( 2, 1, new BuildTrigger( 1, "test-user" ), "continuum-project-test-2", "BUILD_DEF",
+                                  null, 2 ) );
+
+        String queueName = "BUILD_QUEUE";
+        when( overallBuildQueue.getName() ).thenReturn( queueName );
+        when( overallBuildQueue.getProjectsInBuildQueue() ).thenReturn( tasks );
+
+        Map<String, List<BuildProjectTask>> result = buildsManager.getProjectsInBuildQueues();
+
+        assertEquals( 1, result.size() );
+        assertTrue( queueName + " should be present in result", result.containsKey( queueName ) );
+        assertEquals( tasks, result.get( queueName ) );
     }
 
     public void testGetProjectsInCheckoutQueue()
@@ -1011,23 +630,19 @@ public class ParallelBuildsManagerTest
     {
         setupMockOverallBuildQueues();
 
-        final List<Task> tasks = new ArrayList<Task>();
+        List<CheckOutTask> tasks = new ArrayList<CheckOutTask>();
         tasks.add( new CheckOutTask( 2, new File( getBasedir(), "/target/test-working-dir/1" ),
                                      "continuum-project-test-2", "dummy", "dummypass", null, null ) );
 
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 5 ).of( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE" ) );
-
-                exactly( 5 ).of( overallBuildQueue ).getProjectsInCheckoutQueue();
-                will( returnValue( tasks ) );
-            }
-        } );
-
-        buildsManager.getProjectsInCheckoutQueues();
-        context.assertIsSatisfied();
+        String queueName = "BUILD_QUEUE";
+        when( overallBuildQueue.getName() ).thenReturn( queueName );
+        when( overallBuildQueue.getProjectsInCheckoutQueue() ).thenReturn( tasks );
+
+        Map<String, List<CheckOutTask>> result = buildsManager.getProjectsInCheckoutQueues();
+
+        assertEquals( 1, result.size() );
+        assertTrue( queueName + " should be present in result", result.containsKey( queueName ) );
+        assertEquals( tasks, result.get( queueName ) );
     }
 
     // prepare build queue
@@ -1039,11 +654,16 @@ public class ParallelBuildsManagerTest
         Map<Integer, Integer> map = new HashMap<Integer, Integer>();
         map.put( 1, 1 );
 
-        recordPrepareBuildProjectPrepareBuildQueuesAreEmpty();
+        setupStartOfPrepareBuildProjectSequence();
+
+        when( prepareBuildQueue.getQueueSnapshot() ).thenReturn( new ArrayList<Task>() );
+        when( prepareBuildTaskQueueExecutor.getCurrentTask() ).thenReturn( null );
+        when( overallBuildQueue.getName() ).thenReturn( "BUILD_QUEUE_2" );
 
         buildsManager.prepareBuildProjects( map, new BuildTrigger( 1, "test-user" ), 1, "Project Group A",
                                             "http://scm.root.address", 1 );
-        context.assertIsSatisfied();
+
+        verify( overallBuildQueue ).addToPrepareBuildQueue( any( PrepareBuildProjectsTask.class ) );
     }
 
     public void testPrepareBuildProjectsAlreadyQueued()
@@ -1055,62 +675,39 @@ public class ParallelBuildsManagerTest
         map.put( 1, 1 );
 
         //queue second project - 1st queue is not empty, 2nd queue is empty 
-        recordStartOfPrepareBuildProjectSequence();
+        setupStartOfPrepareBuildProjectSequence();
 
-        // the first prepare build queue already has a task queued
-        final List<Task> tasks = new ArrayList<Task>();
-        final List<Task> tasksOfFirstPrepareBuildQueue = new ArrayList<Task>();
+        List<Task> tasks = new ArrayList<Task>();
+        List<Task> tasksOfFirstPrepareBuildQueue = new ArrayList<Task>();
         tasksOfFirstPrepareBuildQueue.add( new PrepareBuildProjectsTask( new HashMap<Integer, Integer>(),
                                                                          new BuildTrigger( 1, "test-user" ), 1,
                                                                          "Project Group B", "http://scm.root.address2",
                                                                          2 ) );
-        context.checking( new Expectations()
-        {
-            {
-                one( prepareBuildQueue ).getQueueSnapshot();
-                will( returnValue( tasksOfFirstPrepareBuildQueue ) );
 
-                // the second prepare build queue has no tasks queued, so it should return 0
-                one( prepareBuildQueue ).getQueueSnapshot();
-                will( returnValue( tasks ) );
-
-                exactly( 2 ).of( prepareBuildTaskQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_3" ) );
-            }
-        } );
-
-        recordAddToPrepareBuildQueue();
+        // the first prepare build queue already has a task queued
+        // the second prepare build queue has no tasks queued, so it should return 0
+        when( prepareBuildQueue.getQueueSnapshot() ).thenReturn( tasksOfFirstPrepareBuildQueue, tasks );
+        when( prepareBuildTaskQueueExecutor.getCurrentTask() ).thenReturn( null );
+        when( overallBuildQueue.getName() ).thenReturn( "BUILD_QUEUE_3" );
 
         buildsManager.prepareBuildProjects( map, new BuildTrigger( 1, "test-user" ), 1, "Project Group A",
                                             "http://scm.root.address", 1 );
-        context.assertIsSatisfied();
 
-        // queue third project - both queues have 1 task queued each
-        recordStartOfPrepareBuildProjectSequence();
+        verify( overallBuildQueue ).addToPrepareBuildQueue( any( PrepareBuildProjectsTask.class ) );
 
-        // both queues have 1 task each        
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 2 ).of( prepareBuildQueue ).getQueueSnapshot();
-                will( returnValue( tasksOfFirstPrepareBuildQueue ) );
-
-                exactly( 2 ).of( prepareBuildTaskQueueExecutor ).getCurrentTask();
-                will( returnValue( null ) );
-
-                one( overallBuildQueue ).getName();
-                will( returnValue( "BUILD_QUEUE_2" ) );
-            }
-        } );
+        // queue third project - both queues have 1 task queued each
+        reset( overallBuildQueue );
+        setupStartOfPrepareBuildProjectSequence(); // Redundant
 
-        recordAddToPrepareBuildQueue();
+        // both queues have 1 task each
+        when( prepareBuildQueue.getQueueSnapshot() ).thenReturn( tasksOfFirstPrepareBuildQueue );
+        when( prepareBuildTaskQueueExecutor.getCurrentTask() ).thenReturn( null );
+        when( overallBuildQueue.getName() ).thenReturn( "BUILD_QUEUE_2" );
 
         buildsManager.prepareBuildProjects( map, new BuildTrigger( 1, "test-user" ), 1, "Project Group A",
                                             "http://scm.root.address", 1 );
-        context.assertIsSatisfied();
+
+        verify( overallBuildQueue ).addToPrepareBuildQueue( any( PrepareBuildProjectsTask.class ) );
     }
 
     public void testGetProjectsInPrepareBuildQueue()
@@ -1118,41 +715,30 @@ public class ParallelBuildsManagerTest
     {
         setupMockOverallBuildQueues();
 
-        final List<Task> tasks = new ArrayList<Task>();
+        List<PrepareBuildProjectsTask> tasks = new ArrayList<PrepareBuildProjectsTask>();
         tasks.add( new PrepareBuildProjectsTask( new HashMap<Integer, Integer>(), new BuildTrigger( 1, "test-user" ), 1,
                                                  "Project Group A", "http://scm.root.address", 2 ) );
 
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 5 ).of( overallBuildQueue ).getName();
-                will( returnValue( "PREPARE_BUILD_QUEUE" ) );
-
-                exactly( 5 ).of( overallBuildQueue ).getProjectsInPrepareBuildQueue();
-                will( returnValue( tasks ) );
-            }
-        } );
-
-        buildsManager.getProjectsInPrepareBuildQueue();
-        context.assertIsSatisfied();
+        String queueName = "PREPARE_BUILD_QUEUE";
+        when( overallBuildQueue.getName() ).thenReturn( queueName );
+        when( overallBuildQueue.getProjectsInPrepareBuildQueue() ).thenReturn( tasks );
+
+        Map<String, List<PrepareBuildProjectsTask>> result = buildsManager.getProjectsInPrepareBuildQueue();
+
+        assertEquals( 1, result.size() );
+        assertTrue( queueName + " should be present in result", result.containsKey( queueName ) );
+        assertEquals( tasks, result.get( queueName ) );
     }
 
     public void testRemoveProjectFromPrepareBuildQueue()
         throws Exception
     {
         setupMockOverallBuildQueues();
-        context.checking( new Expectations()
-        {
-            {
-                exactly( 5 ).of( overallBuildQueue ).isInPrepareBuildQueue( 1, 2 );
-                will( returnValue( true ) );
-
-                one( overallBuildQueue ).removeProjectFromPrepareBuildQueue( 1, 2 );
-            }
-        } );
+        when( overallBuildQueue.isInPrepareBuildQueue( 1, 2 ) ).thenReturn( true );
 
         buildsManager.removeProjectFromPrepareBuildQueue( 1, 2 );
-        context.assertIsSatisfied();
+
+        verify( overallBuildQueue ).removeProjectFromPrepareBuildQueue( 1, 2 );
     }
 
     /*



Mime
View raw message