Exemplo n.º 1
0
  @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);
  }
Exemplo n.º 2
0
  @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);
  }
Exemplo n.º 3
0
  @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);
  }
Exemplo n.º 4
0
  @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);
  }
Exemplo n.º 5
0
  @Test
  public void simple_state_transfers() {
    // Given
    StateMachine atm = new ATMStateMachine();

    // When
    atm.execute(new TurnedOn());

    // Then
    assertThat(atm.getActiveStateName()).isEqualTo(SELF_TEST);
  }