@Test public void displayGreeting_showSpecialGreetingOnNewYearsDay() { fakeClock.setTime(NEW_YEARS_DAY); fakeUser.setName("Fake User”); userGreeter.displayGreeting(); // The test will fail if userGreeter.displayGreeting() didn’t call // mockUserPrompter.updatePrompt() with these exact arguments. verify(mockUserPrompter).updatePrompt( "Hi Fake User! Happy New Year!", TitleBar.of("2018-01-01"), PromptStyle.NORMAL); }
@Test public void displayGreeting_showSpecialGreetingOnNewYearsDay() { fakeClock.setTime(NEW_YEARS_DAY); userGreeter.displayGreeting(); verify(mockUserPrompter).updatePrompt(contains("Happy New Year!"), any(), any())); }
@Test public void displayGreeting_renderUserName() { fakeUser.setName(“Fake User”); userGreeter.displayGreeting(); // Focus on the argument relevant to showing the user's name. verify(mockUserPrompter).updatePrompt(contains("Hi Fake User!"), any(), any()); }
TEST_F(BankAccountTest, WithdrawFromAccount) { Transaction transaction = account_.Deposit(Usd(5)); clock_.AdvanceTime(MIN_TIME_TO_SETTLE); account_.Settle(transaction); EXPECT_THAT(account_.Withdraw(Usd(5)), IsOk()); EXPECT_THAT(account_.Withdraw(Usd(1)), IsRejected()); account_.SetOverdraftLimit(Usd(1)); EXPECT_THAT(account_.Withdraw(Usd(1)), IsOk()); }
TEST_F(BankAccountTest, CanWithdrawWithinBalance) { DepositAndSettle(Usd(5)); // Common setup code is extracted into a helper method. EXPECT_THAT(account_.Withdraw(Usd(5)), IsOk()); } TEST_F(BankAccountTest, CannotOverdraw) { DepositAndSettle(Usd(5)); EXPECT_THAT(account_.Withdraw(Usd(6)), IsRejected()); } TEST_F(BankAccountTest, CanOverdrawUpToOverdraftLimit) { DepositAndSettle(Usd(5)); account_.SetOverdraftLimit(Usd(1)); EXPECT_THAT(account_.Withdraw(Usd(6)), IsOk()); }