### Question:
InterruptedState implements BoltStateMachineState { @Override public BoltStateMachineState process( RequestMessage message, StateMachineContext context ) throws BoltConnectionFatality { assertInitialized(); if ( message instanceof InterruptSignal ) { return this; } else if ( message instanceof ResetMessage ) { if ( context.connectionState().decrementInterruptCounter() > 0 ) { context.connectionState().markIgnored(); return this; } if ( context.resetMachine() ) { context.connectionState().resetPendingFailedAndIgnored(); return readyState; } return failedState; } else { context.connectionState().markIgnored(); return this; } }  @Override BoltStateMachineState process( RequestMessage message, StateMachineContext context ); @Override String name(); void setReadyState( BoltStateMachineState readyState ); void setFailedState( BoltStateMachineState failedState );  }### Answer:
@Test void shouldProcessInterruptMessage() throws Exception { BoltStateMachineState newState = state.process( InterruptSignal.INSTANCE, context ); assertEquals( state, newState ); }
@Test void shouldProcessResetMessageWhenInterrupted() throws Exception { connectionState.incrementInterruptCounter(); connectionState.incrementInterruptCounter(); assertTrue( connectionState.isInterrupted() ); assertFalse( connectionState.hasPendingIgnore() ); BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( state, newState ); assertTrue( connectionState.hasPendingIgnore() ); }
@Test void shouldProcessResetMessage() throws Exception { when( context.resetMachine() ).thenReturn( true ); BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( readyState, newState ); }
@Test void shouldHandleFailureDuringResetMessageProcessing() throws Exception { when( context.resetMachine() ).thenReturn( false ); BoltStateMachineState newState = state.process( ResetMessage.INSTANCE, context ); assertEquals( failedState, newState ); }
@Test void shouldIgnoreMessagesOtherThanInterruptAndReset() throws Exception { List<RequestMessage> messages = asList( AckFailureMessage.INSTANCE, PullAllMessage.INSTANCE, DiscardAllMessage.INSTANCE, new RunMessage( "RETURN 1", EMPTY_MAP ), new InitMessage( "Driver", emptyMap() ) ); for ( RequestMessage message: messages ) { connectionState.resetPendingFailedAndIgnored(); BoltStateMachineState newState = state.process( message, context ); assertEquals( state, newState ); assertTrue( connectionState.hasPendingIgnore() ); } }