Mexi 8 vuotta sitten
vanhempi
commit
5286829531

+ 2
- 2
src/main/java/com/zipcoder/payment/Check.java Näytä tiedosto

60
     }
60
     }
61
 
61
 
62
     public int compareTo(Payment o) {
62
     public int compareTo(Payment o) {
63
-
64
-        return 0;
63
+        int n = this.getShortDescription().compareTo(o.getShortDescription());
64
+        return n;
65
     }
65
     }
66
 }
66
 }

+ 25
- 3
src/test/java/com/zipcoder/payment/CheckTest.java Näytä tiedosto

8
 public class CheckTest {
8
 public class CheckTest {
9
 
9
 
10
     Check check;
10
     Check check;
11
+
11
     @Before
12
     @Before
12
     public void start(){
13
     public void start(){
13
         check = new Check(12312l, "Jo","33775", "8800");
14
         check = new Check(12312l, "Jo","33775", "8800");
79
     }
80
     }
80
 
81
 
81
     @Test
82
     @Test
82
-    public void compareTo() {
83
-        Check check1 = new Check();
83
+    public void compareToWhenEquals() {
84
+            Check check1 = new Check(123l,"Jo","12345","2233");
85
+            Check check2 = new Check(123l,"Jo","12345","2233");
86
+            Assert.assertTrue(check1.getShortDescription().compareTo(check2.getShortDescription())==0);
87
+
88
+    }
89
+
90
+    @Test
91
+    public void compareToWhenPayment1ComesBeforePayment2() {
92
+        Check check1 = new Check(123l,"Bo","12345","2233");
93
+        Check check2 = new Check(222l,"Jo","11345","2233");
94
+
95
+        Assert.assertTrue(check1.getShortDescription().compareTo(check2.getShortDescription()) < 0);
96
+
97
+    }
98
+    @Test
99
+    public void compareToWhenPayment2ComesBeforePayment1() {
100
+        Check check1 = new Check(123l,"Jo","12345","2233");
101
+        Check check2 = new Check(122l,"Bo","11345","2233");
102
+
103
+        Assert.assertTrue(check1.getShortDescription().compareTo(check2.getShortDescription()) > 0);
104
+
105
+    }
106
+
84
 
107
 
85
     }
108
     }
86
-}
87
 
109
 
88
 
110