CHU1TA26 6 years ago
parent
commit
c5c810c545

+ 8
- 0
pom.xml View File

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

+ 6
- 0
src/.idea/misc.xml View File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="JavaScriptSettings">
4
+    <option name="languageLevel" value="ES6" />
5
+  </component>
6
+</project>

+ 8
- 0
src/.idea/modules.xml View File

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/.idea/src.iml" filepath="$PROJECT_DIR$/.idea/src.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 6
- 0
src/.idea/vcs.xml View File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5
+  </component>
6
+</project>

+ 152
- 0
src/.idea/workspace.xml View File

@@ -0,0 +1,152 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ChangeListManager">
4
+    <list default="true" id="2981891f-d055-44c6-91ac-179b59e85706" name="Default Changelist" comment="">
5
+      <change afterPath="$PROJECT_DIR$/main/java/com/zipcoder/payment/CreditCard.java" afterDir="false" />
6
+      <change afterPath="$PROJECT_DIR$/main/java/com/zipcoder/payment/Payment.java" afterDir="false" />
7
+      <change afterPath="$PROJECT_DIR$/test/java/com/zipcoder/payment/CreditCardTest.java" afterDir="false" />
8
+    </list>
9
+    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
10
+    <option name="SHOW_DIALOG" value="false" />
11
+    <option name="HIGHLIGHT_CONFLICTS" value="true" />
12
+    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
13
+    <option name="LAST_RESOLUTION" value="IGNORE" />
14
+  </component>
15
+  <component name="FUSProjectUsageTrigger">
16
+    <session id="-2001832802">
17
+      <usages-collector id="statistics.lifecycle.project">
18
+        <counts>
19
+          <entry key="project.closed" value="1" />
20
+          <entry key="project.open.time.1" value="1" />
21
+          <entry key="project.opened" value="1" />
22
+        </counts>
23
+      </usages-collector>
24
+    </session>
25
+  </component>
26
+  <component name="Git.Settings">
27
+    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
28
+  </component>
29
+  <component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
30
+  <component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
31
+  <component name="JsGulpfileManager">
32
+    <detection-done>true</detection-done>
33
+    <sorting>DEFINITION_ORDER</sorting>
34
+  </component>
35
+  <component name="ProjectFrameBounds">
36
+    <option name="x" value="123" />
37
+    <option name="y" value="45" />
38
+    <option name="width" value="1086" />
39
+    <option name="height" value="677" />
40
+  </component>
41
+  <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
42
+  <component name="ProjectView">
43
+    <navigator proportions="" version="1">
44
+      <foldersAlwaysOnTop value="true" />
45
+    </navigator>
46
+    <panes>
47
+      <pane id="ProjectPane">
48
+        <subPane>
49
+          <expand>
50
+            <path>
51
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
52
+              <item name="src" type="462c0819:PsiDirectoryNode" />
53
+            </path>
54
+          </expand>
55
+          <select />
56
+        </subPane>
57
+      </pane>
58
+      <pane id="PackagesPane" />
59
+      <pane id="Scope" />
60
+    </panes>
61
+  </component>
62
+  <component name="PropertiesComponent">
63
+    <property name="WebServerToolWindowFactoryState" value="false" />
64
+    <property name="aspect.path.notification.shown" value="true" />
65
+    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
66
+    <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
67
+    <property name="nodejs_npm_path_reset_for_default_project" value="true" />
68
+  </component>
69
+  <component name="RunDashboard">
70
+    <option name="ruleStates">
71
+      <list>
72
+        <RuleState>
73
+          <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
74
+        </RuleState>
75
+        <RuleState>
76
+          <option name="name" value="StatusDashboardGroupingRule" />
77
+        </RuleState>
78
+      </list>
79
+    </option>
80
+  </component>
81
+  <component name="SvnConfiguration">
82
+    <configuration />
83
+  </component>
84
+  <component name="TaskManager">
85
+    <task active="true" id="Default" summary="Default task">
86
+      <changelist id="2981891f-d055-44c6-91ac-179b59e85706" name="Default Changelist" comment="" />
87
+      <created>1541816097890</created>
88
+      <option name="number" value="Default" />
89
+      <option name="presentableId" value="Default" />
90
+      <updated>1541816097890</updated>
91
+      <workItem from="1541816099311" duration="26000" />
92
+    </task>
93
+    <servers />
94
+  </component>
95
+  <component name="TimeTrackingManager">
96
+    <option name="totallyTimeSpent" value="26000" />
97
+  </component>
98
+  <component name="ToolWindowManager">
99
+    <frame x="123" y="45" width="1086" height="677" extended-state="0" />
100
+    <layout>
101
+      <window_info id="Image Layers" />
102
+      <window_info id="Designer" />
103
+      <window_info id="UI Designer" />
104
+      <window_info id="Capture Tool" />
105
+      <window_info id="Favorites" side_tool="true" />
106
+      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25" />
107
+      <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
108
+      <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
109
+      <window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
110
+      <window_info anchor="bottom" id="Terminal" />
111
+      <window_info anchor="bottom" id="Event Log" side_tool="true" />
112
+      <window_info anchor="bottom" id="Message" order="0" />
113
+      <window_info anchor="bottom" id="Find" order="1" />
114
+      <window_info anchor="bottom" id="Run" order="2" />
115
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
116
+      <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
117
+      <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
118
+      <window_info anchor="bottom" id="TODO" order="6" />
119
+      <window_info anchor="right" id="Palette" />
120
+      <window_info anchor="right" id="Theme Preview" />
121
+      <window_info anchor="right" id="Capture Analysis" />
122
+      <window_info anchor="right" id="Palette&#9;" />
123
+      <window_info anchor="right" id="Database" />
124
+      <window_info anchor="right" id="Maven Projects" />
125
+      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
126
+      <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
127
+      <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
128
+    </layout>
129
+  </component>
130
+  <component name="TypeScriptGeneratedFilesManager">
131
+    <option name="version" value="1" />
132
+  </component>
133
+  <component name="VcsContentAnnotationSettings">
134
+    <option name="myLimit" value="2678400000" />
135
+  </component>
136
+  <component name="masterDetails">
137
+    <states>
138
+      <state key="ProjectJDKs.UI">
139
+        <settings>
140
+          <last-edited>1.8</last-edited>
141
+          <splitter-proportions>
142
+            <option name="proportions">
143
+              <list>
144
+                <option value="0.2" />
145
+              </list>
146
+            </option>
147
+          </splitter-proportions>
148
+        </settings>
149
+      </state>
150
+    </states>
151
+  </component>
152
+</project>

