Procházet zdrojové kódy

cc, check, pp classes and tests

yauhenip před 8 roky
rodič
revize
6a316c8dfb

+ 9
- 0
pom.xml Zobrazit soubor

8
     <artifactId>payment</artifactId>
8
     <artifactId>payment</artifactId>
9
     <version>1.0-SNAPSHOT</version>
9
     <version>1.0-SNAPSHOT</version>
10
 
10
 
11
+    <dependencies>
12
+        <dependency>
13
+            <groupId>org.junit.jupiter</groupId>
14
+            <artifactId>junit-jupiter-api</artifactId>
15
+            <version>5.2.0</version>
16
+            <scope>test</scope>
17
+        </dependency>
18
+    </dependencies>
19
+
11
 
20
 
12
 </project>
21
 </project>

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

1
+package com.zipcoder.payment;
2
+
3
+public class Check implements Payment {
4
+
5
+    private Long id;
6
+    private String payerName;
7
+    private String routingNumber;
8
+    private String accountNumber;
9
+
10
+    public Long getId() {
11
+        return this.id;
12
+    }
13
+
14
+    public String getPayerName() {
15
+        return this.payerName;
16
+    }
17
+
18
+    public String getRoutingNumber() {
19
+        return this.routingNumber;
20
+    }
21
+
22
+    public String getAccountNumber() {
23
+        return this.accountNumber;
24
+    }
25
+
26
+    public String getShortDescription() {
27
+        return String.format("%s %s %s%s", "Check", getPayerName(), "***",
28
+                getAccountNumber().substring(getAccountNumber().length()-4));
29
+    }
30
+
31
+    public void setId(Long id) {
32
+        this.id = id;
33
+    }
34
+
35
+    public void setPayerName(String payerName) {
36
+        this.payerName = payerName;
37
+    }
38
+
39
+    public void setRoutingNumber(String routingNumber) {
40
+        this.routingNumber = routingNumber;
41
+    }
42
+
43
+    public void setAccountNumber(String accountNumber) {
44
+        this.accountNumber = accountNumber;
45
+    }
46
+}

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

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

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

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

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

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

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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.assertEquals;
6
+
7
+public class CheckTest {
8
+
9
+    Check myCheck = new Check();
10
+
11
+    @Test
12
+    public void getIdTest(){
13
+        Long expected = 63L;
14
+        myCheck.setId(63L);
15
+        Long actual = myCheck.getId();
16
+        assertEquals(expected, actual);
17
+    }
18
+
19
+    @Test
20
+    public void getPayerNameTest(){
21
+        String expected = "Dan Rivas";
22
+        myCheck.setPayerName("Dan Rivas");
23
+        String actual = myCheck.getPayerName();
24
+        assertEquals(expected, actual);
25
+    }
26
+
27
+    @Test
28
+    public void getAccountNumberTest(){
29
+        String expected = "1243567895";
30
+        myCheck.setAccountNumber("1243567895");
31
+        String actual = myCheck.getAccountNumber();
32
+        assertEquals(expected, actual);
33
+    }
34
+
35
+    @Test
36
+    public void getRoutingNumberTest(){
37
+        String expected = "0834596787";
38
+        myCheck.setRoutingNumber("0834596787");
39
+        String actual = myCheck.getRoutingNumber();
40
+        assertEquals(expected, actual);
41
+    }
42
+
43
+    @Test
44
+    public void getShortDescriptionTest(){
45
+        String expected = "Check Dan Rivas ***7895";
46
+        myCheck.setPayerName("Dan Rivas");
47
+        myCheck.setAccountNumber("1243567895");
48
+        String actual = myCheck.getShortDescription();
49
+        assertEquals(expected, actual);
50
+    }
51
+}

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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.assertEquals;
6
+
7
+public class CreditCardTest {
8
+
9
+    CreditCard cc = new CreditCard();
10
+
11
+    @Test
12
+    public void getIdTest(){
13
+        Long expected = 65L;
14
+        cc.setId(65L);
15
+        Long actual = cc.getId();
16
+        assertEquals(expected, actual);
17
+    }
18
+
19
+    @Test
20
+    public void getPayerNameTest(){
21
+        String expected = "Jacob Browler";
22
+        cc.setPayerName("Jacob Browler");
23
+        String actual = cc.getPayerName();
24
+        assertEquals(expected, actual);
25
+    }
26
+
27
+    @Test
28
+    public void getNumberTest(){
29
+        String expected = "1233-3245-5366-3456";
30
+        cc.setNumber("1233-3245-5366-3456");
31
+        String actual = cc.getNumber();
32
+        assertEquals(expected, actual);
33
+    }
34
+
35
+    @Test
36
+    public void getExpiredMonthTest(){
37
+        int expected = 9;
38
+        cc.setExpiredMonth(9);
39
+        int actual = cc.getExpiredMonth();
40
+        assertEquals(expected, actual);
41
+    }
42
+
43
+    @Test
44
+    public void getExpiredYearTest(){
45
+        int expected = 23;
46
+        cc.setExpiredYear(23);
47
+        int actual = cc.getExpiredYear();
48
+        assertEquals(expected, actual);
49
+    }
50
+
51
+    @Test
52
+    public void getShortDescriptionTest(){
53
+        String expected = "CC Jacob Browler 3456 09/23";
54
+        cc.setPayerName("Jacob Browler");
55
+        cc.setNumber("1233-3245-5366-3456");
56
+        cc.setExpiredMonth(9);
57
+        cc.setExpiredYear(23);
58
+        String actual = cc.getShortDescription();
59
+        assertEquals(expected, actual);
60
+    }
61
+}

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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.assertEquals;
6
+
7
+public class PayPalTest {
8
+
9
+    PayPal pp = new PayPal("Shane McNaulty", "shane@loews.com");
10
+
11
+    @Test
12
+    public void getIdTest(){
13
+        Long expected = 59L;
14
+        pp.setId(59L);
15
+        Long actual = pp.getId();
16
+        assertEquals(expected, actual);
17
+    }
18
+
19
+    @Test
20
+    public void getPayerNameTest(){
21
+        String expected = "Shane McNaulty";
22
+        String actual = pp.getPayerName();
23
+        assertEquals(expected, actual);
24
+    }
25
+
26
+    @Test
27
+    public void getEmailTest(){
28
+        String expected = "shane@loews.com";
29
+        String actual = pp.getEmail();
30
+        assertEquals(expected, actual);
31
+    }
32
+
33
+    @Test
34
+    public void getShortDescriptionTest(){
35
+        String expected = "Paypal Shane McNaulty shane@loews.com";
36
+        String actual = pp.getShortDescription();
37
+        assertEquals(expected, actual);
38
+    }
39
+}