ソースを参照

finished sections 1 and 2

Michelle DiMarino 7 年 前
コミット
54e37862d3

+ 13
- 1
pom.xml ファイルの表示

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

+ 61
- 0
src/main/java/com/zipcoder/payment/Check.java ファイルの表示

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

+ 70
- 0
src/main/java/com/zipcoder/payment/CreditCard.java ファイルの表示

@@ -0,0 +1,70 @@
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 CreditCard(int id, String name, String number, int emonth, int eyear){
12
+        this.id = id;
13
+        this.payerName = name;
14
+        this.number = number;
15
+        this.expiredMonth = emonth;
16
+        this.expiredYear = eyear;
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
+    @Override
52
+    public long getId() {
53
+        return id;
54
+    }
55
+
56
+    @Override
57
+    public String getPayerName() {
58
+        return payerName;
59
+    }
60
+
61
+    @Override
62
+    public String getShortDescription() {
63
+        return "CC " + payerName+" "+ number+" "+ expiredMonth+"/"+expiredYear;
64
+    }
65
+
66
+    @Override
67
+    public int compareTo(Payment o) {
68
+        return getShortDescription().compareToIgnoreCase(o.getShortDescription());
69
+    }
70
+}

+ 51
- 0
src/main/java/com/zipcoder/payment/PayPal.java ファイルの表示

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

+ 10
- 0
src/main/java/com/zipcoder/payment/Payment.java ファイルの表示

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

+ 11
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPlayer.java ファイルの表示

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

+ 79
- 0
src/test/java/com/zipcoder/payment/CheckTest.java ファイルの表示

@@ -0,0 +1,79 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+import org.junit.Assert;
5
+
6
+public class CheckTest {
7
+
8
+    Check check1 = new Check(111000, "Michelle", "12345", "67789");
9
+
10
+    @Test
11
+    public void idSetGet(){
12
+        long expectedOutput = 11110000;
13
+
14
+        check1.setId(11110000);
15
+        long actualOutput = check1.getId();
16
+
17
+        Assert.assertEquals(expectedOutput, actualOutput);
18
+
19
+    }
20
+
21
+
22
+    @Test
23
+    public void payerNameSetGet(){
24
+        String expectedOutput = "Michelle";
25
+
26
+        check1.setPayerName("Michelle");
27
+        String actualOutput = check1.getPayerName();
28
+
29
+        Assert.assertEquals(expectedOutput, actualOutput);
30
+
31
+
32
+    }
33
+
34
+    @Test
35
+    public void routingSetGet(){
36
+        String expectedOutput = "1234567";
37
+
38
+        check1.setRoutingNumber("1234567");
39
+        String actualOutput = check1.getRoutingNumber();
40
+
41
+        Assert.assertEquals(expectedOutput, actualOutput);
42
+
43
+    }
44
+
45
+    @Test
46
+    public void accountSetGet(){
47
+        String expectedOutput = "78910";
48
+
49
+        check1.setAccountNumber("78910");
50
+        String actualOutput = check1.getAccountNumber();
51
+
52
+        Assert.assertEquals(expectedOutput, actualOutput);
53
+    }
54
+
55
+    @Test
56
+    public void getShortDescTest(){
57
+        check1.setPayerName("Michelle");
58
+        check1.setAccountNumber("78910");
59
+
60
+        String expectedOutput = "Check Michelle ***78910";
61
+
62
+        String actualOutput = check1.getShortDescription();
63
+
64
+        Assert.assertEquals(expectedOutput, actualOutput);
65
+    }
66
+
67
+    @Test
68
+    public void compare2Test() {
69
+        CreditCard cc2 = new CreditCard(2233, "Michelle", "12345", 12, 18);
70
+        Check check2 = new Check(22233, "Michelle", "123456", "1234567");
71
+
72
+        int expectedOutput = 0;
73
+        int actualOutput = check2.getShortDescription().compareTo(cc2.getShortDescription());
74
+
75
+        Assert.assertTrue(expectedOutput < actualOutput);
76
+    }
77
+
78
+
79
+}

+ 92
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java ファイルの表示

