#24 Seth-Abrams

Offen
Seth-Abrams möchte 7 Commits von Seth-Abrams/InterfaceComparableLab:master nach master zusammenführen

+ 8
- 0
pom.xml Datei anzeigen

@@ -7,6 +7,14 @@
7 7
     <groupId>com.zipcoder</groupId>
8 8
     <artifactId>payment</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+    </dependencies>
10 18
     <properties>
11 19
         <maven.compiler.source>1.8</maven.compiler.source>
12 20
         <maven.compiler.target>1.8</maven.compiler.target>

+ 60
- 0
src/main/java/com/zipcoder/payment/Check.java Datei anzeigen

@@ -0,0 +1,60 @@
1
+package com.zipcoder.payment;
2
+
3
+public class Check implements Payment {
4
+    long id;
5
+    String payerName;
6
+    String routingNumber;
7
+    String accountNumber;
8
+
9
+    public Check(long id, String payerName, String routingNumber, String accountNumber) {
10
+        this.id = id;
11
+        this.payerName = payerName;
12
+        this.routingNumber = routingNumber;
13
+        this.accountNumber = accountNumber;
14
+    }
15
+
16
+    public long getId() {
17
+        return id;
18
+    }
19
+
20
+    public void setId(long id) {
21
+        this.id = id;
22
+    }
23
+
24
+    public String getPayerName() {
25
+        return payerName;
26
+    }
27
+
28
+    public void setPayerName(String payerName) {
29
+        this.payerName = payerName;
30
+    }
31
+
32
+    public String getRoutingNumber() {
33
+        return routingNumber;
34
+    }
35
+
36
+    public void setRoutingNumber(String routingNumber) {
37
+        this.routingNumber = routingNumber;
38
+    }
39
+
40
+    public String getAccountNumber() {
41
+        return accountNumber;
42
+    }
43
+
44
+    public void setAccountNumber(String accountNumber) {
45
+        this.accountNumber = accountNumber;
46
+    }
47
+
48
+    public String getLastFourDigits(String number) {
49
+        int length = number.length();
50
+        return number.substring(length - 4, length);
51
+    }
52
+
53
+    public String getShortDescription() {
54
+        return "Check " + payerName + " ***" + getLastFourDigits(accountNumber);
55
+    }
56
+
57
+    public int compareTo(Payment payment2) {
58
+        return this.getShortDescription().compareTo(payment2.getShortDescription());
59
+    }
60
+}

+ 50
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Datei anzeigen

@@ -0,0 +1,50 @@
1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment {
4
+    long id;
5
+    String payerName;
6
+    String number;
7
+    int expiredMonth;
8
+    int expiredYear;
9
+
10
+    public CreditCard(int id, String payerName, String number, int expiredMonth, int expiredYear) {
11
+        this.id = id;
12
+        this.payerName = payerName;
13
+        this.number = number;
14
+        this.expiredMonth = expiredMonth;
15
+        this.expiredYear = expiredYear;
16
+    }
17
+
18
+    public long getId() { return id; }
19
+
20
+    public void setId(long id) { this.id = id; }
21
+
22
+    public String getPayerName() { return payerName; }
23
+
24
+    public void setPayerName(String payerName) { this.payerName = payerName; }
25
+
26
+    public String getNumber() { return number; }
27
+
28
+    public void setNumber(String number) { this.number = number; }
29
+
30
+    public int getExpiredMonth() { return expiredMonth; }
31
+
32
+    public void setExpiredMonth(int expiredMonth) { this.expiredMonth = expiredMonth; }
33
+
34
+    public int getExpiredYear() { return expiredYear; }
35
+
36
+    public void setExpiredYear(int expiredYear) { this.expiredYear = expiredYear; }
37
+
38
+    public String getLastFourDigits(String number) {
39
+        int length = number.length();
40
+        return number.substring(length - 4, length);
41
+    }
42
+
43
+    public String getShortDescription() {
44
+        return "CC " + payerName + " " + getLastFourDigits(number) + " " + expiredMonth + "/" + expiredYear;
45
+    }
46
+
47
+    public int compareTo(Payment payment2) {
48
+        return this.getShortDescription().compareTo(payment2.getShortDescription());
49
+    }
50
+}

+ 45
- 0
src/main/java/com/zipcoder/payment/PayPal.java Datei anzeigen

@@ -0,0 +1,45 @@
1
+package com.zipcoder.payment;
2
+
3
+public class PayPal implements Payment{
4
+    long id;
5
+    String payerName;
6
+    String email;
7
+
8
+    public PayPal(long id, String payerName, String email) {
9
+        this.id = id;
10
+        this.payerName = payerName;
11
+        this.email = email;
12
+    }
13
+
14
+    public long getId() {
15
+        return id;
16
+    }
17
+
18
+    public void setId(long id) {
19
+        this.id = id;
20
+    }
21
+
22
+    public String getPayerName() {
23
+        return payerName;
24
+    }
25
+
26
+    public void setPayerName(String payerName) {
27
+        this.payerName = payerName;
28
+    }
29
+
30
+    public String getEmail() {
31
+        return email;
32
+    }
33
+
34
+    public void setEmail(String email) {
35
+        this.email = email;
36
+    }
37
+
38
+    public String getShortDescription() {
39
+        return "PayPal " + payerName + " " +email;
40
+    }
41
+
42
+    public int compareTo(Payment payment2) {
43
+        return this.getShortDescription().compareTo(payment2.getShortDescription());
44
+    }
45
+}

