Selaa lähdekoodia

up to paymentpresenter

Jamez-s 8 vuotta sitten
vanhempi
commit
a76f4b1558

BIN
.DS_Store Näytä tiedosto


+ 7
- 4
README.MD Näytä tiedosto

@@ -61,7 +61,7 @@
61 61
 # Section 2 - Comparable
62 62
 Note: You may use the String/Long compareTo methods in your code
63 63
 1. Edit the `Payment` class to extends the Comparable interface
64
-  - `public class Payment extends Comparable<Payment>`
64
+  - `public interface Payment extends Comparable<Payment>`
65 65
   - This indicate that payment can be comparable, which means it can be sorted
66 66
 2. Fix the syntax error in your CreditCard, Check, and Paypal class by adding the compare method
67 67
 3. Create a test for the `compareTo` method. Compare using the getShortDescription()
@@ -102,7 +102,8 @@ Note: You may use the String/Long compareTo methods in your code
102 102
     Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
103 103
 
104 104
     payment[0] = paypal;
105
-
105
+    payment[1] = check;
106
+    
106 107
     PaymentPresenter presenter = new PaymentPresenter();
107 108
     String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
108 109
 
@@ -119,11 +120,12 @@ Note: You may use the String/Long compareTo methods in your code
119 120
       Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
120 121
 
121 122
       payment[0] = paypal;
123
+      payment[1] = check;
122 124
 
123 125
       PaymentPresenter presenter = new PaymentPresenter();
124 126
       String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
125 127
 
126
-      String actual = presenter.toString(payments);
128
+      String actual = presenter.toStringByPayerName(payments);
127 129
       assertEquals(expected, actual);
128 130
     ```
129 131
     
@@ -136,10 +138,11 @@ Note: You may use the String/Long compareTo methods in your code
136 138
       Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
137 139
 
138 140
       payment[0] = paypal;
141
+      payment[1] = check;
139 142
 
140 143
       PaymentPresenter presenter = new PaymentPresenter();
141 144
       String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
142 145
 
143
-      String actual = presenter.toString(payments);
146
+      String actual = presenter.toStringById(payments);
144 147
       assertEquals(expected, actual);
145 148
     ```

+ 12
- 1
pom.xml Näytä tiedosto

@@ -7,6 +7,17 @@
7 7
     <groupId>com.zipcoder</groupId>
8 8
     <artifactId>payment</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
-
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+    </dependencies>
18
+    <properties>
19
+        <maven.compiler.source>1.8</maven.compiler.source>
20
+        <maven.compiler.target>1.8</maven.compiler.target>
21
+    </properties>
11 22
 
12 23
 </project>

BIN
src/.DS_Store Näytä tiedosto


BIN
src/main/.DS_Store Näytä tiedosto


BIN
src/main/java/.DS_Store Näytä tiedosto


BIN
src/main/java/com/.DS_Store Näytä tiedosto


BIN
src/main/java/com/zipcoder/.DS_Store Näytä tiedosto


+ 54
- 42
src/main/java/com/zipcoder/payment/Check.java Näytä tiedosto

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

+ 77
- 71
src/main/java/com/zipcoder/payment/CreditCard.java Näytä tiedosto

@@ -1,75 +1,81 @@
1 1
 package com.zipcoder.payment;
