Procházet zdrojové kódy

blaaaaaaaaaaaaaaaaaaaaaaas

Ahmad Rusdi před 8 roky
rodič
revize
b6643cdcb6

+ 10
- 0
pom.xml Zobrazit soubor

@@ -12,4 +12,14 @@
12 12
         <maven.compiler.target>1.8</maven.compiler.target>
13 13
     </properties>
14 14
 
15
+    <dependencies>
16
+        <dependency>
17
+            <groupId>junit</groupId>
18
+            <artifactId>junit</artifactId>
19
+            <version>4.12</version>
20
+            <scope>test</scope>
21
+        </dependency>
22
+
23
+    </dependencies>
24
+
15 25
 </project>

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

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

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

@@ -0,0 +1,70 @@
1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment {
4
+    long Id;
5
+    String payerName;
6
+    String number;
7
+    int expiredYear;
8
+
9
+    public CreditCard(long id, String payerName, String number, int expiredYear, int expiredMonth) {
10
+        Id = id;
11
+        this.payerName = payerName;
12
+        this.number = number;
13
+        this.expiredYear = expiredYear;
14
+        this.expiredMonth = expiredMonth;
15
+    }
16
+
17
+    int expiredMonth;
18
+
19
+    public void setId(long id) {
20
+        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 getExpiredYear() {
36
+        return expiredYear;
37
+    }
38
+
39
+    public void setExpiredYear(int expiredYear) {
40
+        this.expiredYear = expiredYear;
41
+    }
42
+
43
+    public int getExpiredMonth() {
44
+        return expiredMonth;
45
+    }
46
+
47
+    public void setExpiredMonth(int expiredMonth) {
48
+        this.expiredMonth = expiredMonth;
49
+    }
50
+
51
+    @Override
52
+    public long getId() {
53
+        return this.Id;
54
+    }
55
+
56
+    @Override
57
+    public String getPayerName() {
58
+        return this.payerName;
59
+    }
60
+
61
+    @Override
62
+    public String getShortDescription() {
63
+        return String.format("CC %s %s %d/%d", payerName, number.substring(number.length() - 4), expiredMonth, expiredYear);
64
+    }
65
+
66
+    @Override
67
+    public int compareTo(Payment o) {
68
+        return this.getShortDescription().compareTo(o.getShortDescription());
69
+    }
70
+}

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

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

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

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

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

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

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

@@ -0,0 +1,47 @@
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
+    Check check;
10
+
11
+    @Before
12
+    public void setUp() {
13
+        check = new Check(1, "owo", "23341", "22192");
14
+    }
15
+
16
+    @Test
17
+    public void testIdField() {
18
+        long expected = 1;
19
+        check.setId(expected);
20
+        long actual = check.getId();
21
+        assertEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void testPayerName() {
26
+        String expected = "Owo Bank";
27
+        check.setPayerName(expected);
28
+        String actual = check.getPayerName();
29
+        assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void testRoutingNumber() {
34
+        String expected = "2039230";
35
+        check.setRoutingNumber(expected);
36
+        String actual = check.getRoutingNumber();
37
+        assertEquals(expected, actual);
38
+    }
39
+
40
+    @Test
41
+    public void testAccountNumber() {
42
+        String expected = "1337";
43
+        check.setAccountNumber(expected);
44
+        String actual = check.getAccountNumber();
45
+        assertEquals(expected, actual);
46
+    }
47
+}

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

@@ -0,0 +1,55 @@
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 CreditCardTest {
9
+    CreditCard cc;
10
+
11
+    @Before
12
+    public void setUp() {
13
+        cc = new CreditCard(1, "wo", "wo", 1992, 10);
14
+    }
15
+
16
+    @Test
17
+    public void testIdField() {
18
+        long expected = 1;
19
+        cc.setId(expected);
20
+        long actual = cc.getId();
21
+        assertEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void testExpiredYear() {
26
+        int expected = 2001;
27
+        cc.setExpiredYear(expected);
28
+        int actual = cc.getExpiredYear();
29
+        assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void testExpiredMonth() {
34
+        int expected = 11;
35
+        cc.setExpiredMonth(expected);
36
+        int actual = cc.getExpiredMonth();
37
+        assertEquals(expected, actual);
38
+    }
39
+
40
+    @Test
41
+    public void testNumberField() {
42
+        String expected = "1337";
43
+        cc.setNumber(expected);
44
+        String actual = cc.getNumber();
45
+        assertEquals(expected, actual);
46
+    }
47
+
48
+    @Test
49
+    public void testPayerNameField() {
50
+        String expected = "Owo Banks";
51
+        cc.setPayerName(expected);
52
+        String actual = cc.getPayerName();
53
+        assertEquals(expected, actual);
54
+    }
55
+}

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

@@ -1,4 +1,32 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.assertEquals;
6
+
3 7
 public class PaymentPresenterTest {
8
+    @Test
9
+    public void noPayment() {
10
+        Payment[] payments = new Payment[0];
11
+        PaymentPresenter presenter = new PaymentPresenter();
12
+        String expected = "";
13
+        String actual = presenter.toString(payments);
14
+        assertEquals(expected, actual);
15
+    }
16
+
17
+    @Test
18
+    public void multiplePayments() {
19
+        Payment[] payments = new Payment[2];
20
+        Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
21
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
22
+
23
+        payments[0] = paypal;
24
+        payments[1] = check;
25
+
26
+        PaymentPresenter presenter = new PaymentPresenter();
27
+        String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
28
+
29
+        String actual = presenter.toString(payments);
30
+        assertEquals(expected, actual);
31
+    }
4 32
 }

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

@@ -0,0 +1,39 @@
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 PaypalTest {
9
+    Paypal pp;
10
+
11
+    @Before
12
+    public void setUp() {
13
+        pp = new Paypal();
14
+    }
15
+
16
+    @Test
17
+    public void testId() {
18
+        long expected = 1;
19
+        pp.setId(expected);
20
+        long actual = pp.getId();
21
+        assertEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void testPayerName() {
26
+        String expected = "wooten";
27
+        pp.setPayerName(expected);
28
+        String actual = pp.getPayerName();
29
+        assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void testEmail() {
34
+        String expected = "OE@OW.com";
35
+        pp.setEmail(expected);
36
+        String actual = pp.getEmail();
37
+        assertEquals(expected, actual);
38
+    }
39
+}