Explorar el Código

finishing up#

Jason Gibbs hace 6 años
padre
commit
eeaba2302b

BIN
.DS_Store Ver fichero


+ 25
- 0
pom.xml Ver fichero

@@ -7,6 +7,31 @@
7 7
     <groupId>com.zipcoder</groupId>
8 8
     <artifactId>payment</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
23
+    <dependencies>
24
+        <dependency>
25
+            <groupId>junit</groupId>
26
+            <artifactId>junit</artifactId>
27
+            <version>4.12</version>
28
+            <scope>test</scope>
29
+        </dependency>
30
+        <dependency>
31
+            <groupId>com.google.guava</groupId>
32
+            <artifactId>guava</artifactId>
33
+            <version>25.1-jre</version>
34
+        </dependency>
35
+    </dependencies>
11 36
 
12 37
 </project>

BIN
src/.DS_Store Ver fichero


BIN
src/main/.DS_Store Ver fichero


BIN
src/main/java/.DS_Store Ver fichero


BIN
src/main/java/com/.DS_Store Ver fichero


BIN
src/main/java/com/zipcoder/.DS_Store Ver fichero


+ 69
- 0
src/main/java/com/zipcoder/payment/Check.java Ver fichero

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

+ 77
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Ver fichero

@@ -0,0 +1,77 @@
1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment{
4
+    
5
+    private Long id;
6
+    private String payerName;
7
+    private String number;
8
+    private String expiredMonth;
9
+    private String expiredYear;
10
+
11
+    public CreditCard(Long id, String payerName, String number, String expiredMonth, String expiredYear) {
12
+        this.id = id;
13
+        this.payerName = payerName;
14
+        this.number = number;
15
+        this.expiredMonth = expiredMonth;
16
+        this.expiredYear = expiredYear;
17
+    }
18
+
19
+    public void setId(long id) {
20
+        this.id = id;
21
+    }
22
+
23
+    public Long getId() {
24
+        return id;
25
+    }
26
+
27
+    public void setPayerName(String payerName) {
28
+        this.payerName = payerName;
29
+    }
30
+
31
+    public String getPayerName() {
32
+
33
+        return payerName;
34
+    }
35
+
36
+    public String getShortDescription() {
37
+        String lastFour = id.toString().substring(id.toString().length() - 3);
38
+        return "CC" + payerName + lastFour + " " + expiredMonth + "/" + expiredYear + "\n";
39
+    }
40
+    
41
+    public void setNumber(String number) {
42
+        this.number = number;
43
+    }
44
+
45
+    public String getNumber() {
46
+        return number;
47
+    }
48
+
49
+    public void setExpiredMonth(String expiredMonth) {
50
+        this.expiredMonth = expiredMonth;
51
+    }
52
+
53
+    public String getExpiredMonth( ) {
54
+        return this.expiredMonth;
55
+    }
56
+
57
+    public void setExpiredYear(String expiredYear) {
58
+        this.expiredYear = expiredYear;
59
+    }
60
+
61
+    public String getExpiredYear() {
62
+        return expiredYear;
63
+    }
64
+
65
+    public int compareTo(Payment payment) {
66
+        int comparison;
67
+        if (id.compareTo(payment.getId()) == 0) {
68
+            comparison =  0;
69
+        } else if (id.compareTo(payment.getId())  < 0) {
70
+            comparison = -1;
71
+        } else {
72
+            comparison = 1;
73
+        }
74
+            return  comparison;
75
+        }
76
+    }
77
+

+ 17
- 0
src/main/java/com/zipcoder/payment/Main.java Ver fichero

@@ -0,0 +1,17 @@
1
+package com.zipcoder.payment;
2
+
3
+public class Main {
4
+
5
+    public static void main(String[] args) {
6
+
7
+        Payment payPal = new PayPal(500L, "James Jones", "JJ@yahoo.com");
8
+        Payment creditCard = new CreditCard(900L, "Phil Anders", "462008",
9
+                "11", "22");
10
+        Payment check = new Check(234L, "Amy Tuck", "874402", "95720");
11
+
12
+        PaymentPresenter presenter = new PaymentPresenter(payPal, check, creditCard);
13
+        System.out.println(presenter.toStringByPayerName());
14
+        System.out.println(presenter.toStringById());
15
+
16
+    }
17
+}

+ 43
- 0
src/main/java/com/zipcoder/payment/PayPal.java Ver fichero

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

+ 10
- 0
src/main/java/com/zipcoder/payment/Payment.java Ver fichero

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

+ 49
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java Ver fichero

@@ -1,6 +1,55 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import java.lang.reflect.Array;
4
+import java.util.Arrays;
5
+
3 6
 public class PaymentPresenter {
4 7
 
8
+    private Payment[] payments;
9
+
10
+    public PaymentPresenter(Payment payment) {
11
+        payments = new Payment[1];
12
+        payments[0] = payment;
13
+    }
14
+
15
+    public PaymentPresenter(Payment paymentOne, Payment paymentTwo) {
16
+        payments = new Payment[2];
17
+        payments[0] = paymentOne;
18
+        payments[1] = paymentTwo;
19
+    }
20
+
21
+    public PaymentPresenter(Payment paymentOne, Payment paymentTwo, Payment paymentThree) {
22
+        payments = new Payment[3];
23
+        payments[0] = paymentOne;
24
+        payments[1] = paymentTwo;
25
+        payments[2] = paymentThree;
26
+    }
27
+
28
+    public Payment[] getPayments() {
29
+        return payments;
30
+    }
31
+
32
+    public Payment[] sortPayments() {
33
+        Arrays.sort(payments, new PaymentSortByPayer());
34
+        return payments;
35
+    }
36
+
37
+    public String toStringByPayerName() {
38
+        sortPayments();
39
+        String describe = "";
40
+        for (Payment payment : payments) {
41
+            describe += payment.getShortDescription() + "\n";
42
+        }
43
+        return describe;
44
+    }
45
+
5 46
 
47
+    public String toStringById() {
48
+        Arrays.sort(payments, (paymentOne, paymentTwo) -> (int) (paymentOne.getId() - paymentTwo.getId()));
49
+        String describe = "";
50
+        for (Payment payment : payments) {
51
+            describe += payment.getShortDescription();
52
+        }
53
+        return describe;
54
+    }
6 55
 }

+ 18
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Ver fichero

@@ -0,0 +1,18 @@
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 paymentOne, Payment paymentTwo) {
8
+        int comparison;
9
+        if (paymentOne.getPayerName().compareTo(paymentTwo.getPayerName()) == 0) {
10
+            comparison = 0;
11
+        } else if (paymentOne.getPayerName().compareTo(paymentTwo.getPayerName()) < 0) {
12
+            comparison = -1;
13
+        } else {
14
+            comparison = 1;
15
+        }
16
+        return comparison;
17
+    }
18
+}

+ 19
- 0
src/test/java/com/zipcoder/payment/CheckTest.java Ver fichero

@@ -0,0 +1,19 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+import static org.junit.Assert.*;
7
+
8
+public class CheckTest {
9
+
10
+    @Test
11
+    public void compareToTest() {
12
+        Payment c = new Check(500L, "John Jones", "3567280" , "983329");
13
+        Payment second = new Check(700L, "Tom Ryan", "3884625", "447382");
14
+        int expected = -1;
15
+        int actual = c.compareTo(second);
16
+        assertEquals(expected, actual);
17
+    }
18
+
19
+}

+ 100
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java Ver fichero