+ 82
- 0
src/main/java/com/zipcoder/payment/Check.java View File

@@ -0,0 +1,82 @@
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(){
10
+        this.id=id;
11
+        this.payerName = payerName;
12
+        this.accountNumber = accountNumber;
13
+        this.routingNumber=routingNumber;
14
+    }
15
+
16
+
17
+    public Check(Long id, String payerName,String routingNumber, String accountNumber) {
18
+        this.payerName = payerName;
19
+        this.accountNumber = accountNumber;
20
+        this.id=id;
21
+        this.routingNumber=routingNumber;
22
+    }
23
+
24
+    public void setId(Long id) {
25
+        this.id = id;
26
+    }
27
+    @Override
28
+    public Long getId() {
29
+        return  id;
30
+    }
31
+
32
+
33
+    @Override
34
+    public String getPayerName() {
35
+        return payerName;
36
+    }
37
+
38
+    @Override
39
+    public String getShortDescription() {
40
+        return  "Check " + getPayerName() + " ***"+ getLast4Digit();
41
+    }
42
+
43
+
44
+    public void setPayerName(String payerName) {
45
+        this.payerName = payerName;
46
+    }
47
+
48
+    public String getRoutingNumber() {
49
+        return routingNumber;
50
+    }
51
+
52
+    public void setRoutingNumber(String routingNumber) {
53
+        this.routingNumber = routingNumber;
54
+    }
55
+
56
+    public String getAccountNumber() {
57
+        return accountNumber;
58
+    }
59
+
60
+    public void setAccountNumber(String accountNumber) {
61
+        this.accountNumber = accountNumber;
62
+    }
63
+
64
+
65
+
66
+    public String getLast4Digit() {
67
+        String str="";
68
+        if (accountNumber.length() == 4) {
69
+            str= accountNumber;
70
+        } else if (accountNumber.length() > 4) {
71
+            str= accountNumber.substring(accountNumber.length() - 4);
72
+
73
+        }
74
+        return str;
75
+    }
76
+
77
+    @Override
78
+    public int compareTo(Payment other) {
79
+
80
+        return this.getShortDescription().compareTo(other.getShortDescription());
81
+     }
82
+}

