Chad 8 年 前
コミット
f72d035ca6

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

@@ -3,7 +3,18 @@
3 3
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 4
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 5
     <modelVersion>4.0.0</modelVersion>
6
-
6
+    <build>
7
+        <plugins>
8
+            <plugin>
9
+                <groupId>org.apache.maven.plugins</groupId>
10
+                <artifactId>maven-compiler-plugin</artifactId>
11
+                <configuration>
12
+                    <source>1.8</source>
13
+                    <target>1.8</target>
14
+                </configuration>
15
+            </plugin>
16
+        </plugins>
17
+    </build>
7 18
     <groupId>com.zipcoder</groupId>
8 19
     <artifactId>payment</artifactId>
9 20
     <version>1.0-SNAPSHOT</version>

+ 2
- 1
src/main/java/com/zipcoder/payment/PaymentPresenter.java ファイルの表示

@@ -1,6 +1,7 @@
1 1
 package com.zipcoder.payment;
2 2
 
3 3
 import java.util.Arrays;
4
+import java.util.Comparator;
4 5
 
5 6
 public class PaymentPresenter {
6 7
     Payment[] payments;
@@ -32,7 +33,7 @@ public class PaymentPresenter {
32 33
 
33 34
     public String toStringById(Payment[] payments){
34 35
         StringBuilder output = new StringBuilder();
35
-        Arrays.sort(payments,new PaymentSortById());
36
+        Arrays.sort(payments,(p, q) -> p.getId().compareTo(q.getId()));
36 37
 
37 38
         for (int i=0; i<payments.length; i++) {
38 39
             output.append(payments[i].getShortDescription()+"\n");

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

@@ -10,4 +10,5 @@ public class PaymentSortByPayer implements Comparator<Payment> {
10 10
     public int compare(Payment o1, Payment o2) {
11 11
         return o1.getPayerName().compareTo(o2.getPayerName());
12 12
     }
13
+
13 14
 }

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

@@ -50,7 +50,7 @@ public class CheckTest {
50 50
     public void compareToTest(){
51 51
 
52 52
         int expected= 1;
53
-        int actual= test.getShortDescription().compareTo(test1.getShortDescription());
53
+        int actual= test.compareTo(test1);
54 54
         Assert.assertTrue(actual<expected);
55 55
     }
56 56
 }

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

@@ -1,7 +1,6 @@
1 1
 package com.zipcoder.payment;
2 2
 
3 3
 import org.junit.Assert;
4
-import org.junit.Before;
5 4
 import org.junit.Test;
6 5
 
7 6
 public class CreditCardTest {
@@ -10,7 +9,7 @@ public class CreditCardTest {
10 9
 
11 10
     @Test
12 11
     public void getIdTest(){
13
-
12
+        test.setId(1L);
14 13
         Long expected= 1L;
15 14
         Long actual= test.getId();
16 15
         Assert.assertEquals(expected,actual);
@@ -59,8 +58,7 @@ public class CreditCardTest {
59 58
     @Test
60 59
     public void compareToTest(){
61 60
 
62
-        int expected= 1;
63
-        int actual= test.getShortDescription().compareTo(test1.getShortDescription());
64
-        Assert.assertEquals(expected,actual);
61
+        int actual= test.compareTo(test1);
62
+        Assert.assertTrue(actual>0);
65 63
     }
66 64
 }

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

@@ -3,6 +3,8 @@ package com.zipcoder.payment;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6
+import java.util.Comparator;
7
+
6 8
 public class PaymentPresenterTest {
7 9
 
8 10
     @Test
@@ -55,6 +57,7 @@ public class PaymentPresenterTest {
55 57
     Payment paypal = new Paypal(81L, "Tamara Mowry", "tamara@mowry.com");
56 58
     Payment check = new Check(120L, "Tia Mowry", "11432543", "134344551");
57 59
 
60
+
58 61
     payments[0]=paypal;
59 62
     payments[1]=check;
60 63
 

+ 17
- 5
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java ファイルの表示

@@ -1,18 +1,30 @@
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 PaymentSortByPayerTest {
7 8
 
8
-    CreditCard test2 = new CreditCard(1L,"chad","123456789",1,2020);
9
-    Check test1 = new Check(2L,"brad","98 76 5432","0987654321");
10
-    PaymentSortByPayer test = new PaymentSortByPayer();
9
+    CreditCard test2;
10
+    Check test1;
11
+    PaymentSortByPayer test;
12
+
13
+    @Before
14
+    public void setUp(){
15
+        test2 = new CreditCard(1L,"chad","123456789",1,2020);
16
+        test1 = new Check(2L,"brad","98 76 5432","0987654321");
17
+        test = new PaymentSortByPayer();
18
+    }
19
+
20
+
11 21
     @Test
12 22
     public void compareTest(){
23
+        //Given
13 24
 
14
-        int expected= 1;
25
+        //When
15 26
         int actual= test.compare(test1,test2);
16
-        Assert.assertTrue(actual<expected);
27
+        //Assert
28
+        Assert.assertTrue(actual<0);
17 29
     }
18 30
 }

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

@@ -1,11 +1,28 @@
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
 
7
+
6 8
 public class PaypalTest {
7
-    Paypal test = new Paypal(1L,"Chad Hallinan","hallinanc@susqu.edu");
8
-    Paypal test1 = new Paypal(2L,"brad","bradbrobrill");
9
+    Paypal test;
10
+    Paypal test1;
11
+
12
+    @Before
13
+    public void before(){
14
+        test = new Paypal(1L,"Chad Hallinan","hallinanc@susqu.edu");
15
+        test1 = new Paypal(2L,"brad","bradbrobrill");
16
+    }
17
+
18
+    @Test
19
+    public void liveTest(){
20
+        test.setPayerName("Nafis");
21
+        String actual= test.getPayerName();
22
+        String expected = "Nafis";
23
+        Assert.assertEquals(actual, expected);
24
+    }
25
+
9 26
     @Test
10 27
     public void getIdTest(){
11 28
 
@@ -41,8 +58,7 @@ public class PaypalTest {
41 58
     @Test
42 59
     public void compareToTest(){
43 60
 
44
-        int expected= 1;
45
-        int actual= test.getShortDescription().compareTo(test1.getShortDescription());
46
-        Assert.assertTrue(actual<expected);
61
+        int actual= test.compareTo(test1);
62
+        Assert.assertTrue(actual<0);
47 63
     }
48 64
 }