2 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() {
12
-    }
13
-
14
-    public CreditCard(Long id, String payerName, String number, int expiredMonth, int expiredYear) {
15
-        this.id = id;
16
-        this.payerName = payerName;
17
-        this.number = number;
18
-        this.expiredMonth = expiredMonth;
19
-        this.expiredYear = expiredYear;
20
-    }
21
-
22
-    public int getExpiredYear() {
23
-        return expiredYear;
24
-    }
25
-
26
-    public void setExpiredYear(int expiredYear) {
27
-        this.expiredYear = expiredYear;
28
-    }
29
-
30
-    public String getNumber() {
31
-        return number;
32
-    }
33
-
34
-    public void setNumber(String number) {
35
-        this.number = number;
36
-    }
37
-
38
-    public int getExpiredMonth() {
39
-        return expiredMonth;
40
-    }
41
-
42
-    public void setExpiredMonth(int expiredMonth) {
43
-        this.expiredMonth = expiredMonth;
44
-    }
45
-
46
-    public Long getId() {
47
-        return id;
48
-    }
49
-
50
-    public void setId(Long id) {
51
-        this.id = id;
52
-    }
53
-
54
-    public String getPayerName() {
55
-        return payerName;
56
-    }
57
-
58
-    public void setPayerName(String payerName) {
59
-        this.payerName = payerName;
60
-    }
61
-
62
-    public String getShortDescription() {
63
-        String lastFourDigitsOfNumber = number.substring(number.length() - 4, number.length());
64
-        String expiredMonthStringValue = String.valueOf(expiredMonth);
65
-        if (expiredMonth < 10) {
66
-            expiredMonthStringValue = "0" + expiredMonthStringValue;
67
-        }
68
-        return "CC " + payerName + " " + lastFourDigitsOfNumber + " " + expiredMonthStringValue + "/" + expiredYear;
69
-    }
70
-
71
-    public int compareTo(Payment o) {
72
-        return this.id.compareTo(o.getId());
73
-    }
3
+public class CreditCard implements Payments{
74 4
 
5
+
6
+	Long id;
7
+	String payerName;
8
+	String number;
9
+	int expiredMonth;
10
+	int expiredYear;
11
+
12
+	public CreditCard(Long id, String payerName, String number, int expiredMonth, int expiredYear) {
13
+		this.id = id;
14
+		this.payerName = payerName;
15
+		this.number = number;
16
+		this.expiredMonth = expiredMonth;
17
+		this.expiredYear = expiredYear;
18
+	}
19
+
20
+	public CreditCard(){}
21
+
22
+	public String getNumber() {
23
+		return number;
24
+	}
25
+
26
+	public void setNumber(String number) {
27
+		this.number = number;
28
+	}
29
+
30
+	public int getExpiredMonth() {
31
+		return expiredMonth;
32
+	}
33
+
34
+	public void setExpiredMonth(int expiredMonth) {
35
+		this.expiredMonth = expiredMonth;
36
+	}
37
+
38
+	public int getExpiredYear() {
39
+		return expiredYear;
40
+	}
41
+
42
+	public void setExpiredYear(int expiredYear) {
43
+		this.expiredYear = expiredYear;
44
+	}
45
+
46
+
47
+
48
+	public void setId(Long id) {
49
+		this.id = id;
50
+	}
51
+
52
+	public Long getID() {
53
+		return id;
54
+	}
55
+
56
+
57
+	public String getPayerName() {
58
+		return payerName;
59
+	}
60
+
61
+
62
+	public String getShortDescription() {
63
+		return "CC " + payerName + " "+number.substring(number.length()-4, number.length())+" "+expiredMonth+"/"+expiredYear;
64
+	}
65
+
66
+
67
+	public void setPayerName(String payerName) {
68
+		this.payerName = payerName;
69
+	}
70
+
71
+	@Override
72
+	public int compareTo(Payments o) {
73
+		return this.getShortDescription().compareTo(o.getShortDescription());
74
+	}
75
+
76
+
77
+//	@Override
78
+//	public int compareTo(Payments o) {
79
+//		return 0;
80
+//	}
75 81
 }

+ 0
- 11
src/main/java/com/zipcoder/payment/Payment.java Näytä tiedosto

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

+ 11
- 29
src/main/java/com/zipcoder/payment/PaymentPresenter.java Näytä tiedosto

@@ -1,34 +1,16 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
-import java.util.Arrays;
3
+		import java.util.Arrays;
4
+		import java.util.Comparator;
4 5
 