+ 97
- 0
src/main/java/com/zipcoder/payment/CreditCard.java View File

@@ -0,0 +1,97 @@
1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment {
4
+
5
+
6
+    private  long id;
7
+    private String payerName;
8
+    private String number;
9
+    int expiredMonth;
10
+    int expiredYear;
11
+
12
+    public CreditCard() {
13
+        this.id = id;
14
+        this.payerName = payerName;
15
+        this.number = number;
16
+        this.expiredMonth = expiredMonth;
17
+        this.expiredYear = expiredYear;
18
+
19
+    }
20
+
21
+
22
+    public CreditCard(Long id, String payerName, String number, int expiredMonth, int expiredYear) {
23
+        this.payerName = payerName;
24
+        this.number = number;
25
+        this.expiredMonth = expiredMonth;
26
+        this.expiredYear = expiredYear;
27
+
28
+    }
29
+
30
+    public void setPayerName(String payerName) {
31
+        this.payerName = payerName;
32
+    }
33
+
34
+    public String getNumber() {
35
+        return number;
36
+    }
37
+    public String getLast4Digit() {
38
+        String str="";
39
+        if (number.length() == 4) {
40
+            str= number;
41
+        } else if (number.length() > 4) {
42
+            str= number.substring(number.length() - 4);
43
+
44
+        }
45
+        return str;
46
+    }
47
+
48
+    public void setNumber(String number) {
49
+        this.number = number;
50
+    }
51
+
52
+    public int getExpiredMonth() {
53
+        return expiredMonth;
54
+    }
55
+
56
+    public void setExpiredMonth(int expiredMonth) {
57
+        this.expiredMonth = expiredMonth;
58
+    }
59
+
60
+    public int getExpiredYear() {
61
+        return expiredYear;
62
+    }
63
+
64
+    public void setExpiredYear(int expiredYear) {
65
+        this.expiredYear = expiredYear;
66
+    }
67
+
68
+    @Override
69
+    public Long getId() {
70
+
71
+        return id;
72
+    }
73
+
74
+    @Override
75
+    public String getPayerName() {
76
+
77
+        return payerName;
78
+    }
79
+
80
+    @Override
81
+    public String getShortDescription() {
82
+    CreditCard cc = new CreditCard();
83
+
84
+        return  "Credit Card  "+ payerName +" *** " + getLast4Digit()+ " "+ expiredMonth +"/" +expiredYear ;
85
+    }
86
+
87
+
88
+    public void setId(long id) {
89
+        this.id = id;
90
+    }
91
+
92
+    @Override
93
+    public int compareTo(Payment other) {
94
+        return this.getShortDescription().compareTo(other.getShortDescription());
95
+
96
+    }
97
+}

+ 57
- 0
src/main/java/com/zipcoder/payment/PayPal.java View File

