Randall Gibson Jr před 6 roky
rodič
revize
8c5969f709

+ 20
- 0
pom.xml Zobrazit soubor

@@ -7,6 +7,26 @@
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>
22
+    <dependencies>
23
+        <dependency>
24
+            <groupId>junit</groupId>
25
+            <artifactId>junit</artifactId>
26
+            <version>RELEASE</version>
27
+            <scope>test</scope>
28
+        </dependency>
29
+    </dependencies>
10 30
 
11 31
 
12 32
 </project>

+ 62
- 0
src/main/java/com/zipcoder/payment/Check.java Zobrazit soubor

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

+ 68
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Zobrazit soubor

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

+ 48
- 0
src/main/java/com/zipcoder/payment/PayPal.java Zobrazit soubor

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

+ 9
- 0
src/main/java/com/zipcoder/payment/Payment.java Zobrazit soubor

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

+ 33
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java Zobrazit soubor

@@ -1,6 +1,39 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import java.util.Arrays;
4
+import java.util.Comparator;
5
+
3 6
 public class PaymentPresenter {
4 7
 
5 8
 
9
+    public String toString(Payment[] payments) {
10
+        StringBuilder sb = new StringBuilder();
11
+        Arrays.sort(payments);
12
+
13
+        for (int i = 0; i < payments.length; i++) {
14
+
15
+            sb.append(payments[i].getShortDescription() + "\n");
16
+        }
17
+
18
+        return sb.toString();
19
+    }
20
+
21
+    public String toStringByPayerName(Payment[] payments) {
22
+        StringBuilder sb = new StringBuilder();
23
+        Arrays.sort(payments, new PaymentSortByPayer());
24
+        for (int i = 0; i < payments.length; i++) {
25
+            sb.append(payments[i].getShortDescription() + "\n");
26
+        }
27
+        return sb.toString();
28
+    }
29
+
30
+    public String toStringById(Payment[] payments) {
31
+        StringBuilder sb = new StringBuilder();
32
+        Arrays.sort(payments, Comparator.comparing(Payment::getId));
33
+
34
+        for (int i = 0; i < payments.length; i++) {
35
+            sb.append(payments[i].getShortDescription() + "\n");
36
+        }
37
+        return sb.toString();
38
+    }
6 39
 }

+ 10
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Zobrazit soubor

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

+ 97
- 0
src/test/java/com/zipcoder/payment/CheckTest.java Zobrazit soubor

@@ -0,0 +1,97 @@
1
+package com.zipcoder.payment;
2
+import org.junit.Assert;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+import static org.junit.Assert.assertEquals;
7
+
8
+public class CheckTest {
9
+
10
+    Check check;
11
+    Check check2;
12
+
13
+    @Before
14
+    public void setup() {
15
+        check = new Check();
16
+        check2 = new Check();
17
+    }
18
+    @Test
19
+    public void getIdTest() {
20
+
21
+        check.setId(1234L);
22
+        check2.setId(3456L);
23
+
24
+        Long expected = 1234L;
25
+        Long actual = check.getId();
26
+
27
+        assertEquals(expected, actual);
28
+    }
29
+
30
+    @Test
31
+    public void getPayNameTest() {
32
+
33
+        check2.setPayerName("Money");
34
+        check.setPayerName("Lucky");
35
+        String expected = "Lucky";
36
+
37
+        String actual = check.getPayerName();
38
+
39
+        assertEquals(expected, actual);
40
+    }
41
+
42
+    @Test
43
+    public void getRoutingNumber() {
44
+
45
+        check2.setRoutingNumber("5678");
46
+        check.setRoutingNumber("1234");
47
+        String expected = "1234";
48
+        String actual = check.getRoutingNumber();
49
+
50
+        assertEquals(expected, actual);
51
+    }
52
+
53
+    @Test
54
+    public void getAccountNumber() {
55
+
56
+
57
+        check2.setAccountNumber("52000");
58
+        check.setAccountNumber("52820");
59
+        String expected = "52820";
60
+        String actual = check.getAccountNumber();
61
+
62
+        assertEquals(expected, actual);
63
+    }
64
+
65
+    //    Check Tia Mowry ***4551
66
+    @org.junit.Test
67
+    public void getShortDescription() {
68
+
69
+        check2.setPayerName("Tia Mowry");
70
+        check2.setRoutingNumber("5678");
71
+        check2.setAccountNumber("52000");
72
+        check.setPayerName("Randall Gibson");
73
+        check.setRoutingNumber("1234");
74
+        check.setAccountNumber("52820");
75
+        String expected = "check Randall Gibson ***2820";
76
+        String actual = check.getShortDescription();
77
+
78
+        Assert.assertEquals(expected, actual);
79
+
80
+    }
81
+    @Test
82
+    public void compareToTest(){
83
+
84
+        check2.setPayerName("Tia Mowry");
85
+        check2.setRoutingNumber("5678");
86
+        check2.setAccountNumber("52000");
87
+        check.setPayerName("Randall Gibson");
88
+        check.setRoutingNumber("1234");
89
+        check.setAccountNumber("52820");
90
+
91
+
92
+        int actual = check.compareTo(check2);
93
+
94
+        Assert.assertTrue(actual < 0);
95
+    }
96
+
97
+}