+ 11
- 0
src/main/java/com/zipcoder/payment/Payment.java Datei anzeigen

@@ -0,0 +1,11 @@
1
+package com.zipcoder.payment;
2
+
3
+public interface Payment extends Comparable<Payment>{
4
+
5
+    public long getId();
6
+
7
+    public String getPayerName();
8
+
9
+    public String getShortDescription();
10
+
11
+}

+ 4
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java Datei anzeigen

@@ -1,6 +1,10 @@
1 1
 package com.zipcoder.payment;
2 2
 
3 3
 public class PaymentPresenter {
4
+    public PaymentPresenter() {
5
+
6
+    }
7
+
4 8
 
5 9
 
6 10
 }

+ 10
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Datei anzeigen

@@ -0,0 +1,10 @@
1
+package com.zipcoder.payment;
2
+
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.getPayerName().compareTo(payment2.getPayerName());
9
+    }
10
+}

+ 82
- 0
src/test/java/com/zipcoder/payment/CheckTest.java Datei anzeigen

@@ -0,0 +1,82 @@
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 CheckTest {
8
+    Check testCheck;
9
+    CreditCard otherPayment;
10
+
11
+    @Before
12
+    public void initialize() {
13
+        testCheck = new Check(100, "Karen Paige", "124567", "7654321");
14
+        otherPayment = new CreditCard(10, "John Hurt", "0043783590454335", 03,2020);
15
+    }
16
+
17
+    @Test
18
+    public void getSetIdTest() {
19
+        long expected = 10000;
20
+        testCheck.setId(10000);
21
+
22
+        long actual = testCheck.getId();
23
+
24
+        Assert.assertEquals(expected, actual);
25
+    }
26
+
27
+    @Test
28
+    public void getSetPayerNameTest() {
29
+        String expected = "Karen";
30
+        testCheck.setPayerName("Karen");
31
+
32
+        String actual = testCheck.getPayerName();
33
+
34
+        Assert.assertEquals(expected, actual);
35
+    }
36
+
37
+    @Test
38
+    public void getSetRoutingNumberTest() {
39
+        String expected = "1234567";
40
+        testCheck.setRoutingNumber("1234567");
41
+
42
+        String actual = testCheck.getRoutingNumber();
43
+
44
+        Assert.assertEquals(expected, actual);
45
+    }
46
+
47
+    @Test
48
+    public void getSetAccountNumberTest() {
49
+        String expected = "7654321";
50
+        testCheck.setAccountNumber("7654321");
51
+
52
+        String actual = testCheck.getAccountNumber();
53
+
54
+        Assert.assertEquals(expected, actual);
55
+    }
56
+
57
+    @Test
58
+    public void getLastFourDigitsTest() {
59
+        String expected = "4556";
60
+        String fullNumber = "230598904556";
61
+
62
+        String actual = testCheck.getLastFourDigits(fullNumber);
63
+
64
+        Assert.assertEquals(expected, actual);
65
+
66
+    }
67
+
68
+    @Test
69
+    public void getShortDescriptionTest() {
70
+        String expected = "Check Karen Paige ***4321";
71
+        String actual = testCheck.getShortDescription();
72
+
73
+        Assert.assertEquals(expected, actual);
74
+    }
75
+
76
+    @Test
77
+    public void compareToTest() {
78
+        int actual = testCheck.compareTo(otherPayment);
79
+
80
+        Assert.assertTrue(actual > 0);
81
+    }
82
+}

+ 99
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java Datei anzeigen

