### Question:
LicenseChecker { public boolean checkLicenseAcceptance() { if (!accepted) { debug.log("License not yet accepted."); user.tell(MSG_LICENSE_HEADER); try { licensePresenter.presentLicenses(accepted); accepted = true; debug.log("License agreement accepted by user."); } catch (MissingLicenseException ex) { debug.log("License file not found: " + ex.getLicenseName()); user.tell(MSG_ERROR_NO_LICENSE_FILE); throw ex; } catch (LicenseRejectedException ex) { accepted = false; debug.log("User rejected license: " + ex.getRejectedLicense().getFilename()); } } else { debug.log("License already accepted by the user"); } return accepted; } @Inject  LicenseChecker(LicenseLocator locator, LicenseLog log, User user, DebugLog debug); boolean checkLicenseAcceptance();  }### Answer:
@Test public void shouldDisplayLicenseHeader() { given(mockLocator.getRequiredLicenses()).willReturn(new LicenseSet(Collections.<License>emptyList())); checker.checkLicenseAcceptance(); verify(mockUser).tell(LicenseChecker.MSG_LICENSE_HEADER); }
@Test public void shouldPresentLicensesWhenNotAlreadyAccepted() { checker.checkLicenseAcceptance(); verify(mockUser).show(license.getLicenseText()); }
@Test public void shouldReportFailureIfLicenseRejected() { given(mockUser.ask("prompt")).willReturn("n"); boolean accepted = checker.checkLicenseAcceptance(); assertFalse(accepted); }
@Test public void shouldReportSuccessIfLicenseAccepted() { given(mockUser.ask("prompt")).willReturn("y"); boolean accepted = checker.checkLicenseAcceptance(); assertTrue(accepted); }
@Test public void shouldNotPromptIfLicensesAlreadyAccepted() { given(mockUser.ask("prompt")).willReturn("y"); checker.checkLicenseAcceptance(); given(mockUser.ask("prompt")).willThrow(new AssertionError()); boolean accepted = checker.checkLicenseAcceptance(); assertTrue(accepted); }
@Test public void shouldRecordLicenseAcceptance() { given(mockUser.ask("prompt")).willReturn("y"); checker.checkLicenseAcceptance(); license.accept(); verify(mockLog).logLicenseAccepted(eq(license), eq(USER), any(Date.class)); }
@Test public void shouldNotPromptIfLicenseAcceptanceRecorded() { given(mockLog.isLicenseAccepted(license, USER)).willReturn(true); boolean accepted = checker.checkLicenseAcceptance(); assertTrue(accepted); }
@Test public void shouldNotLogIfUsernameIsNull() { given(mockUser.getName()).willReturn(null); checker = new LicenseChecker(mockLocator, mockLog, mockUser, mockDebug); checker.checkLicenseAcceptance(); verifyZeroInteractions(mockLog); }
@Test public void shouldNotLogIfUsernameIsEmpty() { given(mockUser.getName()).willReturn(" "); checker = new LicenseChecker(mockLocator, mockLog, mockUser, mockDebug); checker.checkLicenseAcceptance(); verifyZeroInteractions(mockLog); }