Exercise 2: A Corrected Integration Test — Possible Solution ==================================================================== THE FIX ------------------------------ class UserRegistrationServiceFixed: def __init__(self, sender): self.sender = sender self.users = [] def register(self, email): self.users.append(email) self.sender.send(email, "Welcome!", "Thanks for signing up!") # matches the new 3-arg signature return {'email': email, 'registered': True} def test_registration_integration_fixed(): real_sender = RealNotificationSenderV2() service = UserRegistrationServiceFixed(real_sender) result = service.register("frank@example.com") assert service.users == ["frank@example.com"] assert result['registered'] is True return True RESULT ------------------------------ Integration test against RealNotificationSenderV2: PASS The integration test now passes cleanly against the real dependency, confirming the fix rather than merely detecting the original break. WHY THIS WORKS AS AN ANSWER ------------------------------ This closes the loop the chapter opened: an integration test caught the original bug by wiring the real seam together; the same kind of test, run again after the fix, is what actually proves the fix worked - not just that the code compiles, but that the real, unmocked dependency accepts the call without error. This is the same discipline Clean Code, SOLID & Refactoring's own capstone used throughout its own six-step refactor: verify the bug exists with a real reproduction, then verify the same reproduction now succeeds after the fix, using the identical check both times.