Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created April 10, 2021 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/2de7f6a1569f711398c911ff44439e48 to your computer and use it in GitHub Desktop.
Save jasongorman/2de7f6a1569f711398c911ff44439e48 to your computer and use it in GitHub Desktop.
public interface Payments {
Boolean process(double amount, CreditCard card);
}
public class BuyCdTest {
private Payments payments;
private CompactDisc cd;
private CreditCard card;
@Before
public void setUp() {
payments = mock(Payments.class);
when(payments.process(any(), any())).thenReturn(true); // payment accepted
cd = new CompactDisc(10, 9.99);
card = new CreditCard(
"MR P SQUIRE",
"1234234534564567",
"10/24",
567);
}
@Test
public void saleIsSuccessful(){
cd.buy(1, card);
assertEquals(9, cd.getStock());
}
@Test
public void cardIsChargedCorrectAmount(){
cd.buy(2, card);
verify(payments).process(19.98, card);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment