Lock down Room and Employee behavior with JUnit | Workbook p.68
Now that Room and Employee have real behavior, write JUnit tests that prove they work the way you expect — and keep working as the code changes.
For RoomTest, write tests that exercise checkIn(), checkout(), and cleanRoom(). How many tests do you need? Think about the edge cases: should you be able to check in to a room that's already occupied? Or one that's still dirty? Should housekeeping be able to clean a room while a guest is in it?
For EmployeeTest, test that punchIn(int) stores the start time, and that punchOut(int) calculates hours worked correctly. Skip the no-arg overloads — those depend on the current time and are hard to test reliably.
checkIn() on a fresh, clean Room, what should be true afterwards?checkout(), what changes? What stays the same?hoursWorked equal?cleanRoom() — is that a problem or a no-op?Names only — you write the body. Each name reads like a one-line spec: what method, in what state, expecting what?
methodUnderTest_StateUnderTest_ExpectedBehavior reads like a tiny spec at a glance. Other styles work too — shouldDoX_whenY, given_when_then, plain English — just don't mix them inside one project. When a test fails, the name should tell you exactly what broke without opening the file.
Workbook 4a, p.68 — Module 3, Exercise 1: hotel-operations Unit Tests