소스 검색

all parts complete

Allison Ziegler 8 년 전
부모
커밋
5a6f5b8ad9

+ 20
- 20
README.MD 파일 보기

1
-# Polymorphism Payment Lab
1
+# Polymorphism com.zipcoder.payment.Payment Lab
2
 
2
 
3
 ## Objectives
3
 ## Objectives
4
 
4
 
7
 - To learn [lambda function](https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html)
7
 - To learn [lambda function](https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html)
8
 
8
 
9
 # Section 1 - Setting up the classes
9
 # Section 1 - Setting up the classes
10
-## Part 1 - Payment
11
-1. Create a `Payment` interface
10
+## Part 1 - com.zipcoder.payment.Payment
11
+1. Create a `com.zipcoder.payment.Payment` interface
12
   - The class should define a `getId()` method which returns a Long
12
   - The class should define a `getId()` method which returns a Long
13
   - The class should define a `getPayerName()` method which returns a String
13
   - The class should define a `getPayerName()` method which returns a String
14
   - The class should define a `getShortDescription` method which returns a String
14
   - The class should define a `getShortDescription` method which returns a String
15
 
15
 
16
 ## Part 2 - Credit Card
16
 ## Part 2 - Credit Card
17
 1. Create a `CreditCardTest` test class
17
 1. Create a `CreditCardTest` test class
18
-2. Create a `CreditCard` class which implements the `Payment` interface
18
+2. Create a `CreditCard` class which implements the `com.zipcoder.payment.Payment` interface
19
 3. Add the required methods from the interface
19
 3. Add the required methods from the interface
20
 4. Add getter and setter test for an id
20
 4. Add getter and setter test for an id
21
   - Add a Long id field
21
   - Add a Long id field
31
 
31
 
32
 ## Part 3 - Check
32
 ## Part 3 - Check
33
 1. Create a `CheckTest` test class
33
 1. Create a `CheckTest` test class
34
-2. Create a `Check` class which implements the `Payment` interface
34
+2. Create a `Check` class which implements the `com.zipcoder.payment.Payment` interface
35
 3. Add the required methods from the interface
35
 3. Add the required methods from the interface
36
 4. Add getter and setter test for an id
36
 4. Add getter and setter test for an id
37
   - Add a Long id field
37
   - Add a Long id field
46
 
46
 
47
 ## Part 4 - Paypal
47
 ## Part 4 - Paypal
48
 1. Create a `PayPalTest` test class
48
 1. Create a `PayPalTest` test class
49
-2. Create a `PayPal` class which implements the `Payment` interface
49
+2. Create a `PayPal` class which implements the `com.zipcoder.payment.Payment` interface
50
 3. Add the required methods from the interface
50
 3. Add the required methods from the interface
51
 4. Add getter and setter test for an id
51
 4. Add getter and setter test for an id
52
   - Add a Long id field
52
   - Add a Long id field
60
 
60
 
61
 # Section 2 - Comparable
61
 # Section 2 - Comparable
62
 Note: You may use the String/Long compareTo methods in your code
62
 Note: You may use the String/Long compareTo methods in your code
63
-1. Edit the `Payment` class to extends the Comparable interface
64
-  - `public class Payment extends Comparable<Payment>`
63
+1. Edit the `com.zipcoder.payment.Payment` class to extends the Comparable interface
64
+  - `public class com.zipcoder.payment.Payment extends Comparable<com.zipcoder.payment.Payment>`
65
   - This indicate that payment can be comparable, which means it can be sorted
65
   - This indicate that payment can be comparable, which means it can be sorted
66
 2. Fix the syntax error in your CreditCard, Check, and Paypal class by adding the compare method
66
 2. Fix the syntax error in your CreditCard, Check, and Paypal class by adding the compare method
67
 3. Create a test for the `compareTo` method. Compare using the getShortDescription()
67
 3. Create a test for the `compareTo` method. Compare using the getShortDescription()