5 6
 public class PaymentPresenter {
6 7
 
7
-
8
-    public String toString(Payment[] payments) {
9
-
10
-        Arrays.sort(payments, new PaymentSortByShortDescription());
11
-
12
-        return createString(payments);
13
-    }
14
-
15
-    public String toStringByPayerName(Payment[] payments) {
16
-        Arrays.sort(payments, new PaymentSortByPayer());
17
-
18
-        return createString(payments);
19
-    }
20
-
21
-    public String toStringById(Payment[] payments) {
22
-        Arrays.sort(payments);
23
-
24
-        return createString(payments);
25
-    }
26
-
27
-    private String createString(Payment[] payments) {
28
-        String retVal = "";
29
-        for (Payment payment : payments) {
30
-            retVal += payment.getShortDescription() + "\n";
31
-        }
32
-        return retVal;
33
-    }
34
-}
8
+	public String toString(Payments[] payments) {
9
+		StringBuilder sb = new StringBuilder();
10
+		Arrays.sort(payments);
11
+		for (int i = 0; i < payments.length; i++) {
12
+			payments[i].getShortDescription().toString();
13
+		}
14
+		return null;
15
+	}
16
+}

+ 7
- 5
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Näytä tiedosto

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

+ 0
- 9
src/main/java/com/zipcoder/payment/PaymentSortByShortDescription.java Näytä tiedosto

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

+ 13
- 0
src/main/java/com/zipcoder/payment/Payments.java Näytä tiedosto

@@ -0,0 +1,13 @@
1
+package com.zipcoder.payment;
2
+
3
+public interface Payments extends Comparable<Payments>{
4
+
5
+	public Long getID();
6
+	public void setId(Long id);
7
+	public String getPayerName();
8
+	public String getShortDescription();
9
+
10
+	void setPayerName(String payerName);
11
+}
12
+
13
+

+ 45
- 24
src/main/java/com/zipcoder/payment/Paypal.java Näytä tiedosto

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

BIN
src/test/.DS_Store Näytä tiedosto


+ 90
- 11
src/test/java/com/zipcoder/payment/CheckTest.java Näytä tiedosto

@@ -1,20 +1,99 @@
1 1
 package com.zipcoder.payment;
2 2
 
3 3
 import org.junit.Assert;
4
+import org.junit.Before;
4 5
 import org.junit.Test;
5 6
 
6 7
 public class CheckTest {
8
+	Check test = new Check();
7 9
 
8
-    @Test
9
-    public void getShortDescriptionTest() {
10
-        // Arrange
11
-        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
12
-        String expected = "Check Tia Mowry ***4551";
13 10
 
14
-        // Act
15
-        String actual = check.getShortDescription();
11
+	@Before
12
+	public void setup() {
13
+	}
16 14
 
17
-        // Assert
18
-        Assert.assertEquals(expected, actual);
19
-    }
20
-}
15
+	@Test
16
+	public void getIdTest() {
17
+		//When
18
+		test.setId(23L);
19
+
20
+		// Expect
21
+		Long expect = 23L;
22
+
23
+		//Actual
24
+		Long actual = test.getID();
25
+
26
+		Assert.assertEquals(expect, actual);
27
+	}
28
+
29
+	@Test
30
+	public void setIdTest() {
31
+		test.setId(30L);
32
+
33
+		Long expect = 30L;
34
+
35
+		Long actual = test.getID();
36
+
37
+		Assert.assertEquals(expect, actual);
38
+	}
39
+
40
+
41
+	@Test
42
+	public void getPayerName() {
43
+		test.setPayerName("Tia Mowry");
44
+
45
+		String expect = "Tia Mowry";
46
+		String actual = test.getPayerName();
47
+
48
+		Assert.assertEquals(expect, actual);
49
+	}
50
+
51
+	@Test
52
+	public void getShortDescription() {
53
+		test.setPayerName("Tia Mowry");
54
+		test.setAccountNumber("4551");
55
+
56
+		String expect = "Check Tia Mowry ***4551";
57
+		String actual = test.getShortDescription();
58
+
59
+		Assert.assertEquals(expect, actual);
60
+	}
61
+
62
+	@Test
63
+	public void getAccountNumber() {
64
+		test.setAccountNumber("4551");
65
+
66
+		String expect = "4551";
67
+		String actual = test.getAccountNumber();
68
+
69
+		Assert.assertEquals(expect, actual);
70
+
71
+	}
72
+
73
+	@Test
74
+	public void getRoutingNumber() {
75
+		test.setRoutingNumber("904551");
76
+
77
+		String expect = "904551";
78
+		String actual = test.getRoutingNumber();
79
+
80
+		Assert.assertEquals(expect, actual);
81
+
82
+	}
83
+
84
+
85
+	@Test
86
+	public void compareToTest() {
87
+
88
+		test.setPayerName("Tia Mowry");
89
+		test.setAccountNumber("904551");
90
+
91
+		Check test1 = new Check();
92
+		test1.setPayerName("Tia Mowry");
93
+		test1.setAccountNumber("904551");
94
+
95
+		int actual = test.getShortDescription().compareTo(test1.getShortDescription());
96
+		Assert.assertTrue(actual == 0);
97
+
98
+	}
99
+}