@@ -0,0 +1,57 @@
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(){
10
+        this.payerName = payerName;
11
+        this.email = email;
12
+        this.id=id;
13
+    }
14
+
15
+    public PayPal(Long id, String payerName, String email) {
16
+        this.payerName = payerName;
17
+        this.email = email;
18
+        this.id=id;
19
+    }
20
+
21
+    public void setPayerName(String payerName) {
22
+        this.payerName = payerName;
23
+    }
24
+
25
+    public String getEmail() {
26
+        return email;
27
+    }
28
+
29
+    public void setEmail(String email) {
30
+        this.email = email;
31
+    }
32
+
33
+    public void setId(Long id) {
34
+        this.id = id;
35
+    }
36
+
37
+    @Override
38
+    public Long getId() {
39
+        return id;
40
+    }
41
+
42
+    @Override
43
+    public String getPayerName() {
44
+        return payerName;
45
+    }
46
+
47
+    @Override
48
+    public String getShortDescription() {
49
+        return "Paypal " + getPayerName() + " " + getEmail();
50
+    }
51
+
52
+    @Override
53
+    public int compareTo(Payment other) {
54
+        return this.getShortDescription().compareTo(other.getShortDescription());
55
+
56
+    }
57
+}

+ 8
- 0
src/main/java/com/zipcoder/payment/Payment.java View File

@@ -0,0 +1,8 @@
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
+}

+ 63
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java View File

@@ -1,6 +1,69 @@
1 1
 package com.zipcoder.payment;
2 2
 
3 3
 public class PaymentPresenter {
4
+    public String toString(Payment [] payments){
5
+        Payment temp;
6
+        for (int i = 0; i < payments.length; i++) {
7
+            for (int j = i + 1; j < payments.length; j++) {
8
+                if (payments[i].compareTo(payments[j]) > 0) {
9
+                    temp = payments[j];
10
+                    payments[j] = payments[i];
11
+                    payments[i] = temp;
12
+                }
13
+            }
14
+        }
4 15
 
16
+        String paymentsList = "";
17
+        for (Payment payment : payments) {
18
+            paymentsList += payment.getShortDescription() + "\n";
19
+        }
20
+        return paymentsList;
21
+
22
+    }
23
+
24
+
25
+
26
+    public String toStringByPayerName(Payment[] payments) {
27
+        PaymentSortByPayer paymentSortByPayer = new PaymentSortByPayer();
28
+        Payment temp;
29
+        for (int i = 0; i < payments.length; i++) {
30
+            for (int j = i + 1; j < payments.length; j++) {
31
+                if (paymentSortByPayer.compare(payments[i], (payments[j])) > 0) {
32
+                    temp = payments[j];
33
+                    payments[j] = payments[i];
34
+                    payments[i] = temp;
35
+                }
36
+            }
37
+        }
38
+
39
+        String paymentsList = "";
40
+        for (Payment payment : payments) {
41
+            paymentsList += payment.getShortDescription() + "\n";
42
+        }
43
+        return paymentsList;
44
+    }
45
+
46
+
47
+
48
+
49
+    public String toStringById(Payment[] payments) {
50
+
51
+        Payment temp;
52
+        for (int i = 0; i < payments.length; i++) {
53
+            for (int j = i + 1; j < payments.length; j++) {
54
+                if (payments[i].getId() > payments[j].getId()) {
55
+                    temp = payments[j];
56
+                    payments[j] = payments[i];
57
+                    payments[i] = temp;
58
+                }
59
+            }
60
+        }
61
+
62
+        String paymentsList = "";
63
+        for (Payment payment : payments) {
64
+            paymentsList += payment.getShortDescription() + "\n";
65
+        }
66
+        return paymentsList;
67
+    }
5 68
 
6 69
 }

+ 10
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java View File

@@ -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
+}

+ 87
- 0
src/test/java/com/zipcoder/payment/CheckTest.java View File

