CompareToTest.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. package com.zipcoder.payment;
  2. import org.junit.Assert;
  3. import org.junit.Test;
  4. public class CompareToTest {
  5. PayPal pal = new PayPal(001L,"Tia Mowry","tia@moury.com");
  6. Check check = new Check(002L,"Tia Mowry","987-9999-9999","333444" );
  7. CreditCard cc = new CreditCard(003L,"Tia Mowry","890-8700-9999",
  8. 12,1999);
  9. @Test
  10. public void testCompareTo2Paypal(){
  11. //given
  12. PayPal pal1 = new PayPal();
  13. pal1.setPayerName("Evangelina H");
  14. pal1.setEmail("evangelila@h.com");
  15. int expected=-15;
  16. //when
  17. pal1.getShortDescription();
  18. pal.getShortDescription();
  19. //then
  20. Assert.assertEquals(expected, pal1.compareTo(pal));
  21. }
  22. @Test
  23. public void testCompareTo2PaypalReverse(){
  24. //given
  25. PayPal pal1 = new PayPal();
  26. pal1.setPayerName("Evangelina H");
  27. pal1.setEmail("evangelila@h.com");
  28. int expected=15;
  29. //when
  30. pal1.getShortDescription();
  31. pal.getShortDescription();
  32. //then
  33. Assert.assertEquals(expected, pal.compareTo(pal1));
  34. }
  35. @Test
  36. public void testCompareToPayPal1() {
  37. //given
  38. int expected = 0;
  39. //when
  40. pal.getShortDescription();
  41. Assert.assertEquals(expected, pal.compareTo(pal));
  42. }
  43. @Test
  44. public void testCompareToPaypa2() {
  45. //given
  46. int expected = 13;
  47. //when
  48. pal.getShortDescription();
  49. check.getShortDescription();
  50. Assert.assertEquals(expected, pal.compareTo(check));
  51. }
  52. @Test
  53. public void testCompareToPaypal3() {
  54. //given
  55. int expected = 13;
  56. //when
  57. pal.getShortDescription();
  58. cc.getShortDescription();
  59. Assert.assertEquals(expected, pal.compareTo(cc));
  60. }
  61. @Test
  62. public void testCompareTo2Check() {
  63. //given
  64. Check check1 = new Check(001L,"Kevin Hart",
  65. "123-4567-8909", "777888");
  66. int expected = 9;
  67. //when
  68. check.getShortDescription();
  69. check1.getShortDescription();
  70. Assert.assertEquals(expected, check.compareTo(check1));
  71. }
  72. @Test
  73. public void testCompareTo2CheckReverse() {
  74. //given
  75. Check check1 = new Check(002L,"Kevin Hart",
  76. "123-4567-8909","998899");
  77. int expected = -9;
  78. //when
  79. check.getShortDescription();
  80. check1.getShortDescription();
  81. Assert.assertEquals(expected, check1.compareTo(check));
  82. }
  83. @Test
  84. public void testCompareToCheck1() {
  85. //given
  86. int expected = 0;
  87. //when
  88. check.getShortDescription();
  89. Assert.assertEquals(expected, check.compareTo(check));
  90. }
  91. @Test
  92. public void testCompareToCheck2() {
  93. //given
  94. int expected = -13;
  95. //when
  96. pal.getShortDescription();
  97. check.getShortDescription();
  98. Assert.assertEquals(expected, check.compareTo(pal));
  99. }
  100. @Test
  101. public void testCompareToCheck3() {
  102. //given
  103. int expected = -10;
  104. //when
  105. check.getShortDescription();
  106. cc.getShortDescription();
  107. Assert.assertEquals(expected, check.compareTo(cc));
  108. }
  109. @Test
  110. public void testCompareTo2Card() {
  111. //given
  112. CreditCard cc1= new CreditCard(002L,"Dina r",
  113. "999-9890-8898",
  114. 04,
  115. 1999);
  116. int expected = 16;
  117. //when
  118. cc.getShortDescription();
  119. cc1.getShortDescription();
  120. Assert.assertEquals(expected, cc.compareTo(cc1));
  121. }
  122. @Test
  123. public void testCompareTo2CardReverse() {
  124. //given
  125. CreditCard cc1= new CreditCard(004L,"Dina r",
  126. "999-9890-8898",
  127. 04,
  128. 1999);
  129. int expected = -16;
  130. //when
  131. cc.getShortDescription();
  132. cc1.getShortDescription();
  133. Assert.assertEquals(expected, cc1.compareTo(cc));
  134. }
  135. @Test
  136. public void testCompareToCard1() {
  137. //given
  138. int expected = 0;
  139. //when
  140. cc.getShortDescription();
  141. Assert.assertEquals(expected, cc.compareTo(cc));
  142. }
  143. @Test
  144. public void testCompareToCard2() {
  145. //given
  146. int expected = -13;
  147. //when
  148. cc.getShortDescription();
  149. pal.getShortDescription();
  150. Assert.assertEquals(expected, cc.compareTo(pal));
  151. }
  152. @Test
  153. public void testCompareToCard3() {
  154. //given
  155. int expected = 10;
  156. //when
  157. cc.getShortDescription();
  158. check.getShortDescription();
  159. Assert.assertEquals(expected, cc.compareTo(check));
  160. }
  161. }