public void testInboundOffHook() throws IllegalStateException {
    phoneStateMachine.onRing();

    phoneStateMachine.onOffhook();
    assertTrue(phoneStateMachine.isInboundOffhook());

    /*
     * Although it is very unlikely that an off-hooked phone will be off-hooked again, make sure
     * that the phone stays in the same state.
     */
    phoneStateMachine.onOffhook();
    assertTrue(phoneStateMachine.isInboundOffhook());

    boolean exceptionOccured = false;
    try {
      phoneStateMachine.onRing();
    } catch (IllegalStateException e) {
      // The phone cannot ring while off-hook!
      exceptionOccured = true;
    }

    assertTrue(exceptionOccured);
    assertTrue(phoneStateMachine.isInboundOffhook());

    phoneStateMachine.onIdle();
    assertTrue(phoneStateMachine.isIdle());
  }
  /** Test whether isOutboundOffhook returns true only on cases where it should be true */
  public void testIsOutboundOffhook() {
    assertFalse(phoneStateMachine.isOutboundOffhook());

    phoneStateMachine.onRing();
    assertFalse(phoneStateMachine.isOutboundOffhook());

    phoneStateMachine.onOffhook();
    assertFalse(phoneStateMachine.isOutboundOffhook());

    phoneStateMachine.onIdle();
    assertFalse(phoneStateMachine.isOutboundOffhook());

    phoneStateMachine.onOffhook();
    assertTrue(phoneStateMachine.isOutboundOffhook());
  }
  public void testRinging() throws IllegalStateException {
    phoneStateMachine.onRing();
    assertTrue(phoneStateMachine.isRinging());

    /*
     * Although it is very unlikely that the phone will ring twice in a row, make sure that it still
     * stays on the same state.
     */
    phoneStateMachine.onRing();
    assertTrue(phoneStateMachine.isRinging());

    phoneStateMachine.onIdle();
    assertTrue(phoneStateMachine.isIdle());
  }
 public void testIdleState() throws IllegalStateException {
   phoneStateMachine.onIdle();
   assertTrue(phoneStateMachine.isIdle());
 }
 public void testInitialState() {
   assertTrue(phoneStateMachine.isIdle());
 }