68
-  - Example: Given Payment of type Paypal with the short description of `Paypal Tia Mowry tia@mowry.com` and a Check with the short description of `Check Tia Mowry ***4551`, then the `compareTo` method should return a number larger than 0
68
+  - Example: Given com.zipcoder.payment.Payment of type Paypal with the short description of `Paypal Tia Mowry tia@mowry.com` and a Check with the short description of `Check Tia Mowry ***4551`, then the `compareTo` method should return a number larger than 0
69
   - The `compareTo` method will return number larger than 0 if this payment comes after payment2
69
   - The `compareTo` method will return number larger than 0 if this payment comes after payment2
70
   - The `compareTo` method will return number 0 if this payment has the same information
70
   - The `compareTo` method will return number 0 if this payment has the same information
71
   - The `compareTo` method will return number less than 0 if this payment comes before payment2
71
   - The `compareTo` method will return number less than 0 if this payment comes before payment2
72
 4. Add the code necessary to make the test pass
72
 4. Add the code necessary to make the test pass
73
 5. Create a new `PaymentSortByPayer` class which implements `java.util.Comparator`
73
 5. Create a new `PaymentSortByPayer` class which implements `java.util.Comparator`
74
   - This class will sort by payer name
74
   - This class will sort by payer name
75
-  - `public class PaymentSortByPayer implements Comparator<Payment>`
75
+  - `public class PaymentSortByPayer implements Comparator<com.zipcoder.payment.Payment>`
76
 6. Add the required `compare` method from the Comparator
76
 6. Add the required `compare` method from the Comparator
77
 7. Create a test to compare two payment
77
 7. Create a test to compare two payment
78
     - The `compare` method will return number larger than 0 if payment1 comes after payment2
78
     - The `compare` method will return number larger than 0 if payment1 comes after payment2
85
   - When there is no payment
85
   - When there is no payment
86
     
86
     
87
     ```
87
     ```
88
-      Payment[] payments = new Payment[0];
88
+      com.zipcoder.payment.Payment[] payments = new com.zipcoder.payment.Payment[0];
89
       PaymentPresenter presenter = new PaymentPresenter();
89
       PaymentPresenter presenter = new PaymentPresenter();
90
       String expected = "";
90
       String expected = "";
91
 
91
 
97
   - When there are multiple payments, you need to sort it first, then build the string using the short description
97
   - When there are multiple payments, you need to sort it first, then build the string using the short description
98
     
98
     
99
   ```
99
   ```
100
-    Payment[] payments = new Payment[2];
101
-    Payment paypal = new PayPayl(4L, "Tia Mowry", "tia@mowry.com");
102
-    Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
100
+    com.zipcoder.payment.Payment[] payments = new com.zipcoder.payment.Payment[2];
101
+    com.zipcoder.payment.Payment paypal = new PayPayl(4L, "Tia Mowry", "tia@mowry.com");
102
+    com.zipcoder.payment.Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
103
 
103
 
104
     payment[0] = paypal;
104
     payment[0] = paypal;
105
 
105
 
114
     - When there are multiple payments, you need to sort by calling the `PaymentSortByPayer` class to sort, then build the string using the short description
114
     - When there are multiple payments, you need to sort by calling the `PaymentSortByPayer` class to sort, then build the string using the short description
115
 
115
 
116
     ```
116
     ```
117
-      Payment[] payments = new Payment[2];
118
-      Payment paypal = new PayPayl(4L, "Tamara Mowry", "tamara@mowry.com");
119
-      Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
117
+      com.zipcoder.payment.Payment[] payments = new com.zipcoder.payment.Payment[2];
118
+      com.zipcoder.payment.Payment paypal = new PayPayl(4L, "Tamara Mowry", "tamara@mowry.com");
119
+      com.zipcoder.payment.Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
120
 
120
 
121
       payment[0] = paypal;
121
       payment[0] = paypal;
122
 
122
 
