-
-
Save jasongorman/2de7f6a1569f711398c911ff44439e48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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