### Question:
StreamingState implements BoltStateMachineState { @Override public BoltStateMachineState process( RequestMessage message, StateMachineContext context ) throws BoltConnectionFatality { assertInitialized(); if ( message instanceof PullAllMessage ) { return processPullAllMessage( context ); } if ( message instanceof DiscardAllMessage ) { return processDiscardAllMessage( context ); } if ( message instanceof ResetMessage ) { return processResetMessage( context ); } if ( message instanceof InterruptSignal ) { return interruptedState; } return null; }  @Override BoltStateMachineState process( RequestMessage message, StateMachineContext context ); @Override String name(); void setReadyState( BoltStateMachineState readyState ); void setInterruptedState( BoltStateMachineState interruptedState ); void setFailedState( BoltStateMachineState failedState );  }### Answer:
@Test void shouldProcessPullAllMessage() throws Exception { StatementProcessor statementProcessor = mock( StatementProcessor.class ); connectionState.setStatementProcessor( statementProcessor ); BoltStateMachineState nextState = state.process( PullAllMessage.INSTANCE, context ); assertEquals( readyState, nextState ); verify( statementProcessor ).streamResult( any() ); }
@Test void shouldHandleAuthErrorWhenProcessingPullAllMessage() throws Exception { AuthorizationExpiredException error = new AuthorizationExpiredException( "Hello" ); StatementProcessor statementProcessor = mock( StatementProcessor.class ); doThrow( error ).when( statementProcessor ).streamResult( any() ); connectionState.setStatementProcessor( statementProcessor ); BoltStateMachineState nextState = state.process( PullAllMessage.INSTANCE, context ); assertEquals( failedState, nextState ); verify( context ).handleFailure( error, true ); }
@Test void shouldHandleErrorWhenProcessingPullAllMessage() throws Exception { RuntimeException error = new RuntimeException( "Hello" ); StatementProcessor statementProcessor = mock( StatementProcessor.class ); doThrow( error ).when( statementProcessor ).streamResult( any() ); connectionState.setStatementProcessor( statementProcessor ); BoltStateMachineState nextState = state.process( PullAllMessage.INSTANCE, context ); assertEquals( failedState, nextState ); verify( context ).handleFailure( error, false ); }
@Test void shouldProcessDiscardAllMessage() throws Exception { StatementProcessor statementProcessor = mock( StatementProcessor.class ); connectionState.setStatementProcessor( statementProcessor ); BoltStateMachineState nextState = state.process( DiscardAllMessage.INSTANCE, context ); assertEquals( readyState, nextState ); verify( statementProcessor ).streamResult( any() ); }
@Test void shouldHandleAuthErrorWhenProcessingDiscardAllMessage() throws Exception { AuthorizationExpiredException error = new AuthorizationExpiredException( "Hello" ); StatementProcessor statementProcessor = mock( StatementProcessor.class ); doThrow( error ).when( statementProcessor ).streamResult( any() ); connectionState.setStatementProcessor( statementProcessor ); BoltStateMachineState nextState = state.process( DiscardAllMessage.INSTANCE, context ); assertEquals( failedState, nextState ); verify( context ).handleFailure( error, true ); }
@Test void shouldHandleErrorWhenProcessingDiscardAllMessage() throws Exception { RuntimeException error = new RuntimeException( "Hello" ); StatementProcessor statementProcessor = mock( StatementProcessor.class ); doThrow( error ).when( statementProcessor ).streamResult( any() ); connectionState.setStatementProcessor( statementProcessor ); BoltStateMachineState nextState = state.process( DiscardAllMessage.INSTANCE, context ); assertEquals( failedState, nextState ); verify( context ).handleFailure( error, false ); }
@Test void shouldProcessResetMessage() throws Exception { when( context.resetMachine() ).thenReturn( true ); BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( readyState, newState ); }
@Test void shouldHandleResetMessageFailure() throws Exception { when( context.resetMachine() ).thenReturn( false ); BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( failedState, newState ); }
@Test void shouldProcessInterruptMessage() throws Exception { BoltStateMachineState newState = state.process( InterruptSignal.INSTANCE, context ); assertEquals( interruptedState, newState ); }
@Test void shouldNotProcessUnsupportedMessages() throws Exception { List<RequestMessage> unsupportedMessages = asList( AckFailureMessage.INSTANCE, new RunMessage( "RETURN 1", EMPTY_MAP ), new InitMessage( "Driver 2.5", emptyMap() ) ); for ( RequestMessage message : unsupportedMessages ) { assertNull( state.process( message, context ) ); } }