CleanupEnvironmentStep { public void execute() throws PeerException { Set<Peer> peers = environment.getPeers(); if ( peers.isEmpty() ) { return; } for ( final Peer peer : peers ) { cleanupUtil.addPeerTask( new PeerUtil.PeerTask<>( peer, new Callable<Object>() { @Override public Object call() throws Exception { peer.cleanupEnvironment( environment.getEnvironmentId() ); return null; } } ) ); } PeerUtil.PeerTaskResults<Object> cleanupResults = cleanupUtil.executeParallel(); for ( PeerUtil.PeerTaskResult cleanupResult : cleanupResults.getResults() ) { if ( cleanupResult.hasSucceeded() ) { trackerOperation.addLog( String.format( "Environment cleanup succeeded on peer %s", cleanupResult.getPeer().getName() ) ); } else { trackerOperation.addLog( String.format( "Environment cleanup failed on peer %s. Reason: %s", cleanupResult.getPeer().getName(), cleanupResult.getFailureReason() ) ); } } } CleanupEnvironmentStep( final LocalEnvironment environment, final TrackerOperation trackerOperation ); void execute();  }
@Test public void testExecute() throws Exception { doReturn( true ).when( peerTaskResult ).hasSucceeded(); step.execute(); verify( trackerOperation ).addLog( anyString() ); doReturn( false ).when( peerTaskResult ).hasSucceeded(); step.execute(); verify( trackerOperation, times( 2 ) ).addLog( anyString() ); doReturn( Sets.newHashSet() ).when( environment ).getPeers(); reset( trackerOperation ); step.execute(); verify( trackerOperation, never() ).addLog( anyString() ); }