CommandProcess { void processNextResponse( final Response response ) { final CommandProcess THIS = this; if ( userSession != null ) { Subject.doAs( userSession.getSubject(), new PrivilegedAction<Void>() { @Override public Void run() { try { executor.execute( new ResponseProcessor( response, THIS, commandProcessor, request ) ); } catch ( Exception e ) { LOG.error( "Error in processResponse", e ); } return null; } } ); } else { executor.execute( new ResponseProcessor( response, THIS, commandProcessor, request ) ); } } CommandProcess( final CommandProcessor commandProcessor, final CommandCallback callback, final Request request,
                    final String rhId, final Session userSession ); void stop();  }
@Test public void testProcessNextResponse() throws Exception { commandProcess.processNextResponse( response ); verify( executor ).execute( isA( ResponseProcessor.class ) ); RuntimeException exception = mock( RuntimeException.class ); doThrow( exception ).when( executor ).execute( any( ResponseProcessor.class ) ); commandProcess.processNextResponse( response ); verify( exception ).printStackTrace( any( PrintStream.class ) ); reset( executor ); commandProcess.userSession = null; commandProcess.processNextResponse( response ); verify( executor ).execute( isA( ResponseProcessor.class ) ); verify( session, times( 2 ) ).getSubject(); }