CommandUtil { public CommandResult execute( RequestBuilder requestBuilder, Host host ) throws CommandException { Preconditions.checkNotNull( requestBuilder ); Preconditions.checkNotNull( host ); CommandResult result = host.execute( requestBuilder ); if ( !result.hasSucceeded() ) { throw new CommandException( String.format( "Error executing command on host %s: %s", host.getHostname(), result.hasCompleted() ? result.getStdErr() : "Command timed out" ) ); } return result; }  CommandResult execute( RequestBuilder requestBuilder, Host host ); CommandResult execute( RequestBuilder requestBuilder, Host host, CommandCallback callback ); void executeAsync( RequestBuilder requestBuilder, Host host, final StoppableCallback callback ); void executeAsync( RequestBuilder requestBuilder, Set<Host> hosts, final CommandCallback callback ); Map<Host, CommandResult> executeSequential( RequestBuilder requestBuilder, Set<Host> hosts ); HostCommandResults execute( final RequestBuilder requestBuilder, Set<Host> hosts, String environmentId ); HostCommandResults executeFailFast( final RequestBuilder requestBuilder, Set<Host> hosts,
                                               String environmentId ); boolean cancelEnvironmentCommands( String environmentId ); void cancelAll(); void dispose();  }
@Test public void testExecute() throws Exception { when( host.execute( any( RequestBuilder.class ) ) ).thenReturn( commandResult ); when( commandResult.hasSucceeded() ).thenReturn( true ); commandUtil.execute( requestBuilder, host ); }
@Test( expected = CommandException.class ) public void testExecuteException() throws Exception { when( host.execute( any( RequestBuilder.class ) ) ).thenReturn( commandResult ); when( commandResult.hasSucceeded() ).thenReturn( false ); commandUtil.execute( requestBuilder, host ); }