Raymond Farria před 8 roky
rodič
revize
e979b3038f

+ 19
- 0
pom.xml Zobrazit soubor

7
     <groupId>com.zipcoder</groupId>
7
     <groupId>com.zipcoder</groupId>
8
     <artifactId>payment</artifactId>
8
     <artifactId>payment</artifactId>
9
     <version>1.0-SNAPSHOT</version>
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>1.8</source>
17
+                    <target>1.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
+        </dependency>
28
+    </dependencies>
10
 
29
 
11
 
30
 
12
 </project>
31
 </project>

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

1
+package com.zipcoder.payment;
2
+
3
+public class Check implements Payment{
4
+    private Long ID;
5
+    private String payerName;
6
+    private String routingNumber;
7
+    private String accountNumber;
8
+
9
+    public Check(Long ID, String payerName, String routingNumber, String accountNumber){
10
+
11
+    }
12
+
13
+    public Long getID(){
14
+        return ID;}
15
+
16
+    public String getPayerName(){
17
+        return payerName;}
18
+
19
+    public String getShortDescription(){
20
+        return "Check Tia Mowry ***4551";}
21
+
22
+    public void setID(Long ID) {
23
+        this.ID = ID;
24
+    }
25
+
26
+    public void setPayerName(String payerName) {
27
+        this.payerName = payerName;
28
+    }
29
+
30
+    public String getRoutingNumber() {
31
+        return routingNumber;
32
+    }
33
+
34
+    public void setRoutingNumber(String routingNumber) {
35
+        this.routingNumber = routingNumber;
36
+    }
37
+
38
+    public String getAccountNumber() {
39
+        return accountNumber;
40
+    }
41
+
42
+    public void setAccountNumber(String accountNumber) {
43
+        this.accountNumber = accountNumber;
44
+    }
45
+
46
+    public int compareTo(Payment o) {
47
+        return this.getShortDescription().compareTo(o.getShortDescription());
48
+    }
49
+
50
+    public String toString(){
51
+        return getShortDescription();
52
+    }
53
+}

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

1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment {
4
+    private Long ID;
5
+    private String payerName;
6
+    private String number;
7
+    private int expiredMonth;
8
+    private int expiredYear;
9
+
10
+
11
+    public Long getID() {
12
+        return this.ID;
13
+    }
14
+
15
+    public void setId(Long ID) {
16
+        this.ID = ID;
17
+    }
18
+
19
+    public String getShortDescription() {
20
+        return "CC Tia Mowry 4551 10/2019";
21
+    }
22
+
23
+    public String getPayerName() {
24
+        return payerName;
25
+    }
26
+
27
+    public void setPayerName(String payerName) {
28
+        this.payerName = payerName;
29
+    }
30
+
31
+    public String getNumber() {
32
+        return number;
33
+    }
34
+
35
+    public void setNumber(String number) {
36
+        this.number = number;
37
+    }
38
+
39
+    public int getExpiredMonth() {
40
+        return expiredMonth;
41
+    }
42
+
43
+    public void setExpiredMonth(int expiredMonth) {
44
+        this.expiredMonth = expiredMonth;
45
+    }
46
+
47
+    public int getExpiredYear() {
48
+        return expiredYear;
49
+    }
50
+
51
+    public void setExpiredYear(int expiredYear) {
52
+        this.expiredYear = expiredYear;
53
+    }
54
+
55
+    public int compareTo(Payment o) {
56
+        return this.getShortDescription().compareTo(o.getShortDescription());
57
+    }
58
+}

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

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

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

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
+import java.util.Arrays;
4
+import java.util.List;
5
+import java.util.stream.Collectors;
6
+
3
 public class PaymentPresenter {
7
 public class PaymentPresenter {
4
 
8
 
5
 
9
 
10
+
11
+    public String toString(Payment[] payment) {
12
+
13
+        StringBuilder sTemp = new StringBuilder();
14
+        if(payment.length > 0){
15
+            String [] temp = getShortDescriptions(payment);
16
+
17
+            for (String aTemp : temp) {
18
+                sTemp.append(aTemp + "\n");
19
+            }
20
+            Arrays.sort(temp);
21
+        }
22
+        return sTemp.toString();
23
+    }
24
+
25
+    public String [] getShortDescriptions(Payment [] payment){
26
+        String [] shorties = new String[payment.length];
27
+        for (int i = 0; i < payment.length; i++){
28
+            shorties[i] = payment[i].getShortDescription();
29
+        }
30
+        return shorties;
31
+    }
32
+
33
+
34
+    public String toStringByPayerName(Payment[] payment) {
35
+        return Arrays.stream(payment)
36
+                .map(Payment::getShortDescription)
37
+                .collect(Collectors.joining("\n"));
38
+
39
+    }
40
+
41
+    public String toStringById(Payment[] payment) {
42
+        return Arrays.stream(payment)
43
+                .map(Payment::getShortDescription)
44
+                .collect(Collectors.joining("\n"));
45
+
46
+
47
+
48
+    }
6
 }
49
 }

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

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 o1, Payment o2) {
8
+        return o1.compareTo(o2);
9
+    }
10
+}
11
+