@@ -0,0 +1,92 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+import org.junit.Assert;
5
+
6
+
7
+public class CreditCardTest {
8
+
9
+    CreditCard cc1 = new CreditCard(1100, "Michelle","1234", 12, 18 );
10
+
11
+    @Test
12
+    public void idSetGet(){
13
+        long expectedOutput = 11110000;
14
+
15
+        cc1.setId(11110000);
16
+        long actualOutput = cc1.getId();
17
+
18
+        Assert.assertEquals(expectedOutput, actualOutput);
19
+
20
+
21
+    }
22
+
23
+    @Test
24
+    public void payerNameSetGet(){
25
+        String expectedOutput = "Michelle";
26
+
27
+        cc1.setPayerName("Michelle");
28
+        String actualOutput = cc1.getPayerName();
29
+
30
+        Assert.assertEquals(expectedOutput, actualOutput);
31
+
32
+    }
33
+
34
+    @Test
35
+    public void numberSetGet(){
36
+        String expectedOutput = "12345";
37
+
38
+        cc1.setNumber("12345");
39
+        String actualOutput = cc1.getNumber();
40
+
41
+        Assert.assertEquals(expectedOutput, actualOutput);
42
+
43
+    }
44
+
45
+    @Test
46
+    public void expiredMSetGet(){
47
+        int expectedOutput = 12;
48
+
49
+        cc1.setExpiredMonth(12);
50
+        int actualOutput = cc1.getExpiredMonth();
51
+
52
+        Assert.assertEquals(expectedOutput, actualOutput);
53
+
54
+    }
55
+
56
+    @Test
57
+    public void expiredYSetGet(){
58
+        int expectedOutput = 18;
59
+
60
+        cc1.setExpiredYear(18);
61
+        int actualOutput = cc1.getExpiredYear();
62
+
63
+        Assert.assertEquals(expectedOutput, actualOutput);
64
+
65
+    }
66
+
67
+    @Test
68
+    public void getDescTest(){
69
+        cc1.setPayerName("Michelle");
70
+        cc1.setNumber("12345");
71
+        cc1.setExpiredMonth(12);
72
+        cc1.setExpiredYear(18);
73
+        String expectedOutput = "CC Michelle 12345 12/18";
74
+
75
+        String actualOutput = cc1.getShortDescription();
76
+
77
+        Assert.assertEquals(expectedOutput, actualOutput);
78
+
79
+    }
80
+
81
+    @Test
82
+    public void comare2Test() {
83
+        PayPal paypal2 = new PayPal(1100, "Michelle", "me@me.com");
84
+        CreditCard cc2 = new CreditCard(2233, "Michelle", "12345", 12, 18);
85
+
86
+        int expectedOutput = 0;
87
+        int actualOutput = cc2.getShortDescription().compareTo(paypal2.getShortDescription());
88
+
89
+        Assert.assertTrue(expectedOutput > actualOutput);
90
+    }
91
+
92
+}

+ 64
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java ファイルの表示

@@ -0,0 +1,64 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+import org.junit.Assert;
5
+
6
+public class PayPalTest {
7
+
8
+    PayPal paypal1 = new PayPal(11100, "Michelle", "me@me.com");
9
+
10
+    @Test
11
+    public void idSetGetTest(){
12
+        long expectedOutput = 111000;
13
+
14
+        paypal1.setId(111000);
15
+        long actualOutput = paypal1.getId();
16
+
17
+        Assert.assertEquals(expectedOutput, actualOutput);
18
+
19
+    }
20
+
21
+    @Test
22
+    public void payerNameSetGetTest(){
23
+        String expectedOutput = "Michelle";
24
+
25
+        paypal1.setPayerName("Michelle");
26
+        String actualOutput = paypal1.getPayerName();
27
+
28
+        Assert.assertEquals(expectedOutput, actualOutput);
29
+
30
+    }
31
+
32
+    @Test
33
+    public void emailSetGetTest(){
34
+        String expectedOutput = "me@me.com";
35
+
36
+        paypal1.setEmail("me@me.com");
37
+        String actualOutput = paypal1.getEmail();
38
+
39
+        Assert.assertEquals(expectedOutput, actualOutput);
40
+
41
+    }
42
+
43
+    @Test
44
+    public void getDescTest(){
45
+        paypal1.setPayerName("Michelle");
46
+        paypal1.setEmail("me@me.com");
47
+        String expectedOutput = "Paypal Michelle me@me.com";
48
+
49
+        String actualOutput = paypal1.getShortDescription();
50
+
51
+        Assert.assertEquals(expectedOutput, actualOutput);
52
+    }
53
+
54
+    @Test
55
+    public void compare2Test(){
56
+        PayPal paypal2 = new PayPal(1100, "Michelle", "me@me.com");
57
+        CreditCard cc2 = new CreditCard(2233, "Michelle", "12345", 12, 18);
58
+
59
+        int expectedOutput = 0;
60
+        int actualOutput = paypal2.getShortDescription().compareTo(cc2.getShortDescription());
61
+
62
+        Assert.assertTrue(expectedOutput < actualOutput);
63
+    }
64
+}

+ 21
- 0
src/test/java/com/zipcoder/payment/PaymentSortTest.java ファイルの表示

@@ -0,0 +1,21 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PaymentSortTest {
7
+
8
+    PaymentSortByPlayer psbp = new PaymentSortByPlayer();
9
+
10
+    @Test
11
+    public void compareTest(){
12
+        Check check1 = new Check(111000, "Michelle", "12345", "678910");
13
+        Check check2 = new Check(111001, "Ashley", "12345", "12345");
14
+
15
+        int expectedOutput = 0;
16
+        int actualOutput = psbp.compare(check1, check2);
17
+
18
+        Assert.assertTrue(expectedOutput < actualOutput);
19
+
20
+    }
21
+}