PaymentPresenterTest.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.zipcoder.payment;
  2. import org.junit.Assert;
  3. import org.junit.Test;
  4. public class PaymentPresenterTest {
  5. @Test
  6. public void testToStringNoPayment(){
  7. Payment[] payments = new Payment[0];
  8. PaymentPresenter presenter = new PaymentPresenter();
  9. String expected = "";
  10. String actual = presenter.toString(payments);
  11. Assert.assertEquals(expected,actual);
  12. }
  13. @Test
  14. public void testToStringMultiplePayments(){
  15. Payment[] payments = new Payment[2];
  16. Payment paypal = new PayPal("Tia Mowry", "tia@mowry.com");
  17. Payment check = new Check("Tia Mowry", "11432543","134344551");
  18. payments[0] = paypal;
  19. payments[1] = check;
  20. PaymentPresenter presenter = new PaymentPresenter();
  21. String expected = "Check Tia Mowry ****2543\nPaypal Tia Mowry tia@mowry.com\n";
  22. String actual = presenter.toString(payments);
  23. Assert.assertEquals(expected,actual);
  24. }
  25. @Test
  26. public void testToStringByPayerName(){
  27. Payment[] payments = new Payment[2];
  28. Payment paypal = new PayPal("Tamara Mowry", "tamara@mowry.com");
  29. Payment check = new Check("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 ****2543\n";
  34. String actual = presenter.toStringByPayerName(payments);
  35. Assert.assertEquals(expected, actual);
  36. }
  37. @Test
  38. public void testToStringById(){
  39. Payment[] payments = new Payment[2];
  40. Payment paypal = new PayPal("Tamara Mowry", "tamara@mowry.com");
  41. Payment check = new Check("Tia Mowry", "11432543", "134344551");
  42. ((PayPal) paypal).setId(3L);
  43. ((Check) check).setId(1L);
  44. payments[0] = paypal;
  45. payments[1] = check;
  46. PaymentPresenter presenter = new PaymentPresenter();
  47. String expected = "Check Tia Mowry ****2543\nPaypal Tamara Mowry tamara@mowry.com\n";
  48. String actual = presenter.toStringById(payments);
  49. Assert.assertEquals(expected, actual);
  50. }
  51. }