+ 93
- 96
src/test/java/com/zipcoder/payment/CreditCardTest.java Näytä tiedosto

@@ -1,103 +1,100 @@
1 1
 package com.zipcoder.payment;
2 2
 
3 3
 import org.junit.Assert;
4
+import org.junit.Before;
4 5
 import org.junit.Test;
5 6
 
6 7
 public class CreditCardTest {
8
+	CreditCard test = new CreditCard();
7 9
 
8
-    @Test
9
-    public void idTest() {
10
-        // Arrange
11
-        CreditCard creditCard = new CreditCard();
12
-        Long expectedId = 100L;
13
-        creditCard.setId(expectedId);
14
-
15
-        // Act
16
-        Long actualId = creditCard.getId();
17
-
18
-        // Assert
19
-        Assert.assertEquals(expectedId, actualId);
20
-    }
21
-
22
-    @Test
23
-    public void payerNameTest() {
24
-        // Arrange
25
-        CreditCard creditCard = new CreditCard();
26
-        String expectedPayerName = "Joe";
27
-        creditCard.setPayerName(expectedPayerName);
28
-
29
-        // Act
30
-        String actualPayerName = creditCard.getPayerName();
31
-
32
-        // Assert
33
-        Assert.assertEquals(expectedPayerName, actualPayerName);
34
-    }
35
-
36
-    @Test
37
-    public void numberTest() {
38
-        // Arrange
39
-        CreditCard creditCard = new CreditCard();
40
-        String expectedNumber = "12345";
41
-        creditCard.setNumber(expectedNumber);
42
-
43
-        // Act
44
-        String actualNumber = creditCard.getNumber();
45
-
46
-        // Assert
47
-        Assert.assertEquals(expectedNumber, actualNumber);
48
-    }
49
-
50
-    @Test
51
-    public void expiredMonthTest() {
52
-        // Arrange
53
-        CreditCard creditCard = new CreditCard();
54
-        int expectedExpiredMonth = 2;
55
-        creditCard.setExpiredMonth(expectedExpiredMonth);
56
-
57
-        // Act
58
-        int actualExpiredMonth = creditCard.getExpiredMonth();
59
-
60
-        // Assert
61
-        Assert.assertEquals(expectedExpiredMonth, actualExpiredMonth);
62
-    }
63
-
64
-    @Test
65
-    public void expiredYearTest() {
66
-        // Arrange
67
-        CreditCard creditCard = new CreditCard();
68
-        int expectedExpiredYear = 2019;
69
-        creditCard.setExpiredYear(expectedExpiredYear);
70
-
71
-        // Act
72
-        int actualExpiredYear = creditCard.getExpiredYear();
73
-
74
-        // Assert
75
-        Assert.assertEquals(expectedExpiredYear, actualExpiredYear);
76
-    }
77
-
78
-    @Test
79
-    public void getShortDescription_DoubleDigitMonth_ShouldReturnShortDescription() {
80
-        // Arrange
81
-        CreditCard creditCard = new CreditCard(284914091L, "John Doe", "1234567890123456", 11, 2001);
82
-        String expectedShortDescription = "CC John Doe 3456 11/2001";
83
-
84
-        // Act
85
-        String actualShortDescription = creditCard.getShortDescription();
86
-
87
-        // Assert
88
-        Assert.assertEquals(expectedShortDescription, actualShortDescription);
89
-    }
90
-
91
-    @Test
92
-    public void getShortDescription_SingleDigitMonth_ShouldReturnShortDescription() {
93
-        // Arrange
94
-        CreditCard creditCard = new CreditCard(284914091L, "John Doe", "1234567890123456", 1, 2001);
95
-        String expectedShortDescription = "CC John Doe 3456 01/2001";
96
-
97
-        // Act
98
-        String actualShortDescription = creditCard.getShortDescription();
99
-
100
-        // Assert
101
-        Assert.assertEquals(expectedShortDescription, actualShortDescription);
102
-    }
103
-}
10
+
11
+	@Before
12
+	public void setup() {
13
+	}
14
+
15
+	@Test
16
+	public void getIdTest() {
17
+		//When
18
+		test.setId(23L);
19
+
20
+		// Expect
21
+		Long expect = 23L;
22
+
23
+		//Actual
24
+		Long actual = test.getID();
25
+
26
+		Assert.assertEquals(expect, actual);
27
+	}
28
+
29
+	@Test
30
+	public void setIdTest() {
31
+		test.setId(30L);
32
+
33
+		Long expect = 30L;
34
+
35
+		Long actual = test.getID();
36
+
37
+		Assert.assertEquals(expect, actual);
38
+	}
39
+
40
+
41
+	@Test
42
+	public void getPayerName() {
43
+		test.setPayerName("Tia Mowry");
44
+
45
+		String expect = "Tia Mowry";
46
+		String actual = test.getPayerName();
47
+
48
+		Assert.assertEquals(expect, actual);
49
+	}
50
+
51
+	@Test
52
+	public void getShortDescription() {
53
+		test.setPayerName("Tia Mowry");
54
+		test.setNumber("4551");
55
+		test.setExpiredMonth(10);
56
+		test.setExpiredYear(2019);
57
+
58
+
59
+		String expect = "CC Tia Mowry 4551 10/2019";
60
+		String actual = test.getShortDescription();
61
+
62
+		Assert.assertEquals(expect, actual);
63
+	}
64
+
65
+	@Test
66
+	public void getNumberTest() {
67
+		test.setNumber("4551");
68
+
69
+		String expect = "4551";
70
+		String actual = test.getNumber();
71
+
72
+		Assert.assertEquals(expect, actual);
73
+
74
+	}
75
+
76
+
77
+	@Test
78
+	public void getExpiredMonth() {
79
+		test.setExpiredMonth(9);
80
+
81
+		int expect = 9;
82
+		int actual = test.getExpiredMonth();
83
+
84
+		Assert.assertEquals(expect, actual);
85
+	}
86
+
87
+	@Test
88
+	public void compareToTest() {
89
+
90
+		test.setPayerName("Tia Mowry");
91
+		test.setNumber("4551");
92
+
93
+		Check test1 = new Check();
94
+		test1.setPayerName("Tia Mowry");
95
+		test1.setAccountNumber("***4551");
96
+
97
+		int actual = test.getShortDescription().compareTo(test1.getShortDescription());
98
+		Assert.assertTrue(actual < 0);
99
+	}
100
+}