+ 113
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java Zobrazit soubor

@@ -0,0 +1,113 @@
1
+package com.zipcoder.payment;
2
+import org.junit.Assert;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+import static org.junit.Assert.*;
7
+
8
+public class CreditCardTest {
9
+    CreditCard credit;
10
+    CreditCard credit2;
11
+
12
+    @Before
13
+    public void setup() {
14
+        credit = new CreditCard();
15
+        credit2 = new CreditCard();
16
+
17
+    }
18
+    @org.junit.Test
19
+    public void getIdTest() {
20
+        CreditCard creditCard = new CreditCard();
21
+        CreditCard credit2 = new CreditCard();
22
+
23
+
24
+        creditCard.setId(1234L);
25
+
26
+        Long expected = 1234L;
27
+        Long actual = creditCard.getId();
28
+
29
+        assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void getNumberTest() {
34
+
35
+        credit2.setNumber("4567891011");
36
+        credit.setNumber("123456789");
37
+        String expected="123456789";
38
+        String actual = credit.getNumber();
39
+        Assert.assertEquals(expected,actual);
40
+}
41
+    @org.junit.Test
42
+    public void getPayerName(){
43
+
44
+        credit2.setPayerName("Tia Mowry");
45
+        credit.setPayerName("Randall Gibson");
46
+        String expected = "Randall Gibson";
47
+
48
+        String actual = credit.getPayerName();
49
+
50
+        assertEquals(expected,actual);
51
+    }
52
+
53
+    @org.junit.Test
54
+    public void getShortDescription() {
55
+
56
+        credit2.setPayerName("Tia Mowry");
57
+        credit2.setExpiredYear(2020);
58
+        credit2.setExpiredMonth(11);
59
+        credit2.setNumber("4567891011");
60
+        credit.setPayerName("Randall Gibson");
61
+        credit.setExpiredYear(2019);
62
+        credit.setExpiredMonth(10);
63
+        credit.setNumber("123456789");
64
+        String expected= "CC Randall Gibson 6789 10/2019";
65
+        String actual= credit.getShortDescription();
66
+
67
+        Assert.assertEquals(expected,actual);
68
+    }
69
+
70
+    @org.junit.Test
71
+    public void getExpiredMonth(){
72
+
73
+        credit2.setExpiredMonth(11);
74
+        credit.setExpiredMonth(10);
75
+
76
+        int expected = 10;
77
+
78
+        int actual = credit.getExpiredMonth();
79
+
80
+        assertEquals(expected,actual);
81
+    }
82
+
83
+    @org.junit.Test
84
+    public void getExpiredYear(){
85
+        credit.setExpiredYear(2020);
86
+        credit.setExpiredYear(2019);
87
+        int expected = 2019;
88
+
89
+        int actual = credit.getExpiredYear();
90
+
91
+        assertEquals(expected,actual);
92
+    }
93
+
94
+    @Test
95
+    public void compareToTest(){
96
+
97
+        credit2.setPayerName("Tia Mowry");
98
+        credit2.setExpiredYear(2020);
99
+        credit2.setExpiredMonth(11);
100
+        credit2.setNumber("4567891011");
101
+        credit.setPayerName("Randall Gibson");
102
+        credit.setExpiredYear(2019);
103
+        credit.setExpiredMonth(10);
104
+        credit.setNumber("123456789");
105
+
106
+
107
+        int actual = credit.compareTo(credit2);
108
+
109
+        Assert.assertTrue(actual < 0);
110
+    }
111
+
112
+
113
+}

+ 81
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java Zobrazit soubor

@@ -0,0 +1,81 @@
1
+package com.zipcoder.payment;
2
+import org.junit.Assert;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+import static org.junit.Assert.assertEquals;
7
+
8
+public class PayPalTest {
9
+
10
+    PayPal paypal;
11
+    PayPal paypal2;
12
+
13
+@Before
14
+public void setup(){
15
+    paypal = new PayPal();
16
+    paypal2 = new PayPal();
17
+}
18
+    @Test
19
+    public void getIdTest() {
20
+        paypal2.setId(2345L);
21
+        paypal.setId(1234L);
22
+
23
+        Long expected = 1234L;
24
+        Long actual = paypal.getId();
25
+
26
+        assertEquals(expected, actual);
27
+    }
28
+
29
+    @Test
30
+    public void getPayerName() {
31
+
32
+        paypal.setPayerName("Randall");
33
+        paypal2.setPayerName("Tia");
34
+        String expected = "Randall";
35
+        String actual = paypal.getPayerName();
36
+
37
+        assertEquals(expected, actual);
38
+
39
+    }
40
+
41
+    @Test
42
+    public void getEmail() {
43
+
44
+
45
+        paypal.setEmail("Rgibs@gmail");
46
+        paypal2.setEmail("tia@mowry");
47
+        String expected = "Rgibs@gmail";
48
+        String actual = paypal.getEmail();
49
+
50
+        assertEquals(expected, actual);
51
+    }
52
+
53
+    @org.junit.Test
54
+    public void getShortDescription() {
55
+
56
+        paypal2.setPayerName("Tia Mowry");
57
+        paypal.setPayerName("Randall Gibson");
58
+        paypal.setEmail("ran@gibs.com");
59
+        paypal2.setEmail("tia@mowry");
60
+        String expected = "Paypal Randall Gibson ran@gibs.com";
61
+        String actual = paypal.getShortDescription();
62
+
63
+        Assert.assertEquals(expected, actual);
64
+
65
+    }
66
+
67
+    @Test
68
+    public void compareToTest() {
69
+
70
+        paypal2.setPayerName("Tia Mowry");
71
+        paypal.setPayerName("Randall Gibson");
72
+        paypal.setEmail("ran@gibs.com");
73
+        paypal2.setEmail("tia@mowry");
74
+
75
+
76
+        int actual = paypal.compareTo(paypal2);
77
+
78
+        Assert.assertTrue(actual < 0);
79
+
80
+    }
81
+}

+ 70
- 0
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Zobrazit soubor

@@ -1,4 +1,74 @@
1 1
 package com.zipcoder.payment;
2
+import com.zipcoder.payment.PaymentPresenter;
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import static org.junit.Assert.assertEquals;
2 7
 
3 8
 public class PaymentPresenterTest {
9
+
10
+    @Test
11
+    public void toStringNoPayment(){
12
+        Payment[] payments = new Payment[0];
13
+        PaymentPresenter presenter = new PaymentPresenter();
14
+        String expected = "";
15
+
16
+        String actual = presenter.toString(payments);
17
+
18
+        Assert.assertEquals(expected, actual);
19
+
20
+    }
21
+
22
+    @Test
23
+    public void toStringMultiple(){
24
+        Payment[] payments = new Payment[2];
25
+        Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
26
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
27
+
28
+        payments[0] = paypal;
29
+        payments[1] = check;
30
+
31
+
32
+        PaymentPresenter presenter = new PaymentPresenter();
33
+        String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
34
+
35
+        String actual = presenter.toString(payments);
36
+        Assert.assertEquals(expected, actual);
37
+
38
+    }
39
+
40
+    @Test
41
+    public void toStringByPayerName(){
42
+
43
+        Payment[] payments = new Payment[2];
44
+        Payment paypal = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
45
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
46
+
47
+        payments[0] = paypal;
48
+        payments[1] = check;
49
+
50
+        PaymentPresenter presenter = new PaymentPresenter();
51
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
52
+
53
+        String actual = presenter.toStringByPayerName(payments);
54
+        assertEquals(expected, actual);
55
+    }
56
+
57
+    @Test
58
+    public void toStringById(){
59
+
60
+        Payment[] payments = new Payment[2];
61
+        Payment paypal = new PayPal(81L, "Tamara Mowry", "tamara@mowry.com");
62
+        Payment check = new Check(120, "Tia Mowry", "11432543", "134344551");
63
+
64
+        payments[0] = paypal;
65
+        payments[1] = check;
66
+        PaymentPresenter presenter = new PaymentPresenter();
67
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
68
+
69
+        String actual = presenter.toStringById(payments);
70
+        assertEquals(expected, actual);
71
+    }
4 72
 }
73
+
74
+

+ 40
- 0
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java Zobrazit soubor

@@ -0,0 +1,40 @@
1
+package com.zipcoder.payment;
2
+import org.junit.Assert;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+import static org.junit.Assert.*;
7
+
8
+public class PaymentSortByPayerTest {
9
+
10
+    CreditCard credit2;
11
+    Check check;
12
+    PaymentSortByPayer test;
13
+
14
+
15
+    @Before
16
+    public void setUp() {
17
+        credit2 = new CreditCard();
18
+        check = new Check();
19
+        test = new PaymentSortByPayer();
20
+    }
21
+
22
+    @Test
23
+    public void CompareTest(){
24
+        credit2.setPayerName("Tia Mowry");
25
+        credit2.setExpiredYear(2020);
26
+        credit2.setExpiredMonth(11);
27
+        credit2.setNumber("4567891011");
28
+
29
+        check.setPayerName("Randall Gibson");
30
+        check.setRoutingNumber("1234");
31
+        check.setAccountNumber("52820");
32
+
33
+        int actual = test.compare(check,credit2);
34
+
35
+        Assert.assertTrue(actual <0);
36
+
37
+
38
+
39
+        }
40
+    }