StateMachine { public synchronized void nextState(T nextState){ if(null != mCurrentState) mCurrentState.exitingState(); mCurrentState = nextState; nextState.enteringState(); }  synchronized void nextState(T nextState); synchronized void finish(T finalState); synchronized T getCurrentState();  }
@Test public void firstState_lifecycleMethodsCalled() { StateMachine.State mockedState = Mockito.mock(StateMachine.State.class); mStateStateMachine.nextState(mockedState); Mockito.verify(mockedState).enteringState(); }
@Test public void singleStateTransition_callBothStateTransitionMethods() { StateMachine.State firstMockedState = Mockito.mock(StateMachine.State.class); StateMachine.State secondMockedState = Mockito.mock(StateMachine.State.class); InOrder inOrder = Mockito.inOrder(firstMockedState, secondMockedState); mStateStateMachine.nextState(firstMockedState); inOrder.verify(firstMockedState).enteringState(); mStateStateMachine.nextState(secondMockedState); inOrder.verify(firstMockedState).exitingState(); inOrder.verify(secondMockedState).enteringState(); }