@@ -0,0 +1,87 @@
1
+package com.zipcoder.payment;
2
+
3
+
4
+import org.junit.Assert;
5
+import org.junit.Test;
6
+
7
+public class CheckTest {
8
+
9
+     @Test
10
+        public void testGetId(){
11
+            //given
12
+            Check check = new Check();
13
+            long id = 3;
14
+            check.setId(id);
15
+            //when
16
+            long actualId= check.getId();
17
+            //then
18
+
19
+            Assert.assertEquals(id,actualId);
20
+        }
21
+        @Test
22
+        public void testGetPayerName(){
23
+            //given
24
+           Check  check = new Check();
25
+            String name = "Nury";
26
+            check.setPayerName(name);
27
+            //when
28
+            String actual= check.getPayerName();
29
+            //then
30
+
31
+            Assert.assertEquals(name,actual);
32
+
33
+
34
+        }
35
+
36
+        @Test
37
+        public void testGetAccoungNumber(){
38
+            //given
39
+            Check check = new Check();
40
+            String number = "99999";
41
+            check.setAccountNumber(number);
42
+            //when
43
+            String actual= check.getAccountNumber();
44
+            //then
45
+
46
+            Assert.assertEquals(number,actual);
47
+
48
+
49
+        }
50
+        @Test
51
+        public void testGetRoutingNumber(){
52
+            //given
53
+           Check check = new Check();
54
+            String routingNumber = "999";
55
+            check.setRoutingNumber(routingNumber);
56
+            //when
57
+            String actual= check.getRoutingNumber();
58
+            //then
59
+
60
+            Assert.assertEquals(routingNumber,actual);
61
+
62
+
63
+        }
64
+    @Test
65
+    public void testGetLast4Digit(){
66
+        Check check = new Check();
67
+        String  id = "9999989";
68
+        String expectedId= "9989";
69
+        check.setAccountNumber(id);
70
+
71
+        //when
72
+        String actual=check.getLast4Digit();
73
+        //System.out.print(check.getLast4Digit());
74
+        //then
75
+        Assert.assertEquals(expectedId,actual);
76
+
77
+    }
78
+    @Test
79
+    public void testGetShortDescription() {
80
+        Check check = new Check(002L,"Nuri H", "0000888","1234567");
81
+
82
+         String expected = "Check Nuri H ***4567";
83
+         String actual = check.getShortDescription();
84
+         Assert.assertEquals(expected, actual);
85
+          }
86
+
87
+}

+ 238
- 0
src/test/java/com/zipcoder/payment/CompareToTest.java View File