131
     - When there are multiple payments, you need to sort by creating a lambda to sort the payment by id, then build the string using the short description
131
     - When there are multiple payments, you need to sort by creating a lambda to sort the payment by id, then build the string using the short description
132
 
132
 
133
     ```
133
     ```
134
-      Payment[] payments = new Payment[2];
135
-      Payment paypal = new PayPayl(120L, "Tamara Mowry", "tamara@mowry.com");
136
-      Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
134
+      com.zipcoder.payment.Payment[] payments = new com.zipcoder.payment.Payment[2];
135
+      com.zipcoder.payment.Payment paypal = new PayPayl(120L, "Tamara Mowry", "tamara@mowry.com");
136
+      com.zipcoder.payment.Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
137
 
137
 
138
       payment[0] = paypal;
138
       payment[0] = paypal;
139
 
139
 

+ 8
- 0
pom.xml 파일 보기

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>junit</groupId>
14
+            <artifactId>junit</artifactId>
15
+            <version>4.12</version>
16
+            <scope>test</scope>
17
+        </dependency>
18
+    </dependencies>
11
 
19
 
12
 </project>
20
 </project>

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

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
+        this.id = id;
11
+        this.payerName = payerName;
12
+        this.routingNumber = routingNumber;
13
+        this.accountNumber = accountNumber;
14
+    }
15
+
16
+    public long getId(){
17
+        return id;
18
+    }
19
+    public String getPayerName(){
20
+        return payerName;
21
+    }
22
+    public String getShortDescription(){
23
+        return String.format("Check %s ***%s", payerName, accountNumber.substring(accountNumber.length()-4, accountNumber.length()));
24
+    }
25
+    public String getAccountNumber() {
26
+        return accountNumber;
27
+    }
28
+    public String getRoutingNumber() {
29
+        return routingNumber;
30
+    }
31
+    public int compareTo(Payment p) {
32
+        return this.getShortDescription().compareTo(p.getShortDescription());
33
+    }
34
+
35
+}

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

1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment {
4
+    private long id;
5
+    private String payerName;
6
+    private String number;
7
+    private int expiredMonth;
8
+    private 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
+    public long getId() {
19
+        return id;
20
+    }
21
+    public String getPayerName() {
22
+        return payerName;
23
+    }
24
+    public String getNumber() {
25
+        return number;
26
+    }
27
+    public int getExpiredMonth() {
28
+        return expiredMonth;
29
+    }
30
+    public int getExpiredYear() {
31
+        return expiredYear;
32
+    }
33
+
34
+    public String getShortDescription(){
35
+        return String.format("CC %s %s %d/%d", payerName, number.substring(number.length() - 4, number.length()), expiredMonth, expiredYear);
36
+    }
37
+
38
+    public int compareTo(Payment p) {
39
+        return this.getShortDescription().compareTo(p.getShortDescription());
40
+    }
41
+
42
+}

+ 29
- 0
src/main/java/com/zipcoder/payment/PayPal.java 파일 보기