@@ -0,0 +1,99 @@
1
+package com.zipcoder.payment;
2
+
3
+
4
+import org.junit.Assert;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+public class CreditCardTest {
9
+    CreditCard testCard;
10
+    PayPal otherPayment;
11
+    Check otherPayment2;
12
+
13
+
14
+    @Before
15
+    public void initialize() {
16
+        testCard = new CreditCard(10, "John Hurt", "0043783590454335", 03,2020);
17
+        otherPayment =new PayPal(15,"Momo Hashimoto", "kawaii54@line.com");
18
+
19
+    }
20
+
21
+    @Test
22
+    public void getSetIdTest() {
23
+        long expected = 100;
24
+        testCard.setId(100);
25
+        long actual = testCard.getId();
26
+
27
+        Assert.assertEquals(expected, actual);
28
+
29
+    }
30
+
31
+    @Test
32
+    public void getSetPayerNameTest() {
33
+        String expected = "Bob";
34
+        testCard.setPayerName("Bob");
35
+
36
+        String actual = testCard.getPayerName();
37
+
38
+        Assert.assertEquals(expected, actual);
39
+
40
+    }
41
+
42
+    @Test
43
+    public void getSetNumberTest() {
44
+        String expected = "4536";
45
+        testCard.setNumber("4536");
46
+
47
+        String actual = testCard.getNumber();
48
+
49
+        Assert.assertEquals(expected, actual);
50
+    }
51
+
52
+    @Test
53
+    public void getSetExpiredMonthTest() {
54
+        int expected = 10;
55
+        testCard.setExpiredMonth(10);
56
+
57
+        int actual = testCard.getExpiredMonth();
58
+
59
+        Assert.assertEquals(expected, actual);
60
+
61
+    }
62
+
63
+    @Test
64
+    public void getSetExpiredYearTest() {
65
+        int expected = 2021;
66
+        testCard.setExpiredYear(2021);
67
+
68
+        int actual = testCard.getExpiredYear();
69
+
70
+        Assert.assertEquals(expected, actual);
71
+    }
72
+
73
+    @Test
74
+    public void getLastFourDigitsTest() {
75
+        String expected = "4556";
76
+        String fullNumber = "230598904556";
77
+
78
+        String actual = testCard.getLastFourDigits(fullNumber);
79
+
80
+        Assert.assertEquals(expected, actual);
81
+
82
+    }
83
+
84
+    @Test
85
+    public void getShortDescriptionTest() {
86
+        String expected = "CC John Hurt 4335 3/2020";
87
+        String actual = testCard.getShortDescription();
88
+
89
+        Assert.assertEquals(expected, actual);
90
+    }
91
+
92
+    @Test
93
+    public void compareToTest() {
94
+        int actual = testCard.compareTo(otherPayment);
95
+
96
+        Assert.assertTrue(actual < 0);
97
+
98
+    }
99
+}

+ 63
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java Datei anzeigen

@@ -0,0 +1,63 @@
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 PayPalTest {
8
+    PayPal testPal;
9
+    Check otherPayment;
10
+
11
+
12
+    @Before
13
+    public void initialization() {
14
+        testPal = new PayPal(15,"Momo Hashimoto", "kawaii54@line.com");
15
+        otherPayment = new Check(100, "Karen Paige", "124567", "7654321");
16
+
17
+    }
18
+    @Test
19
+    public void getSetIdTest() {
20
+        long expected = 100;
21
+        testPal.setId(100);
22
+        long actual = testPal.getId();
23
+
24
+        Assert.assertEquals(expected, actual);
25
+
26
+    }
27
+
28
+    @Test
29
+    public void getSetPayerNameTest() {
30
+        String expected = "Sara";
31
+        testPal.setPayerName("Sara");
32
+
33
+        String actual = testPal.getPayerName();
34
+
35
+        Assert.assertEquals(expected, actual);
36
+    }
37
+
38
+    @Test
39
+    public void getSetEmail() {
40
+        String expected = "godot@gmail.com";
41
+        testPal.setEmail("godot@gmail.com");
42
+
43
+        String actual = testPal.getEmail();
44
+
45
+        Assert.assertEquals(expected, actual);
46
+    }
47
+
48
+    @Test
49
+    public void getShortDescriptionTest() {
50
+        String expected = "PayPal Momo Hashimoto kawaii54@line.com";
51
+        String actual = testPal.getShortDescription();
52
+
53
+        Assert.assertEquals(expected, actual);
54
+    }
55
+
56
+    @Test
57
+    public void compareToTest() {
58
+        int actual = testPal.compareTo(otherPayment);
59
+
60
+
61
+        Assert.assertTrue(actual > 0);
62
+    }
63
+}

+ 29
- 0
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Datei anzeigen

@@ -1,4 +1,33 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
3 6
 public class PaymentPresenterTest {
7
+
8
+    @Test
9
+    public void toStringEmptyTest() {
10
+        Payment[] payments = new Payment[0];
11
+        PaymentPresenter presenter = new PaymentPresenter();
12
+        String expected = "";
13
+
14
+        String actual = presenter.toString(payments);
15
+
16
+        Assert.assertEquals(expected, actual);
17
+    }
18
+//    @Test
19
+//    public void toStringTest() {
20
+//        Payment[] payments = new Payment[2];
21
+//        Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
22
+//        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
23
+//
24
+//        payments[0] = paypal;
25
+//        payments[1] = check;
26
+//
27
+//        PaymentPresenter presenter = new PaymentPresenter();
28
+//        String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
29
+//
30
+//        String actual = presenter.toString(payments);
31
+//        Assert.assertEquals(expected, actual);
32
+//    }
4 33
 }

+ 44
- 0
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java Datei anzeigen

@@ -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,"Zach 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
+}