@@ -0,0 +1,238 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class CompareToTest {
7
+    PayPal pal = new PayPal(001L,"Tia Mowry","tia@moury.com");
8
+    Check check = new Check(002L,"Tia Mowry","987-9999-9999","333444" );
9
+    CreditCard cc = new CreditCard(003L,"Tia Mowry","890-8700-9999",
10
+            12,1999);
11
+
12
+
13
+
14
+    @Test
15
+    public void testCompareTo2Paypal(){
16
+        //given
17
+        PayPal pal1 = new PayPal();
18
+        pal1.setPayerName("Evangelina H");
19
+        pal1.setEmail("evangelila@h.com");
20
+        int expected=-15;
21
+        //when
22
+        pal1.getShortDescription();
23
+        pal.getShortDescription();
24
+        //then
25
+        Assert.assertEquals(expected, pal1.compareTo(pal));
26
+
27
+
28
+    }
29
+    @Test
30
+    public void testCompareTo2PaypalReverse(){
31
+        //given
32
+        PayPal pal1 = new PayPal();
33
+        pal1.setPayerName("Evangelina H");
34
+        pal1.setEmail("evangelila@h.com");
35
+        int expected=15;
36
+        //when
37
+        pal1.getShortDescription();
38
+        pal.getShortDescription();
39
+        //then
40
+        Assert.assertEquals(expected, pal.compareTo(pal1));
41
+
42
+
43
+    }
44
+
45
+    @Test
46
+    public void testCompareToPayPal1() {
47
+        //given
48
+        int expected = 0;
49
+        //when
50
+        pal.getShortDescription();
51
+
52
+
53
+        Assert.assertEquals(expected, pal.compareTo(pal));
54
+
55
+
56
+    }
57
+
58
+    @Test
59
+    public void testCompareToPaypa2() {
60
+        //given
61
+        int expected = 13;
62
+        //when
63
+        pal.getShortDescription();
64
+        check.getShortDescription();
65
+
66
+        Assert.assertEquals(expected, pal.compareTo(check));
67
+
68
+
69
+    }
70
+
71
+    @Test
72
+    public void testCompareToPaypal3() {
73
+        //given
74
+
75
+        int expected = 13;
76
+        //when
77
+        pal.getShortDescription();
78
+        cc.getShortDescription();
79
+
80
+        Assert.assertEquals(expected, pal.compareTo(cc));
81
+
82
+
83
+    }
84
+    @Test
85
+    public void testCompareTo2Check() {
86
+        //given
87
+        Check check1 = new Check(001L,"Kevin Hart",
88
+                "123-4567-8909", "777888");
89
+        int expected = 9;
90
+        //when
91
+        check.getShortDescription();
92
+        check1.getShortDescription();
93
+
94
+        Assert.assertEquals(expected, check.compareTo(check1));
95
+
96
+
97
+    }
98
+    @Test
99
+    public void testCompareTo2CheckReverse() {
100
+        //given
101
+        Check check1 = new Check(002L,"Kevin Hart",
102
+                "123-4567-8909","998899");
103
+        int expected = -9;
104
+        //when
105
+        check.getShortDescription();
106
+        check1.getShortDescription();
107
+
108
+        Assert.assertEquals(expected, check1.compareTo(check));
109
+
110
+
111
+    }
112
+
113
+
114
+
115
+    @Test
116
+    public void testCompareToCheck1() {
117
+        //given
118
+
119
+        int expected = 0;
120
+        //when
121
+        check.getShortDescription();
122
+
123
+        Assert.assertEquals(expected, check.compareTo(check));
124
+
125
+
126
+    }
127
+
128
+
129
+    @Test
130
+    public void testCompareToCheck2() {
131
+        //given
132
+
133
+        int expected = -13;
134
+        //when
135
+        pal.getShortDescription();
136
+        check.getShortDescription();
137
+
138
+        Assert.assertEquals(expected, check.compareTo(pal));
139
+
140
+
141
+    }
142
+    @Test
143
+    public void testCompareToCheck3() {
144
+        //given
145
+
146
+        int expected = -10;
147
+        //when
148
+        check.getShortDescription();
149
+        cc.getShortDescription();
150
+
151
+        Assert.assertEquals(expected, check.compareTo(cc));
152
+
153
+
154
+    }
155
+
156
+    @Test
157
+    public void testCompareTo2Card() {
158
+        //given
159
+        CreditCard cc1= new CreditCard(002L,"Dina r",
160
+                "999-9890-8898",
161
+                04,
162
+                1999);
163
+
164
+        int expected = 16;
165
+        //when
166
+        cc.getShortDescription();
167
+        cc1.getShortDescription();
168
+
169
+
170
+        Assert.assertEquals(expected, cc.compareTo(cc1));
171
+
172
+
173
+    }
174
+
175
+    @Test
176
+    public void testCompareTo2CardReverse() {
177
+        //given
178
+        CreditCard cc1= new CreditCard(004L,"Dina r",
179
+                "999-9890-8898",
180
+                04,
181
+                1999);
182
+
183
+        int expected = -16;
184
+        //when
185
+        cc.getShortDescription();
186
+        cc1.getShortDescription();
187
+
188
+
189
+        Assert.assertEquals(expected, cc1.compareTo(cc));
190
+
191
+
192
+    }
193
+
194
+
195
+    @Test
196
+    public void testCompareToCard1() {
197
+        //given
198
+
199
+        int expected = 0;
200
+        //when
201
+        cc.getShortDescription();
202
+
203
+
204
+
205
+        Assert.assertEquals(expected, cc.compareTo(cc));
206
+
207
+
208
+    }
209
+
210
+
211
+    @Test
212
+    public void testCompareToCard2() {
213
+        //given
214
+
215
+        int expected = -13;
216
+        //when
217
+        cc.getShortDescription();
218
+        pal.getShortDescription();
219
+
220
+        Assert.assertEquals(expected, cc.compareTo(pal));
221
+
222
+
223
+    }
224
+    @Test
225
+    public void testCompareToCard3() {
226
+        //given
227
+        int expected = 10;
228
+        //when
229
+        cc.getShortDescription();
230
+        check.getShortDescription();
231
+
232
+        Assert.assertEquals(expected, cc.compareTo(check));
233
+
234
+
235
+    }
236
+
237
+
238
+}

