PaymentPresenterTest.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.zipcoder.payment;
  2. import org.junit.Test;
  3. import static org.junit.Assert.assertEquals;
  4. public class PaymentPresenterTest {
  5. @Test
  6. public void toStringWhenNoPaymentTest() {
  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 toStringWhenMultiplePaymentTest() {
  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(81L, "Tamara Mowry", "tamara@mowry.com");
  41. Payment check = new Check(120L, "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. }