+ 44
- 0
src/main/java/com/zipcoder/payment/Paypal.java Zobrazit soubor

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

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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import static org.junit.Assert.*;
7
+
8
+public class CheckTest {
9
+
10
+    @Test
11
+    public void getID() {
12
+        Check cc = new Check(81L, "Tia Mowry", "11432543", "134344551");
13
+        cc.setID(200L);
14
+        Long expected = 200L;
15
+        Long actual = cc.getID();
16
+
17
+        assertEquals(expected, actual);
18
+    }
19
+
20
+    @Test
21
+    public void getPayerName() {
22
+        Check cc = new Check(81L, "Tia Mowry", "11432543", "134344551");
23
+        cc.setPayerName("Ahmad");
24
+        String expected = "Ahmad";
25
+        String actual = cc.getPayerName();
26
+
27
+        assertEquals(expected, actual);
28
+    }
29
+
30
+    @Test
31
+    public void getShortDescription() {
32
+        Check cc = new Check(81L, "Tia Mowry", "11432543", "134344551");
33
+        String expected = "Check Tia Mowry ***4551";
34
+        String actual = cc.getShortDescription();
35
+        assertEquals(expected, actual);
36
+    }
37
+
38
+    @Test
39
+    public void getRoutingNumber() {
40
+        Check cc = new Check(81L, "Tia Mowry", "11432543", "134344551");
41
+        cc.setRoutingNumber("122334432");
42
+        String expected = "122334432";
43
+        String actual = cc.getRoutingNumber();
44
+
45
+        assertEquals(expected, actual);
46
+    }
47
+
48
+    @Test
49
+    public void getAccountNumber() {
50
+        Check cc = new Check(81L, "Tia Mowry", "11432543", "134344551");
51
+        cc.setAccountNumber("08293963816");
52
+        String expected = "08293963816";
53
+        String actual = cc.getAccountNumber();
54
+        assertEquals(expected, actual);
55
+    }
56
+
57
+    @Test
58
+    public void compareTest1(){
59
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
60
+        int expected = 0;
61
+        int actual = check.getShortDescription().compareTo(check.getShortDescription());
62
+        assertEquals(expected, actual);
63
+    }
64
+
65
+    @Test
66
+    public void compareTest2(){
67
+    Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
68
+    Paypal pay = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
69
+
70
+    int actual = check.getShortDescription().compareTo(pay.getShortDescription());
71
+    assertTrue(actual < 0 );
72
+    }
73
+
74
+    @Test
75
+    public void compareTest3(){
76
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
77
+        CreditCard cc = new CreditCard();
78
+
79
+        int actual = check.getShortDescription().compareTo(cc.getShortDescription());
80
+        assertTrue(actual > 0);
81
+    }
82
+}

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

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 getID() {
11
+      CreditCard cc = new CreditCard();
12
+      cc.setId(200L);
13
+        Long expected = 200L;
14
+        Long actual = cc.getID();
15
+
16
+        assertEquals(expected, actual);
17
+    }
18
+
19
+    @Test
20
+    public void getShortDescription() {
21
+        CreditCard cc = new CreditCard();
22
+        String expected = "CC Tia Mowry 4551 10/2019";
23
+        String actual = cc.getShortDescription();
24
+
25
+        assertEquals(expected, actual);
26
+    }
27
+
28
+    @Test
29
+    public void getPayerName() {
30
+        CreditCard cc = new CreditCard();
31
+        cc.setPayerName("Raymond");
32
+        String expected = "Raymond";
33
+        String actual = cc.getPayerName();
34
+
35
+        assertEquals(expected, actual);
36
+    }
37
+
38
+    @Test
39
+    public void getNumber() {
40
+        CreditCard cc = new CreditCard();
41
+        cc.setNumber("44");
42
+        String expected = "44";
43
+        String actual = cc.getNumber();
44
+
45
+        assertEquals(expected,actual);
46
+    }
47
+
48
+    @Test
49
+    public void getExpiredMonth() {
50
+        CreditCard cc = new CreditCard();
51
+        cc.setExpiredMonth(12);
52
+        int expected = 12;
53
+        int actual = cc.getExpiredMonth();
54
+
55
+        assertEquals(expected, actual);
56
+    }
57
+
58
+    @Test
59
+    public void getExpiredYear() {
60
+        CreditCard cc = new CreditCard();
61
+        cc.setExpiredYear(22);
62
+        int expected = 22;
63
+        int actual = cc.getExpiredYear();
64
+
65
+        assertEquals(expected, actual);
66
+    }
67
+
68
+    @Test
69
+    public void compareTest1(){
70
+        CreditCard cc = new CreditCard();
71
+        int expected = 0;
72
+        int actual = cc.getShortDescription().compareTo(cc.getShortDescription());
73
+
74
+        assertEquals(expected, actual);
75
+    }
76
+
77
+    @Test
78
+    public void compareTest2(){
79
+        CreditCard cc = new CreditCard();
80
+        Paypal pay = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
81
+        int actual = cc.getShortDescription().compareTo(pay.getShortDescription());
82
+
83
+        assertTrue(actual < 0);
84
+    }
85
+
86
+    @Test
87
+    public void compareTest3(){
88
+        CreditCard cc = new CreditCard();
89
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
90
+        int actual = cc.getShortDescription().compareTo(check.getShortDescription());
91
+
92
+        assertTrue(actual < 0);
93
+    }
94
+}

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

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

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

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 comparePaypal() {
11
+        PaymentSortByPayer payment = new PaymentSortByPayer();
12
+        Paypal pay = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
13
+        int expected = 0;
14
+        int actual = payment.compare(pay, pay);
15
+
16
+        assertEquals(expected, actual);
17
+    }
18
+
19
+    @Test
20
+    public void compareCC() {
21
+        PaymentSortByPayer payment = new PaymentSortByPayer();
22
+        CreditCard cc = new CreditCard();
23
+        int expected = 0;
24
+        int actual = payment.compare(cc,cc);
25
+
26
+        assertEquals(expected,actual);
27
+    }
28
+
29
+    @Test
30
+    public void compareCheck() {
31
+        PaymentSortByPayer payment = new PaymentSortByPayer();
32
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
33
+        int expected = 0;
34
+        int actual = payment.compare(check, check);
35
+
36
+        assertEquals(expected, actual);
37
+    }
38
+
39
+    @Test
40
+    public void compare1(){
41
+        PaymentSortByPayer payment = new PaymentSortByPayer();
42
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
43
+        Paypal pay = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
44
+        int actual = payment.compare(check, pay);
45
+
46
+        assertTrue(actual < 0);
47
+    }
48
+
49
+    @Test
50
+    public void compare2(){
51
+        PaymentSortByPayer payment = new PaymentSortByPayer();
52
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
53
+        CreditCard cc = new CreditCard();
54
+        int actual = payment.compare(cc,check);
55
+
56
+        assertTrue(actual < 0);
57
+    }
58
+
59
+    @Test
60
+    public void compare3(){
61
+        PaymentSortByPayer payment = new PaymentSortByPayer();
62
+        CreditCard cc = new CreditCard();
63
+        Paypal pay = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
64
+        int actual = payment.compare(pay,cc);
65
+
66
+        assertTrue(actual > 0);
67
+    }
68
+
69
+
70
+}