+ 38
- 0
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Näytä tiedosto

@@ -0,0 +1,38 @@
1
+package com.zipcoder.payment;
2
+
3
+import java.util.Arrays;
4
+import org.junit.Assert;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+import static org.junit.Assert.assertEquals;
9
+
10
+public class PaymentPresenterTest {
11
+
12
+
13
+	@Before
14
+	public void setup() {
15
+		StringBuilder sb = new StringBuilder();
16
+	}
17
+
18
+
19
+
20
+	@Test
21
+	public void toStringNoPayment() {
22
+
23
+		Payments[] payments = new Payments[0];
24
+		PaymentPresenter presenter = new PaymentPresenter();
25
+		String expected = "";
26
+
27
+		String actual = presenter.toString(payments);
28
+
29
+		assertEquals(expected, actual);
30
+	}
31
+
32
+	@Test
33
+
34
+	public void multiplesToStringById() {
35
+
36
+	}
37
+
38
+}

+ 29
- 0
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java Näytä tiedosto

@@ -0,0 +1,29 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+public class PaymentSortByPayerTest {
8
+
9
+	CreditCard check1;
10
+	Check check2;
11
+
12
+	PaymentSortByPayer paymentSortByPayer;
13
+
14
+	@Before
15
+
16
+	public void setup(){
17
+		paymentSortByPayer = new PaymentSortByPayer();
18
+		check1 = new CreditCard(0L,"James","4033",10,2000);
19
+		check2 = new Check(201111L, "James", "334344", "343423434");
20
+	}
21
+
22
+	@Test
23
+	public void compareTest(){
24
+
25
+		int actual = paymentSortByPayer.compare(check1, check2);
26
+
27
+		Assert.assertTrue(actual ==0);
28
+	}
29
+}

