소스 검색

made it through

Chad 8 년 전
부모
커밋
f3cdfead43

+ 8
- 0
pom.xml 파일 보기

@@ -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
 
11 19
 
12 20
 </project>

+ 55
- 0
src/main/java/com/zipcoder/payment/Check.java 파일 보기

@@ -0,0 +1,55 @@
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 void setId(Long id) {
10
+        this.id = id;
11
+    }
12
+
13
+    public void setPayerName(String payerName) {
14
+        this.payerName = payerName;
15
+    }
16
+
17
+    public String getRoutingNumber() {
18
+        return routingNumber;
19
+    }
20
+
21
+    public void setRoutingNumber(String routingNumber) {
22
+        this.routingNumber = routingNumber;
23
+    }
24
+
25
+    public String getAccountNumber() {
26
+        return accountNumber;
27
+    }
28
+
29
+    public void setAccountNumber(String accountNumber) {
30
+        this.accountNumber = accountNumber;
31
+    }
32
+
33
+    public Check(Long id, String payerName, String routingNumber, String accountNumber){
34
+        this.id = id;
35
+        this.payerName = payerName;
36
+        this.routingNumber = routingNumber;
37
+        this.accountNumber = accountNumber;
38
+    }
39
+
40
+    public String getShortDescription() {
41
+        return "Check "+ payerName+" ***"+ accountNumber.substring(accountNumber.length()-4,accountNumber.length());
42
+    }
43
+
44
+    public Long getId() {
45
+        return id;
46
+    }
47
+
48
+    public String getPayerName() {
49
+        return payerName;
50
+    }
51
+
52
+    public int compareTo(Payment o) {
53
+        return this.getShortDescription().compareTo(o.getShortDescription());
54
+    }
55
+}

+ 66
- 0
src/main/java/com/zipcoder/payment/CreditCard.java 파일 보기

@@ -0,0 +1,66 @@
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(Long 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
+
19
+    public void setId(long id) {
20
+        this.id = id;
21
+    }
22
+
23
+    public void setPayerName(String payerName) {
24
+        this.payerName = payerName;
25
+    }
26
+
27
+    public String getNumber() {
28
+        return number;
29
+    }
30
+
31
+    public void setNumber(String number) {
32
+        this.number = number;
33
+    }
34
+
35
+    public int getExpiredMonth() {
36
+        return expiredMonth;
37
+    }
38
+
39
+    public void setExpiredMonth(int expiredMonth) {
40
+        this.expiredMonth = expiredMonth;
41
+    }
42
+
43
+    public int getExpiredYear() {
44
+        return expiredYear;
45
+    }
46
+
47
+    public void setExpiredYear(int expiredYear) {
48
+        this.expiredYear = expiredYear;
49
+    }
50
+
51
+    public Long getId() {
52
+        return id;
53
+    }
54
+
55
+    public String getPayerName() {
56
+        return payerName;
57
+    }
58
+
59
+    public String getShortDescription() {
60
+        return "CC "+ payerName+" "+ number.substring(number.length()-4,number.length())+" "+expiredMonth+"/"+expiredYear;
61
+    }
62
+
63
+    public int compareTo(Payment o) {
64
+        return this.getShortDescription().compareTo(o.getShortDescription());
65
+    }
66
+}

+ 9
- 0
src/main/java/com/zipcoder/payment/Payment.java 파일 보기

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

+ 37
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java 파일 보기

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

+ 14
- 0
src/main/java/com/zipcoder/payment/PaymentSortById.java 파일 보기

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

+ 13
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java 파일 보기

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

+ 46
- 0
src/main/java/com/zipcoder/payment/Paypal.java 파일 보기

@@ -0,0 +1,46 @@
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
+
15
+    public void setId(Long id) {
16
+        this.id = id;
17
+    }
18
+
19
+    public void setPayerName(String payerName) {
20
+        this.payerName = payerName;
21
+    }
22
+
23
+    public String getEmail() {
24
+        return email;
25
+    }
26
+
27
+    public void setEmail(String email) {
28
+        this.email = email;
29
+    }
30
+
31
+    public String getShortDescription() {
32
+        return "Paypal "+ payerName+" "+email;
33
+    }
34
+
35
+    public Long getId() {
36
+        return id;
37
+    }
38
+
39
+    public String getPayerName() {
40
+        return payerName;
41
+    }
42
+
43
+    public int compareTo(Payment o) {
44
+        return this.getShortDescription().compareTo(o.getShortDescription());
45
+    }
46
+}

