PaymentPresenterTest.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.zipcoder.payment;
  2. import org.junit.jupiter.api.Test;
  3. import static org.junit.jupiter.api.Assertions.assertEquals;
  4. public class PaymentPresenterTest {
  5. @Test
  6. public void paymentPresenterNoPaymentTest() {
  7. Payment[] payments = new Payment[0];
  8. PaymentPresenter presenter = new PaymentPresenter();
  9. String expected = "";
  10. String actual = presenter.toString(payments);
  11. assertEquals(expected, actual);
  12. }
  13. @Test
  14. public void paymentPresenterMultiplePaymentsTest() {
  15. Payment[] payments = new Payment[2];
  16. Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
  17. Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
  18. payments[0] = paypal;
  19. payments[1] = check;
  20. PaymentPresenter presenter = new PaymentPresenter();
  21. String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
  22. String actual = presenter.toString(payments);
  23. assertEquals(expected, actual);
  24. }
  25. @Test
  26. public void toStringByPayerNameTest() {
  27. Payment[] payments = new Payment[2];
  28. Payment paypal = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
  29. Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
  30. payments[0] = paypal;
  31. payments[1] = check;
  32. PaymentPresenter presenter = new PaymentPresenter();
  33. String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
  34. String actual = presenter.toStringByPayerName(payments);
  35. assertEquals(expected, actual);
  36. }
  37. @Test
  38. public void toStringByIdTest() {
  39. Payment[] payments = new Payment[2];
  40. Payment paypal = new PayPal(120L, "Tamara Mowry", "tamara@mowry.com");
  41. Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
  42. payments[0] = paypal;
  43. payments[1] = check;
  44. PaymentPresenter presenter = new PaymentPresenter();
  45. String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
  46. String actual = presenter.toStringById(payments);
  47. assertEquals(expected, actual);
  48. }
  49. }