public void testOutboundOffHook() throws IllegalStateException { phoneStateMachine.onOffhook(); assertTrue(phoneStateMachine.isOutboundOffhook()); /* * 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.isOutboundOffhook()); boolean exceptionOccured = false; try { phoneStateMachine.onRing(); } catch (IllegalStateException e) { // The phone cannot ring while off-hook! exceptionOccured = true; } assertTrue(exceptionOccured); assertTrue(phoneStateMachine.isOutboundOffhook()); phoneStateMachine.onIdle(); assertTrue(phoneStateMachine.isIdle()); }
/** Test whether isIdle returns true only on cases where it should be true */ public void testIsIdle() { phoneStateMachine.onRing(); assertFalse(phoneStateMachine.isIdle()); phoneStateMachine.onOffhook(); assertFalse(phoneStateMachine.isIdle()); phoneStateMachine.onIdle(); assertTrue(phoneStateMachine.isIdle()); phoneStateMachine.onOffhook(); assertFalse(phoneStateMachine.isIdle()); }