Seth 7 lat temu
rodzic
commit
ce3e427424

+ 7
- 1
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Wyświetl plik

@@ -1,4 +1,10 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
-public class PaymentSortByPayer {
3
+import java.util.Comparator;
4
+
5
+public class PaymentSortByPayer implements Comparator<Payment> {
6
+
7
+    public int compare(Payment payment1, Payment payment2) {
8
+        return payment1.compareTo(payment2);
9
+    }
4 10
 }

+ 44
- 0
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java Wyświetl plik

@@ -0,0 +1,44 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+public class PaymentSortByPayerTest {
8
+    private PaymentSortByPayer test;
9
+
10
+    @Before
11
+    public void initialize() {
12
+        test =  new PaymentSortByPayer();
13
+    }
14
+
15
+    @Test
16
+    public void compareTest01() {
17
+        Check payment1 = new Check(100,"Aaron Aaronson", "1234567", "764321");
18
+        CreditCard payment2 = new CreditCard(200, "Zach Zachariah", "455555", 5, 2022);
19
+
20
+        int actual = test.compare(payment1, payment2);
21
+
22
+        Assert.assertTrue(actual > 0);
23
+    }
24
+
25
+    @Test
26
+    public void compareTest02() {
27
+        Check payment1 = new Check(300,"Zaron Aaronson", "1234567", "764321");
28
+        PayPal payment2 = new PayPal(15,"Momo Hashimoto", "kawaii54@line.com");
29
+
30
+        int actual = test.compare(payment1, payment2);
31
+
32
+        Assert.assertTrue(actual < 0);
33
+    }
34
+
35
+    @Test
36
+    public void compareTest03() {
37
+        Check payment1 = new Check(300,"Zaron Aaronson", "1234567", "764321");
38
+        Check payment2 = new Check(300,"Zaron Aaronson", "1234567", "764321");
39
+
40
+        int actual = test.compare(payment1, payment2);
41
+
42
+        Assert.assertTrue(actual == 0);
43
+    }
44
+}