@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 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 to_dot() { StateMachine atm = new ATMStateMachine(); System.out.println("DOT notation for ATM:"); System.out.println(atm.toDot(false)); // Force the composite state to active state for producing DOT notation of the composite state atm.activeStateConfiguration(Arrays.asList(SERVING_CUSTOMER, AUTHENTICATION)); System.out.println("DOT notation for Composite state ServingCustomer:"); System.out.println(((CompositeState) atm.getActiveState()).toDot(false)); }