@Test public void from_off_through_idle_back_to_off() { StateMachine atm = new ATMStateMachine(); atm.execute(new TurnedOn()); atm.execute(new TestedOk()); atm.execute(new TurnedOff()); assertThat(atm.getActiveStateName()).isEqualTo(OFF); }
@Test public void from_idle_to_idle_with_transaction() { StateMachine atm = new ATMStateMachine(); atm.activeStateConfiguration(asList(IDLE)); atm.execute(new CardInserted()); atm.execute(new Authenticated()); atm.execute(new TransactionSelected()); assertThat(atm.getActiveStateName()).isEqualTo(IDLE); }
@Test public void load_and_set_active_state_as_a_inner_state() { StateMachine atm = new ATMStateMachine(); atm.activeStateConfiguration(Arrays.asList(SERVING_CUSTOMER, AUTHENTICATION)); atm.execute(new Authenticated()); assertThat(atm.getActiveStateConfiguration()) .containsSequence(SERVING_CUSTOMER, SELECTING_TRANSACTION); }
@Test public void from_idle_to_authentication() { StateMachine atm = new ATMStateMachine(); atm.activeStateConfiguration(asList(IDLE)); atm.execute(new CardInserted()); assertThat(atm.getActiveStateConfiguration()) .containsSequence(SERVING_CUSTOMER, AUTHENTICATION); }
@Test public void simple_state_transfers() { // Given StateMachine atm = new ATMStateMachine(); // When atm.execute(new TurnedOn()); // Then assertThat(atm.getActiveStateName()).isEqualTo(SELF_TEST); }