1
+package com.zipcoder.payment;
2
+
3
+public class PayPal  implements Payment{
4
+    long id;
5
+    String payerName;
6
+    String payerEmail;
7
+
8
+    public PayPal(long id, String payerName, String payerEmail) {
9
+        this.id = id;
10
+        this.payerName = payerName;
11
+        this.payerEmail = payerEmail;
12
+    }
13
+
14
+    public long getId(){
15
+        return id;
16
+    }
17
+    public String getPayerName(){
18
+        return payerName;
19
+    }
20
+    public String getPayerEmail() {
21
+        return payerEmail;
22
+    }
23
+    public String getShortDescription(){
24
+        return String.format("Paypal %s %s", payerName, payerEmail);
25
+    }
26
+    public int compareTo(Payment p) {
27
+        return this.getShortDescription().compareTo(p.getShortDescription());
28
+    }
29
+}

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

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

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

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
+import java.util.Arrays;
4
+
3
 public class PaymentPresenter {
5
 public class PaymentPresenter {
4
 
6
 
5
 
7
 
8
+    public String toString(Payment[] p){
9
+        Arrays.sort(p);
10
+        return generateOutputString(p);
11
+    }
12
+
13
+    public String toStringByPayerName(Payment[] p) {
14
+        PaymentSortByPayer psbp = new PaymentSortByPayer();
15
+        Arrays.sort(p, psbp);
16
+        return generateOutputString(p);
17
+    }
18
+
19
+    public String toStringByID(Payment[] p){
20
+        PaymentSortById psbi = new PaymentSortById();
21
+        Arrays.sort(p, psbi);
22
+        return generateOutputString(p);
23
+    }
24
+
25
+    private String generateOutputString(Payment[] p) {
26
+        StringBuilder paymentSB = new StringBuilder();
27
+        for (Payment payment : p){
28
+            paymentSB.append(payment.getShortDescription() + "\n");
29
+        }
30
+        return paymentSB.toString();
31
+    }
6
 }
32
 }

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

1
+package com.zipcoder.payment;
2
+
3
+import java.util.Comparator;
4
+
5
+public class PaymentSortById implements Comparator<Payment>{
6
+    public int compare(Payment p1, Payment p2) {
7
+        Long p1ID = p1.getId();
8
+        Long p2ID = p2.getId();
9
+        return p1ID.compareTo(p2ID);
10
+    }
11
+
12
+}

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

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

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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+public class CheckTest {
9
+    Check ch;
10
+    Check c2;
11
+
12
+    @Before
13
+    public void setup() {
14
+        ch = new Check(12345, "Sansa Stark", "1234567", "987654321");
15
+        c2 = new Check(9034, "Arya Stark", "1234569", "987654444");
16
+
17
+    }
18
+
19
+    @Test
20
+    public void getIdTest() {
21
+        long expected = 12345;
22
+        long actual = ch.getId();
23
+        Assert.assertEquals(expected, actual);
24
+    }
25
+    @Test
26
+    public void getPayerNameTest() {
27
+        String expected = "Sansa Stark";
28
+        String actual = ch.getPayerName();
29
+        Assert.assertEquals(expected, actual);
30
+    }
31
+    @Test
32
+    public void getRoutingNumberTest() {
33
+        String expected = "1234567";
34
+        String actual = ch.getRoutingNumber();
35
+        Assert.assertEquals(expected, actual);
36
+    }
37
+    @Test
38
+    public void getAccountNumberTest() {
39
+        String expected = "987654321";
40
+        String actual = ch.getAccountNumber();
41
+        Assert.assertEquals(expected, actual);
42
+    }
43
+    @Test
44
+    public void getShortDescriptionTest() {
45
+        String expected = "Check Sansa Stark ***4321";
46
+        String actual = ch.getShortDescription();
47
+        Assert.assertEquals(expected, actual);
48
+    }
49
+    @Test
50
+    public void compareToTest() {
51
+        int actual = ch.compareTo(c2);
52
+        Assert.assertTrue(actual > 0);
53
+    }
54
+    @Test
55
+    public void compareToTest2() {
56
+        int actual = c2.compareTo(ch);
57
+        Assert.assertTrue(actual < 0);
58
+    }
59
+    @Test
60
+    public void compareToTest3() {
61
+        int actual = c2.compareTo(c2);
62
+        Assert.assertTrue(actual == 0);
63
+    }
64
+}

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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+public class CreditCardTest {
9
+    CreditCard cc;
10
+    PayPal pp;
11
+    @Before
12
+    public void setup() {
13
+        cc = new CreditCard(12345, "Sansa Stark", "4444444444", 12, 2020);
14
+        pp = new PayPal(12345, "Sansa Stark", "ladystark@winterfell.com");
15
+    }
16
+
17
+    @Test
18
+    public void creditCardGetIDTest() {
19
+        long expected = 12345;
20
+        long actual = cc.getId();
21
+
22
+        Assert.assertEquals(expected, actual);
23
+    }
24
+    @Test
25
+    public void creditCardGetPayerNameTest() {
26
+        String expected = "Sansa Stark";
27
+        String actual = cc.getPayerName();
28
+
29
+        Assert.assertEquals(expected, actual);
30
+    }
31
+    @Test
32
+    public void creditCardGetShortDescription() {
33
+        String expected = "CC Sansa Stark 4444 12/2020";
34
+        String actual = cc.getShortDescription();
35
+
36
+        Assert.assertEquals(expected, actual);
37
+    }
38
+    @Test
39
+    public void creditCardGetExpiredMonthTest() {
40
+        int expected = 12;
41
+        int actual = cc.getExpiredMonth();
42
+
43
+        Assert.assertEquals(expected, actual);
44
+    }
45
+    @Test
46
+    public void creditCardGetExpiredYearTest() {
47
+        int expected = 2020;
48
+        int actual = cc.getExpiredYear();
49
+
50
+        Assert.assertEquals(expected, actual);
51
+    }
52
+    @Test
53
+    public void creditCardGetNumberTest() {
54
+        String expected = "4444444444";
55
+        String actual = cc.getNumber();
56
+
57
+        Assert.assertEquals(expected, actual);
58
+    }
59
+
60
+    @Test
61
+    public void compareToTest() {
62
+        int actual = pp.compareTo(cc);
63
+        Assert.assertTrue(actual > 0);
64
+    }
65
+    @Test
66
+    public void compareToTest2() {
67
+        int actual = cc.compareTo(pp);
68
+        Assert.assertTrue(actual < 0);
69
+    }
70
+    @Test
71
+    public void compareToTest3() {
72
+        int actual = cc.compareTo(cc);
73
+        Assert.assertTrue(actual == 0);
74
+    }
75
+}