+ 94
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java View File

@@ -0,0 +1,94 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class
7
+CreditCardTest {
8
+@Test
9
+    public void testGetAndSetId(){
10
+        //given
11
+        CreditCard creditCard = new CreditCard();
12
+        long id = 3;
13
+        creditCard.setId(id);
14
+        //when
15
+       long actualId= creditCard.getId();
16
+        //then
17
+
18
+Assert.assertEquals(id,actualId);
19
+    }
20
+    @Test
21
+    public void testGetPayerName(){
22
+        //given
23
+        CreditCard creditCard = new CreditCard();
24
+      String name = "Nury";
25
+        creditCard.setPayerName(name);
26
+        //when
27
+        String actual= creditCard.getPayerName();
28
+        //then
29
+
30
+        Assert.assertEquals(name,actual);
31
+
32
+
33
+    }
34
+
35
+    @Test
36
+    public void testGetNumber(){
37
+        //given
38
+        CreditCard creditCard = new CreditCard();
39
+        String number = "99999";
40
+        creditCard.setNumber(number);
41
+        //when
42
+        String actual= creditCard.getNumber();
43
+        //then
44
+
45
+        Assert.assertEquals(number,actual);
46
+
47
+
48
+    }
49
+    @Test
50
+    public void testGetExpriedMonth(){
51
+        //given
52
+        CreditCard creditCard = new CreditCard();
53
+       int expiredMonth = 999;
54
+        creditCard.setExpiredMonth(expiredMonth);
55
+        //when
56
+        int actual= creditCard.getExpiredMonth();
57
+        //then
58
+
59
+        Assert.assertEquals(expiredMonth,actual);
60
+
61
+
62
+    }
63
+    @Test
64
+    public void testGetExpiredYear(){
65
+        //given
66
+        CreditCard creditCard = new CreditCard();
67
+        int expiredYear = 9999;
68
+        creditCard.setExpiredYear(expiredYear);
69
+        //when
70
+        int actual= creditCard.getExpiredYear();
71
+        //then
72
+
73
+        Assert.assertEquals(expiredYear,actual);
74
+
75
+
76
+    }
77
+    @Test
78
+    public void testGetLast4Digit(){
79
+        CreditCard creditCard = new CreditCard();
80
+        String  id = "9999989";
81
+        String expectedId= "9989";
82
+        creditCard.setNumber(id);
83
+
84
+        //when
85
+         String actual=creditCard.getLast4Digit();
86
+        //System.out.print(creditCard.getLast4Digit());
87
+        //then
88
+        Assert.assertEquals(expectedId,actual);
89
+
90
+    }
91
+
92
+
93
+}
94
+

+ 53
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java View File

@@ -0,0 +1,53 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PayPalTest  {
7
+    PayPal pal = new PayPal();
8
+
9
+
10
+    @Test
11
+    public void testGetAndSetId(){
12
+        //given
13
+        long id = 3L;
14
+        pal.setId(id);
15
+        //when
16
+        long actualId= pal.getId();
17
+        //then
18
+
19
+        Assert.assertEquals(id,actualId);
20
+    }
21
+    @Test
22
+    public void testGetPayerName(){
23
+        //given
24
+
25
+        String name = "Nury";
26
+        pal.setPayerName(name);
27
+        //when
28
+        String actual= pal.getPayerName();
29
+        //then
30
+
31
+        Assert.assertEquals(name,actual);
32
+
33
+
34
+    }
35
+
36
+    @Test
37
+    public void testGetEmail(){
38
+        //given
39
+
40
+        String email = "nury@aol.com";
41
+        pal.setEmail(email);
42
+        //when
43
+        String actual= pal.getEmail();
44
+        //then
45
+
46
+        Assert.assertEquals(email,actual);
47
+    }
48
+
49
+
50
+
51
+}
52
+
53
+

