Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created April 5, 2019 08:50
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/5b69336cedf211ac5d38bd4791d65c4f to your computer and use it in GitHub Desktop.
Save jasongorman/5b69336cedf211ac5d38bd4791d65c4f to your computer and use it in GitHub Desktop.
class BuyCdTest {
@Test
void buyCdPaymentAccepted() {
int stock = 10;
double price = 9.99;
String creditCardNumber = "1234";
Payments payments = new PaymentsStub(PaymentResponse.ACCEPTED);
stock = buy(stock, price, creditCardNumber, payments);
assertEquals(9, stock );
}
private int buy(int stock, double price, String creditCardNumber, Payments payments) {
if(payments.process(price, creditCardNumber) == PaymentResponse.ACCEPTED)
stock--;
return stock;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment