NiraParikh vor 7 Jahren
Ursprung
Commit
7542a2188d

BIN
.DS_Store Datei anzeigen


+ 8
- 0
pom.xml Datei anzeigen

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
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+    </dependencies>
10
     <properties>
18
     <properties>
11
         <maven.compiler.source>1.8</maven.compiler.source>
19
         <maven.compiler.source>1.8</maven.compiler.source>
12
         <maven.compiler.target>1.8</maven.compiler.target>
20
         <maven.compiler.target>1.8</maven.compiler.target>

BIN
src/.DS_Store Datei anzeigen


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

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

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

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

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

1
+package com.zipcoder.payment;
2
+
3
+public class PayPal implements Payment{
4
+
5
+    public long id;
6
+    String payerName;
7
+    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 setPayerName(String payerName) {
16
+        this.payerName = payerName;
17
+    }
18
+
19
+    public String getEmail() {
20
+        return email;
21
+    }
22
+
23
+    public void setEmail(String email) {
24
+        this.email = email;
25
+    }
26
+
27
+    public void setId(long id) {
28
+        this.id = id;
29
+    }
30
+
31
+    public long getId(){
32
+        return id;
33
+    }
34
+    public String getPayerName(){
35
+        return payerName;
36
+    }
37
+    public  String getShortDescription(){
38
+        return "PayPal" + " " + payerName + " " + email;
39
+
40
+    }
41
+
42
+    public int compareTo(Payment o){
43
+        return this.getShortDescription().compareTo(o.getShortDescription());
44
+    }
45
+
46
+    }
47
+

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

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

+ 57
- 1
src/main/java/com/zipcoder/payment/PaymentPresenter.java Datei anzeigen

2
 
2
 
3
 public class PaymentPresenter {
3
 public class PaymentPresenter {
4
 
4
 
5
+    public String toString(Payment[] payments) {
6
+        Payment temp;
7
+        for (int i = 0; i < payments.length; i++) {
8
+            for (int j = i + 1; j < payments.length; j++) {
9
+                if (payments[i].compareTo(payments[j]) > 0) {
10
+                    temp = payments[j];
11
+                    payments[j] = payments[i];
12
+                    payments[i] = temp;
13
+                }
14
+            }
15
+        }
5
 
16
 
6
-}
17
+        String paymentsList = "";
18
+        for (Payment payment : payments) {
19
+            paymentsList += payment.getShortDescription() + " \n ";
20
+        }
21
+        return paymentsList;
22
+    }
23
+
24
+    public String toStringByPayerName(Payment[] payments) {
25
+        PaymentSortByPayer paymentSortByPayer = new PaymentSortByPayer();
26
+        Payment temp;
27
+        for (int i = 0; i < payments.length; i++) {
28
+            for (int j = i + 1; j < payments.length; j++) {
29
+                if (paymentSortByPayer.compare(payments[i], (payments[j])) > 0) {
30
+                    temp = payments[j];
31
+                    payments[j] = payments[i];
32
+                    payments[i] = temp;
33
+                }
34
+            }
35
+        }
36
+
37
+        String paymentsList = " ";
38
+        for (Payment payment : payments) {
39
+            paymentsList += payment.getShortDescription() + "\n";
40
+        }
41
+        return paymentsList;
42
+    }
43
+
44
+    public String toStringById(Payment[] payments) {
45
+        Payment temp;
46
+        for (int i = 0; i < payments.length; i++) {
47
+            for (int j = i + 1; j < payments.length; j++) {
48
+                if (payments[i].getId() > payments[j].getId()) {
49
+                    temp = payments[j];
50
+                    payments[j] = payments[i];
51
+                    payments[i] = temp;
52
+                }
53
+            }
54
+        }
55
+
56
+        String paymentsList = "";
57
+        for (Payment payment : payments) {
58
+            paymentsList += payment.getShortDescription() + "\n";
59
+        }
60
+        return paymentsList;
61
+    }
62
+}

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

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

BIN
src/test/.DS_Store Datei anzeigen


BIN
src/test/java/.DS_Store Datei anzeigen


BIN
src/test/java/com/.DS_Store Datei anzeigen


BIN
src/test/java/com/zipcoder/.DS_Store Datei anzeigen


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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class CheckTest {
7
+
8
+    CreditCard creditCard = new CreditCard(001, "Nira Parikh", "123456789876", 10, 2020);
9
+    Check check = new Check(002, "Nira Parikh", "031100089", "123456789");
10
+    PayPal payPal = new PayPal(003, "Nira Parikh", "angellegna@gmail.com");
11
+
12
+    @Test
13
+    public void testGetShortDescription(){
14
+        String expected = "Check Nira Parikh ***6789";
15
+        String actual = check.getShortDescription();
16
+        Assert.assertEquals(expected,actual);
17
+    }
18
+
19
+
20
+    @Test
21
+    public void testCompareTo_CheckToCC(){
22
+        Assert.assertTrue(check.compareTo(creditCard) > 0);
23
+    }
24
+
25
+    @Test
26
+    public void testCompareTo_CheckToPayPal(){
27
+        Assert.assertTrue(check.compareTo(payPal) < 0);
28
+
29
+    }
30
+
31
+}

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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class CreditCardTest {
7
+    CreditCard creditCard = new CreditCard(001, "Nira Parikh", "123456789876", 10, 2020);
8
+    Check check = new Check(002, "Nira Parikh", "031100089", "123456789");
9
+    PayPal payPal = new PayPal(003, "Nira Parikh", "angellegna@gmail.com");
10
+
11
+    @Test
12
+    public void testGetShortDescription(){
13
+        String expected = "CC Nira Parikh  9876 10/2020";
14
+        String actual = creditCard.getShortDescription();
15
+
16
+        Assert.assertEquals(expected,actual);
17
+    }
18
+    @Test
19
+    public void testCompareTo_CCToPayPal(){
20
+        Assert.assertTrue(creditCard.compareTo(payPal) < 0);
21
+
22
+    }
23
+
24
+    @Test
25
+    public void testCompareTo_CCToCheck(){
26
+        Assert.assertTrue(creditCard.compareTo(check) < 0);
27
+
28
+
29
+    }
30
+}
31
+

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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PayPalTest {
7
+
8
+    CreditCard creditCard = new CreditCard(001, "Nira Parikh", "123456789876", 10, 2020);
9
+    Check check = new Check(002, "Nira Parikh", "031100089", "123456789");
10
+    PayPal payPal = new PayPal(003, "Nira Parikh", "angellegna@gmail.com");
11
+
12
+    @Test
13
+    public void testGetShortDescription() {
14
+        String expected = "PayPal Nira Parikh angellegna@gmail.com";
15
+        String actual = payPal.getShortDescription();
16
+
17
+        Assert.assertEquals(expected, actual);
18
+    }
19
+
20
+    @Test
21
+    public void testCompareTo_PaypalToCC() {
22
+        Assert.assertTrue(payPal.compareTo(creditCard) > 0);
23
+    }
24
+
25
+    @Test
26
+    public void testCompareTo_PaypalToCheck() {
27
+        Assert.assertTrue(payPal.compareTo(check) > 0);
28
+    }
29
+}

+ 64
- 1
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Datei anzeigen

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
3
 public class PaymentPresenterTest {
6
 public class PaymentPresenterTest {
4
-}
7
+
8
+    @Test
9
+    public void testToString_NoPayments() {
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
+
19
+    @Test
20
+    public void toString_Payments() {
21
+        Payment[] payments = new Payment[2];
22
+        Payment payPal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
23
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
24
+
25
+        payments[0] = payPal;
26
+        payments[1] = check;
27
+
28
+        PaymentPresenter presenter = new PaymentPresenter();
29
+        String expected = "Check Tia Mowry ***4551 \n PayPal Tia Mowry tia@mowry.com\n";
30
+
31
+        String actual = presenter.toString(payments);
32
+        Assert.assertEquals(expected, actual);
33
+    }
34
+
35
+    @Test
36
+    public void toStringByPayerName(){
37
+        Payment[] payments = new Payment[2];
38
+        Payment payPal = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
39
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
40
+
41
+        payments[0] = payPal;
42
+        payments[1] = check;
43
+
44
+        PaymentPresenter presenter = new PaymentPresenter();
45
+        String expected = " PayPal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
46
+
47
+        String actual = presenter.toStringByPayerName(payments);
48
+        Assert.assertEquals(expected, actual);
49
+    }
50
+
51
+    @Test
52
+    public void toStringbyId(){
53
+        Payment[] payments = new Payment[2];
54
+        Payment payPal = new PayPal(120L, "Tamara Mowry", "tamara@mowry.com");
55
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
56
+
57
+        payments[0] = payPal;
58
+        payments[1] = check;
59
+
60
+        PaymentPresenter presenter = new PaymentPresenter();
61
+        String expected = "Check Tia Mowry ***4551\nPayPal Tamara Mowry tamara@mowry.com\n";
62
+
63
+        String actual = presenter.toStringById(payments);
64
+        Assert.assertEquals(expected, actual);
65
+    }
66
+
67
+}

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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PaymentSortByPayerTest {
7
+    CreditCard creditCard = new CreditCard(001, "Nira Parikh", "123456789876", 10, 2020);
8
+    Check check = new Check(002, "Nira Parikh", "031100089", "123456789");
9
+    PayPal payPal = new PayPal(003, "Nira Parikh", "angellegna@gmail.com");
10
+
11
+    PaymentSortByPayer paymentSortByPayer = new PaymentSortByPayer();
12
+
13
+
14
+    @Test
15
+    public void testCompare_SameName(){
16
+       Assert.assertTrue(paymentSortByPayer.compare(check, creditCard) == 0);
17
+
18
+    }
19
+
20
+    @Test
21
+    public void testCompare_SmallerLarger(){
22
+
23
+        Assert.assertTrue(paymentSortByPayer.compare(check, payPal) < 0);
24
+    }
25
+
26
+    @Test
27
+    public void testCompare_LargerSmaller(){
28
+        Assert.assertTrue(paymentSortByPayer.compare(payPal, creditCard) > 0);
29
+
30
+    }
31
+
32
+}