+ 68
- 1
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java View File

@@ -1,4 +1,71 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
3 6
 public class PaymentPresenterTest {
4
-}
7
+
8
+    @Test
9
+    public void testToStringNoPayment() {
10
+
11
+        Payment[] payment = new Payment[0];
12
+        PaymentPresenter presenter = new PaymentPresenter();
13
+        String expected = "";
14
+
15
+        String actual = presenter.toString(payment);
16
+
17
+        Assert.assertEquals(expected, actual);
18
+    }
19
+
20
+
21
+    @Test
22
+    public void toStringMultiplePayments() {
23
+        Payment[] payments = new Payment[2];
24
+        Payment paypal = new PayPal(002L,"Tia Mowry", "tia@mowry.com");
25
+        Payment check = new Check(002L,"Tia Mowry", "11432543", "114324551");
26
+
27
+        payments[0] = paypal;
28
+        payments[1] = check;
29
+
30
+        PaymentPresenter presenter = new PaymentPresenter();
31
+        String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
32
+
33
+        String actual = presenter.toString(payments);
34
+        Assert.assertEquals(expected, actual);
35
+    }
36
+
37
+
38
+    @Test
39
+    public void toStringByPayerName() {
40
+        Payment[] payments = new Payment[2];
41
+        Payment paypal = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
42
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
43
+
44
+        payments[0] = paypal;
45
+        payments[1] = check;
46
+
47
+        PaymentPresenter presenter = new PaymentPresenter();
48
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
49
+
50
+        String actual = presenter.toStringByPayerName(payments);
51
+        Assert.assertEquals(expected, actual);
52
+
53
+    }
54
+
55
+    @Test
56
+   public void toStringbyId(){
57
+        Payment[] payments = new Payment[2];
58
+        Payment paypal = new PayPal(120L, "Tamara Mowry", "tamara@mowry.com");
59
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
60
+
61
+        payments[0] = paypal;
62
+        payments[1] = check;
63
+
64
+        PaymentPresenter presenter = new PaymentPresenter();
65
+        String expected = "Check Tia Mowry ***4551\nPaypal Tamara Mowry tamara@mowry.com\n";
66
+
67
+        String actual = presenter.toStringById(payments);
68
+        Assert.assertEquals(expected, actual);
69
+            }
70
+
71
+}

+ 33
- 0
src/test/java/com/zipcoder/payment/paymentSortByPayerTest.java View File

@@ -0,0 +1,33 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class paymentSortByPayerTest  {
7
+    PayPal pal = new PayPal(8L,"Dayhani Castro","tia@moury.com");
8
+    Check  check = new Check(001L,"Dayhani Castro","987-9999-9999","555333");
9
+    CreditCard cc = new CreditCard(005L,"Tia Mowry","987-9999-9999",
10
+            12,1999);
11
+    PaymentSortByPayer pSbP = new PaymentSortByPayer();
12
+
13
+    @Test
14
+public void testCompareSameName() {
15
+        Assert.assertTrue(pSbP.compare(check, pal) == 0);
16
+
17
+
18
+    }
19
+
20
+    @Test
21
+    public void testCompareLess() {
22
+        Assert.assertTrue(pSbP.compare(check, cc) < 0);
23
+
24
+
25
+    }
26
+    @Test
27
+    public void testCompareGreater() {
28
+        Assert.assertTrue(pSbP.compare(cc, pal) > 0);
29
+
30
+
31
+    }
32
+
33
+}