+ 59
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java 파일 보기

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+public class PayPalTest {
9
+    PayPal pp;
10
+    Check ch;
11
+    @Before
12
+    public void setup() {
13
+        pp = new PayPal(12345, "Sansa Stark", "ladystark@winterfell.com");
14
+        ch = new Check(12345, "Sansa Stark", "1234567", "987654321");
15
+
16
+    }
17
+
18
+    @Test
19
+    public void getIdTest() {
20
+        long expected = 12345;
21
+        long actual = pp.getId();
22
+        Assert.assertEquals(expected, actual);
23
+    }
24
+    @Test
25
+    public void getPayerNameTest() {
26
+        String expected = "Sansa Stark";
27
+        String actual = pp.getPayerName();
28
+        Assert.assertEquals(expected, actual);
29
+    }
30
+    @Test
31
+    public void getEmailTest() {
32
+        String expected = "ladystark@winterfell.com";
33
+        String actual = pp.getPayerEmail();
34
+        Assert.assertEquals(expected, actual);
35
+    }
36
+
37
+    @Test
38
+    public void getShortDescriptionTest() {
39
+        String expected = "Paypal Sansa Stark ladystark@winterfell.com";
40
+        String actual = pp.getShortDescription();
41
+        Assert.assertEquals(expected, actual);
42
+    }
43
+
44
+    @Test
45
+    public void compareToTest() {
46
+        int actual = pp.compareTo(ch);
47
+        Assert.assertTrue(actual > 0);
48
+    }
49
+    @Test
50
+    public void compareToTest2() {
51
+        int actual = ch.compareTo(pp);
52
+        Assert.assertTrue(actual < 0);
53
+    }
54
+    @Test
55
+    public void compareToTest3() {
56
+        int actual = pp.compareTo(pp);
57
+        Assert.assertTrue(actual == 0);
58
+    }
59
+}

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

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 {
7
+
8
+    @Test
9
+    public void toStringTest() {
10
+        Payment[] payments = new Payment[0];
11
+        PaymentPresenter presenter = new PaymentPresenter();
12
+        String expected = "";
13
+        String actual = presenter.toString(payments);
14
+        Assert.assertEquals(expected, actual);
15
+    }
16
+
17
+    @Test
18
+    public void toStringTest2() {
19
+        Payment[] payments = new Payment[2];
20
+        payments[0] = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
21
+        payments[1] = new Check(81L, "Tia Mowry", "11432543", "134344551");
22
+
23
+        PaymentPresenter pp = new PaymentPresenter();
24
+        String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
25
+
26
+        String actual = pp.toString(payments);
27
+        Assert.assertEquals(expected, actual);
28
+    }
29
+
30
+    @Test
31
+    public void toStringByPayerName() {
32
+        Payment[] payments = new Payment[2];
33
+        payments[1] = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
34
+        payments [0] = new Check(81L, "Tia Mowry", "11432543", "134344551");
35
+
36
+        PaymentPresenter presenter = new PaymentPresenter();
37
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
38
+
39
+        String actual = presenter.toStringByPayerName(payments);
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+    @Test
43
+    public void toStringByID() {
44
+        Payment[] payments = new Payment[2];
45
+        payments[1] = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
46
+        payments[0] = new Check(81L, "Tia Mowry", "11432543", "134344551");
47
+
48
+        PaymentPresenter presenter = new PaymentPresenter();
49
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
50
+
51
+        String actual = presenter.toStringByID(payments);
52
+        Assert.assertEquals(expected, actual);
53
+    }
54
+
4
 }
55
 }

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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PaymentSortByIdTest {
7
+    Check ch = new Check(1, "Sansa Stark", "1234567", "987654321");
8
+    PayPal pp = new PayPal(1, "Catelyn Stark", "ladystark@winterfell.com");
9
+    CreditCard cc = new CreditCard(123, "Robb Stark", "4444444444", 12, 2020);
10
+    Check ch2 = new Check(900, "Arya Stark", "1234569", "987654444");
11
+
12
+    PaymentSortById psbi = new PaymentSortById();
13
+
14
+
15
+    @Test
16
+    public void paymentSortByIdTest1() {
17
+        int expected = 0;
18
+        int actual = psbi.compare(ch, pp);
19
+        Assert.assertEquals(expected, actual);
20
+    }
21
+    @Test
22
+    public void paymentSortByIdTest2() {
23
+        int actual = psbi.compare(ch, cc);
24
+        Assert.assertTrue(actual < 0);
25
+    }
26
+    @Test
27
+    public void paymentSortByIdTest3() {
28
+        int actual = psbi.compare(ch2, cc);
29
+        Assert.assertTrue(actual > 0);
30
+    }
31
+}

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

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PaymentSortByPayerTest {
7
+    Check ch = new Check(12345, "Sansa Stark", "1234567", "987654321");
8
+    PayPal pp = new PayPal(12345, "Catelyn Stark", "ladystark@winterfell.com");
9
+    CreditCard cc = new CreditCard(12345, "Robb Stark", "4444444444", 12, 2020);
10
+    Check ch2 = new Check(9034, "Arya Stark", "1234569", "987654444");
11
+    PayPal pp2 = new PayPal(12345, "Sansa Stark", "ladystarkthesecond@winterfell.com");
12
+
13
+    PaymentSortByPayer psbp = new PaymentSortByPayer();
14
+
15
+
16
+    @Test
17
+    public void paymentSortByPayerTest1() {
18
+        int expected = 0;
19
+        int actual = psbp.compare(ch, pp2);
20
+        Assert.assertEquals(expected, actual);
21
+    }
22
+    @Test
23
+    public void paymentSortByPayerTest2() {
24
+        int actual = psbp.compare(ch, pp);
25
+        Assert.assertTrue(actual > 0);
26
+    }
27
+    @Test
28
+    public void paymentSortByPayerTest3() {
29
+        int actual = psbp.compare(ch2, cc);
30
+        Assert.assertTrue(actual < 0);
31
+    }
32
+}