+ 75
- 0
src/test/java/com/zipcoder/payment/PaypalTest.java Zobrazit soubor

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 getID() {
11
+        Paypal paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
12
+        paypal.setID(5000L);
13
+        Long expected = 5000L;
14
+        Long actual = paypal.getID();
15
+
16
+        assertEquals(expected, actual);
17
+    }
18
+
19
+    @Test
20
+    public void getPayerName() {
21
+        Paypal paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
22
+        paypal.setPayerName("Raymond");
23
+        String expected = "Raymond";
24
+        String actual = paypal.getPayerName();
25
+
26
+        assertEquals(expected, actual);
27
+    }
28
+
29
+    @Test
30
+    public void getShortDescription() {
31
+        Paypal paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
32
+
33
+        String expected = "Paypal Tia Mowry tia@mowry.com";
34
+        String actual = paypal.getShortDescription();
35
+        assertEquals(expected, actual);
36
+    }
37
+
38
+    @Test
39
+    public void getEmail() {
40
+        Paypal paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
41
+        paypal.setEmail("tiamowry@aol.com");
42
+        String expected = "tiamowry@aol.com";
43
+        String actual = paypal.getEmail();
44
+
45
+        assertEquals(expected, actual);
46
+    }
47
+
48
+    @Test
49
+    public void compareTest1(){
50
+        Paypal paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
51
+        int expected = 0;
52
+        int actual = paypal.getShortDescription().compareTo(paypal.getShortDescription());
53
+
54
+        assertEquals(expected, actual);
55
+    }
56
+
57
+    @Test
58
+    public void compareTest2(){
59
+        Paypal paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
60
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
61
+        int actual = paypal.getShortDescription().compareTo(check.getShortDescription());
62
+        assertTrue(actual > 0);
63
+    }
64
+
65
+    @Test
66
+    public void compareTest3(){
67
+        Paypal paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
68
+        CreditCard cc = new CreditCard();
69
+        int actual = paypal.getShortDescription().compareTo(cc.getShortDescription());
70
+
71
+        assertTrue(actual > 0);
72
+    }
73
+
74
+
75
+}