@@ -0,0 +1,100 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class CreditCardTest {
8
+
9
+    @Test
10
+    public void getIdTest() {
11
+        CreditCard card = new CreditCard(500L, "Ron", "39277","03", "20");
12
+        Long expected = 500L;
13
+        card.setId(expected);
14
+        Long actual = card.getId();
15
+        assertEquals(expected, actual);
16
+    }
17
+
18
+    @Test
19
+    public void setIdTest() {
20
+        CreditCard card = new CreditCard(500L, "Ron", "39277","03", "20");        Long expected = 500L;
21
+        card.setId(expected);
22
+        Long actual = card.getId();
23
+        assertEquals(expected, actual);
24
+    }
25
+
26
+    @Test
27
+    public void getPayerNameTest() {
28
+        CreditCard card = new CreditCard(500L, "Ron", "39277","03", "20");        String expected = "John";
29
+        card.setPayerName(expected);
30
+        String actual = card.getPayerName();
31
+        assertEquals(expected, actual);
32
+    }
33
+
34
+    @Test
35
+    public void setPayerNameTest() {
36
+        CreditCard card = new CreditCard(500L, "Ron", "39277","03", "20");        String expected = "John";
37
+        card.setPayerName(expected);
38
+        String actual = card.getPayerName();
39
+        assertEquals(expected, actual);
40
+    }
41
+
42
+    @Test
43
+    public void getNumberTest() {
44
+        CreditCard card = new CreditCard(500L, "Ron", "39277","03", "20");        String expected = "55724592933";
45
+        card.setNumber(expected);
46
+        String actual = card.getNumber();
47
+        assertEquals(expected, actual);
48
+    }
49
+
50
+    @Test
51
+    public void setNumberTest() {
52
+        CreditCard card = new CreditCard(500L, "Ron", "39277","03", "20");        String expected = "55724592933";
53
+        card.setNumber(expected);
54
+        String actual = card.getNumber();
55
+        assertEquals(expected, actual);
56
+    }
57
+
58
+    @Test
59
+    public void getExpiredMonthTest() {
60
+        CreditCard card = new CreditCard(500L, "Ron", "39277","03", "20");        String expected = "10";
61
+        card.setExpiredMonth("10");
62
+        String actual = card.getExpiredMonth();
63
+        assertEquals(expected, actual);
64
+    }
65
+
66
+    @Test
67
+    public void setExpiredMonthTest() {
68
+        CreditCard card = new CreditCard(500L, "Ron", "39277","03", "20");        String expected = "10";
69
+        card.setExpiredMonth("10");
70
+        String actual = card.getExpiredMonth();
71
+        assertEquals(expected, actual);
72
+    }
73
+
74
+    @Test
75
+    public void getExpiredYearTest() {
76
+        CreditCard card = new CreditCard(500L, "Ron", "39277","03", "20");        String expected = "2021";
77
+        card.setExpiredYear(expected);
78
+        String actual = card.getExpiredYear();
79
+        assertEquals(expected, actual);
80
+
81
+    }
82
+
83
+    @Test
84
+    public void setExpiredYearTest() {
85
+        CreditCard card = new CreditCard(500L, "Ron", "39277","03", "20");        String expected = "2021";
86
+        card.setExpiredYear(expected);
87
+        String actual = card.getExpiredYear();
88
+        assertEquals(expected, actual);
89
+
90
+    }
91
+
92
+    @Test
93
+    public void compareToTest() {
94
+        Payment card = new CreditCard(500L, "Ron", "39277","03", "20");
95
+        Payment second = new CreditCard(700L, "Tom Ryan", "3884625", "10", "18");
96
+        int expected = -1;
97
+        int actual = card.compareTo(second);
98
+        assertEquals(expected, actual);
99
+    }
100
+}

+ 88
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java Ver fichero

