116117118119120121122123124125126127128
} catch (IllegalStateException e) { } } public void testOpenLockedLock() { Door door = new Door(); door.state = Door.OPEN_LOCKED; try { door.lock(); fail("expected exception"); } catch (IllegalStateException e) { } }
126127128129130131132133134135136137138
} catch (IllegalStateException e) { } } public void testOpenLockedClose() { Door door = new Door(); door.state = Door.OPEN_LOCKED; try { door.close(); fail("expected exception"); } catch (IllegalStateException e) { } }
136137138139140141142143144145
} catch (IllegalStateException e) { } } public void testOpenLockedUnlock() { Door door = new Door(); door.state = Door.OPEN_LOCKED; door.unlock(); assertSame(Door.OPEN, door.state); }
5678910111213
import junit.framework.TestCase; public class DoorTest extends TestCase { public void testClosedOpen() { Door door = new Door(); door.open(); assertSame(Door.OPEN, door.state); }
111213141516171819
door.open(); assertSame(Door.OPEN, door.state); } public void testClosedLock() { Door door = new Door(); door.lock(); assertSame(Door.LOCKED, door.state); }
171819202122232425262728
door.lock(); assertSame(Door.LOCKED, door.state); } public void testClosedClose() { Door door = new Door(); try { door.close(); fail("expected exception"); } catch (IllegalStateException e) { } }