CommandProcess { synchronized void processResponse( final Response response ) { if ( expectedResponseNumber == response.getResponseNumber() ) { expectedResponseNumber++; processNextResponse( response ); for ( Response queuedResponse : queuedResponses ) { if ( expectedResponseNumber == queuedResponse.getResponseNumber() ) { expectedResponseNumber++; processNextResponse( queuedResponse ); } } } else { queuedResponses.add( response ); } } CommandProcess( final CommandProcessor commandProcessor, final CommandCallback callback, final Request request,
                    final String rhId, final Session userSession ); void stop();  }
@Test public void testProcessResponse() throws Exception { when( response.getResponseNumber() ).thenReturn( 1 ); Response response1 = mock( Response.class ); doReturn( 2 ).when( response1 ).getResponseNumber(); queuedResponses.add( response1 ); commandProcess.processResponse( response ); verify( executor, times( 2 ) ).execute( isA( ResponseProcessor.class ) ); when( response.getResponseNumber() ).thenReturn( 100 ); commandProcess.processResponse( response ); verify( queuedResponses ).add( response ); }