@@ -0,0 +1,88 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class PayPalTest {
8
+
9
+    @Test
10
+    public void getIdTest() {
11
+        PayPal payPal = new PayPal(500L, "Roy", "Roy@gmail.com");
12
+        Long expected = 500L;
13
+        payPal.setId(500L);
14
+        Long actual = payPal.getId();
15
+        assertEquals(expected, actual);
16
+
17
+    }
18
+
19
+    @Test
20
+    public void setIdTest() {
21
+        PayPal payPal = new PayPal(500L, "Roy", "Roy@gmail.com");
22
+        Long expected = 500L;
23
+        payPal.setId(500L);
24
+        Long actual = payPal.getId();
25
+        assertEquals(expected, actual);
26
+
27
+    }
28
+
29
+    @Test
30
+    public void getPayerNameTest() {
31
+        PayPal payPal = new PayPal(500L, "Roy", "Roy@gmail.com");
32
+        String expected = "John Jones";
33
+        payPal.setPayerName("John Jones");
34
+        String actual = payPal.getPayerName();
35
+        assertEquals(expected, actual);
36
+
37
+    }
38
+
39
+    @Test
40
+    public void setPayerNameTest() {
41
+        PayPal payPal = new PayPal(500L, "Roy", "Roy@gmail.com");
42
+        String expected = "John Jones";
43
+        payPal.setPayerName("John Jones");
44
+        String actual = payPal.getPayerName();
45
+        assertEquals(expected, actual);
46
+
47
+    }
48
+
49
+    @Test
50
+    public void getEmailTest() {
51
+        PayPal payPal = new PayPal(500L, "Roy", "Roy@gmail.com");
52
+        String expected = "JJones@yahoo.com";
53
+        payPal.setEmail("JJones@yahoo.com");
54
+        String actual = payPal.getEmail();
55
+        assertEquals(expected, actual);
56
+
57
+    }
58
+
59
+    @Test
60
+    public void setEmailTest() {
61
+        PayPal payPal = new PayPal(500L, "Roy", "Roy@gmail.com");
62
+        String expected = "JJones@yahoo.com";
63
+        payPal.setEmail("JJones@yahoo.com");
64
+        String actual = payPal.getEmail();
65
+        assertEquals(expected, actual);
66
+
67
+    }
68
+
69
+    @Test
70
+    public void getShortDescriptionTest() {
71
+        PayPal payPal = new PayPal(500L, "Roy", "Roy@gmail.com");
72
+        payPal.setPayerName("John Jones");
73
+        payPal.setEmail("JJones@yahoo.com");
74
+        String expected = "Paypal " + payPal.getPayerName() + " " + payPal.getEmail();
75
+        String actual = payPal.getShortDescription();
76
+        assertEquals(expected, actual);
77
+    }
78
+
79
+    @Test
80
+    public void compareToTest() {
81
+        Payment c = new PayPal(500L, "John Jones", "3567280");
82
+        Payment second = new PayPal(700L, "Tom Ryan", "3884625");
83
+        int expected = -1;
84
+        int actual = c.compareTo(second);
85
+        assertEquals(expected, actual);
86
+    }
87
+
88
+}

+ 39
- 1
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Ver fichero

@@ -1,4 +1,42 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import org.junit.Test;
4
+
5
+import java.util.Arrays;
6
+
7
+import static org.junit.Assert.*;
8
+
3 9
 public class PaymentPresenterTest {
4
-}
10
+
11
+    @Test
12
+    public void getPaymentsTest() {
13
+    }
14
+
15
+    @Test
16
+    public void sortPaymentsTest() {
17
+    }
18
+
19
+    @Test
20
+    public void toStringByPayerNameTest() {
21
+            Payment paypal = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
22
+            Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
23
+            PaymentPresenter presenter = new PaymentPresenter(paypal, check);
24
+            Arrays.sort(presenter.getPayments(), new PaymentSortByPayer());
25
+
26
+            String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
27
+            String actual = presenter.toStringByPayerName();
28
+            assertEquals(expected, actual);
29
+    }
30
+
31
+    @Test
32
+    public void toStringByIdTest() {
33
+        Payment paypal = new PayPal(90L, "Tamara Mowry", "tamara@mowry.com");
34
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
35
+        PaymentPresenter presenter = new PaymentPresenter(paypal, check);
36
+        Arrays.sort(presenter.getPayments(), new PaymentSortByPayer());
37
+        String expected = "Check Tia Mowry ***4551\nPaypal Tamara Mowry tamara@mowry.com\n";
38
+        String actual = presenter.toStringById();
39
+        assertEquals(expected, actual);
40
+
41
+    }
42
+}

+ 20
- 0
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java Ver fichero

@@ -0,0 +1,20 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class PaymentSortByPayerTest {
8
+
9
+    @Test
10
+    public void compareTest() {
11
+        PaymentSortByPayer payer = new PaymentSortByPayer();
12
+        int expected = 1;
13
+        Payment payPal = new PayPal(500L, "Ron Jones", "RJones@Gmail.com");
14
+        Payment check = new Check(400L, "James L", "456673", "609912");
15
+        int actual = payer.compare(payPal, check);
16
+        assertEquals(expected, actual);
17
+
18
+    }
19
+
20
+}