+ 69
- 0
src/test/java/com/zipcoder/payment/PaypalTest.java Näytä tiedosto

@@ -0,0 +1,69 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+
8
+public class PaypalTest {
9
+
10
+	Paypal test;
11
+
12
+	@Before
13
+	public void setup() {
14
+		test = new Paypal();
15
+	}
16
+
17
+	@Test
18
+	public void getID() {
19
+		//When
20
+		test.setId(23L);
21
+
22
+		// Expect
23
+		Long expect = 23L;
24
+
25
+		//Actual
26
+		Long actual = test.getID();
27
+
28
+		Assert.assertEquals(expect, actual);
29
+	}
30
+
31
+
32
+	@Test
33
+	public void getPayerName() {
34
+		//When
35
+		test.setPayerName("Tia Mowry");
36
+
37
+		// Expect
38
+		String expect = "Tia Mowry";
39
+
40
+		//Actual
41
+		String actual = test.getPayerName();
42
+
43
+		Assert.assertEquals(expect, actual);
44
+	}
45
+
46
+
47
+	@Test
48
+	public void getShortDescription() {
49
+		test.setPayerName("Tia Mowry");
50
+		test.setEmail("tia@mowry.com");
51
+
52
+		String expect = "Paypal Tia Mowry tia@mowry.com";
53
+		String actual = test.getShortDescription();
54
+	}
55
+
56
+	@Test
57
+	public void compareTo() {
58
+		test.setPayerName("Tia Mowry");
59
+		test.setEmail("tia@mowry.com");
60
+
61
+		Check test1 = new Check();
62
+		test1.setPayerName("Tia Mowry");
63
+		test1.setAccountNumber("***4551");
64
+
65
+		int actual = test.getShortDescription().compareTo(test1.getShortDescription());
66
+		Assert.assertTrue(actual > 0);
67
+
68
+	}
69
+}

+ 0
- 20
src/test/java/com/zipcoder/payment/PaypalTests.java Näytä tiedosto

@@ -1,20 +0,0 @@
1
-package com.zipcoder.payment;
2
-
3
-import org.junit.Assert;
4
-import org.junit.Test;
5
-
6
-public class PaypalTests {
7
-
8
-    @Test
9
-    public void getShortDescriptionTest() {
10
-        // Arrange
11
-        Paypal paypal = new Paypal(100L, "Tia Mowry", "tia@mowry.com");
12
-        String expectedShortDescription = "Paypal Tia Mowry tia@mowry.com";
13
-
14
-        // Act
15
-        String actualShortDescription = paypal.getShortDescription();
16
-
17
-        // Assert
18
-        Assert.assertEquals(expectedShortDescription, actualShortDescription);
19
-    }
20
-}