+ 56
- 0
src/test/java/com/zipcoder/payment/CheckTest.java 파일 보기

@@ -0,0 +1,56 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class CheckTest {
7
+    Check test = new Check(1L,"Chad","12 34 5678", "1234567890");
8
+    Check test1 = new Check(2L,"brad","98 76 5432","0987654321");
9
+    @Test
10
+    public void getIdTest(){
11
+
12
+        long expected= 1;
13
+        long actual= test.getId();
14
+        Assert.assertEquals(expected,actual);
15
+    }
16
+
17
+    @Test
18
+    public void getPayerNameTest(){
19
+
20
+        String expected= "Chad";
21
+        String actual= test.getPayerName();
22
+        Assert.assertEquals(expected,actual);
23
+    }
24
+
25
+    @Test
26
+    public void getroutingNumberTest(){
27
+
28
+        String expected= "12 34 5678";
29
+        String actual= test.getRoutingNumber();
30
+        Assert.assertEquals(expected,actual);
31
+    }
32
+
33
+    @Test
34
+    public void getAccountNumberTest(){
35
+
36
+        String expected= "1234567890";
37
+        String actual= test.getAccountNumber();
38
+        Assert.assertEquals(expected,actual);
39
+    }
40
+
41
+    @Test
42
+    public void getShortDesrciptionTest(){
43
+
44
+        String expected= "Check Chad ***7890";
45
+        String actual= test.getShortDescription();
46
+        Assert.assertEquals(expected,actual);
47
+    }
48
+
49
+    @Test
50
+    public void compareToTest(){
51
+
52
+        int expected= 1;
53
+        int actual= test.getShortDescription().compareTo(test1.getShortDescription());
54
+        Assert.assertTrue(actual<expected);
55
+    }
56
+}

+ 66
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java 파일 보기

@@ -0,0 +1,66 @@
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 CreditCardTest {
8
+    CreditCard test = new CreditCard(1L,"chad","123456789",1,2020);
9
+    CreditCard test1 = new CreditCard(2L,"brad","987654321",2,2021);
10
+
11
+    @Test
12
+    public void getIdTest(){
13
+
14
+        Long expected= 1L;
15
+        Long actual= test.getId();
16
+        Assert.assertEquals(expected,actual);
17
+    }
18
+
19
+    @Test
20
+    public void getPayerNameTest(){
21
+
22
+        String expected= "chad";
23
+        String actual= test.getPayerName();
24
+        Assert.assertEquals(expected,actual);
25
+    }
26
+
27
+    @Test
28
+    public void getNumberTest(){
29
+
30
+        String expected= "123456789";
31
+        String actual= test.getNumber();
32
+        Assert.assertEquals(expected,actual);
33
+    }
34
+
35
+    @Test
36
+    public void getExpiredMonthTest(){
37
+
38
+        int expected= 1;
39
+        int actual= test.getExpiredMonth();
40
+        Assert.assertEquals(expected,actual);
41
+    }
42
+
43
+    @Test
44
+    public void getExpiredYearTest(){
45
+
46
+        int expected= 2020;
47
+        int actual= test.getExpiredYear();
48
+        Assert.assertEquals(expected,actual);
49
+    }
50
+
51
+    @Test
52
+    public void getShortDesrciptionTest(){
53
+
54
+        String expected= "CC chad 6789 1/2020";
55
+        String actual= test.getShortDescription();
56
+        Assert.assertEquals(expected,actual);
57
+    }
58
+
59
+    @Test
60
+    public void compareToTest(){
61
+
62
+        int expected= 1;
63
+        int actual= test.getShortDescription().compareTo(test1.getShortDescription());
64
+        Assert.assertEquals(expected,actual);
65
+    }
66
+}

+ 64
- 0
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java 파일 보기

@@ -1,4 +1,68 @@
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 toStringNoPaymentTest() {
10
+
11
+        Payment[] payments = new Payment[0];
12
+        PaymentPresenter presenter = new PaymentPresenter();
13
+        String expected = "";
14
+
15
+        String actual = presenter.toString(payments);
16
+
17
+        Assert.assertEquals(expected, actual);
18
+    }
19
+
20
+    @Test
21
+    public void toStringMultiplePaymentTest() {
22
+        Payment[] payments = new Payment[2];
23
+        Payment paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
24
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
25
+
26
+        payments[0] = paypal;
27
+        payments[1] = check;
28
+
29
+        PaymentPresenter presenter = new PaymentPresenter();
30
+        String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
31
+
32
+        String actual = presenter.toString(payments);
33
+        Assert.assertEquals(expected, actual);
34
+    }
35
+
36
+    @Test
37
+    public void toStringByPayerNameMultiplePaymentTest() {
38
+        Payment[] payments = new Payment[2];
39
+        Payment paypal = new Paypal(4L, "Tamara Mowry", "tamara@mowry.com");
40
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
41
+
42
+        payments[0] = paypal;
43
+        payments[1] = check;
44
+
45
+        PaymentPresenter presenter = new PaymentPresenter();
46
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
47
+
48
+        String actual = presenter.toStringByPayerName(payments);
49
+        Assert.assertEquals(expected, actual);
50
+    }
51
+
52
+    @Test
53
+    public void toStringByIdMultiplePaymentTest() {
54
+    Payment[] payments = new Payment[2];
55
+    Payment paypal = new Paypal(81L, "Tamara Mowry", "tamara@mowry.com");
56
+    Payment check = new Check(120L, "Tia Mowry", "11432543", "134344551");
57
+
58
+    payments[0]=paypal;
59
+    payments[1]=check;
60
+
61
+    PaymentPresenter presenter = new PaymentPresenter();
62
+    String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
63
+
64
+    String actual = presenter.toStringById(payments);
65
+
66
+    Assert.assertEquals(expected, actual);
67
+}
4 68
 }

+ 19
- 0
src/test/java/com/zipcoder/payment/PaymentSortByIdTest.java 파일 보기

@@ -0,0 +1,19 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PaymentSortByIdTest {
7
+    CreditCard test2 = new CreditCard(1L,"chad","123456789",1,2020);
8
+    Check test1 = new Check(2L,"brad","98 76 5432","0987654321");
9
+    PaymentSortByPayer test = new PaymentSortByPayer();
10
+    @Test
11
+    public void compareTest(){
12
+
13
+        int expected= 1;
14
+        int actual= test.compare(test1,test2);
15
+        Assert.assertTrue(actual<expected);
16
+    }
17
+}
18
+
19
+

+ 18
- 0
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java 파일 보기

@@ -0,0 +1,18 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PaymentSortByPayerTest {
7
+
8
+    CreditCard test2 = new CreditCard(1L,"chad","123456789",1,2020);
9
+    Check test1 = new Check(2L,"brad","98 76 5432","0987654321");
10
+    PaymentSortByPayer test = new PaymentSortByPayer();
11
+    @Test
12
+    public void compareTest(){
13
+
14
+        int expected= 1;
15
+        int actual= test.compare(test1,test2);
16
+        Assert.assertTrue(actual<expected);
17
+    }
18
+}

+ 48
- 0
src/test/java/com/zipcoder/payment/PaypalTest.java 파일 보기

@@ -0,0 +1,48 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PaypalTest {
7
+    Paypal test = new Paypal(1L,"Chad Hallinan","hallinanc@susqu.edu");
8
+    Paypal test1 = new Paypal(2L,"brad","bradbrobrill");
9
+    @Test
10
+    public void getIdTest(){
11
+
12
+        long expected= 1;
13
+        long actual= test.getId();
14
+        Assert.assertEquals(expected,actual);
15
+    }
16
+
17
+    @Test
18
+    public void getPayerNameTest(){
19
+
20
+        String expected= "Chad Hallinan";
21
+        String actual= test.getPayerName();
22
+        Assert.assertEquals(expected,actual);
23
+    }
24
+
25
+    @Test
26
+    public void getEmailTest(){
27
+
28
+        String expected= "hallinanc@susqu.edu";
29
+        String actual= test.getEmail();
30
+        Assert.assertEquals(expected,actual);
31
+    }
32
+
33
+    @Test
34
+    public void getShortDesrciptionTest(){
35
+
36
+        String expected= "Paypal Chad Hallinan hallinanc@susqu.edu";
37
+        String actual= test.getShortDescription();
38
+        Assert.assertEquals(expected,actual);
39
+    }
40
+
41
+    @Test
42
+    public void compareToTest(){
43
+
44
+        int expected= 1;
45
+        int actual= test.getShortDescription().compareTo(test1.getShortDescription());
46
+        Assert.assertTrue(actual<expected);
47
+    }
48
+}