Chad vor 8 Jahren
Ursprung
Commit
f72d035ca6

+ 12
- 1
pom.xml Datei anzeigen

3
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
     <modelVersion>4.0.0</modelVersion>
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
     <groupId>com.zipcoder</groupId>
18
     <groupId>com.zipcoder</groupId>
8
     <artifactId>payment</artifactId>
19
     <artifactId>payment</artifactId>
9
     <version>1.0-SNAPSHOT</version>
20
     <version>1.0-SNAPSHOT</version>

+ 2
- 1
src/main/java/com/zipcoder/payment/PaymentPresenter.java Datei anzeigen

1
 package com.zipcoder.payment;
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
 public class PaymentPresenter {
6
 public class PaymentPresenter {
6
     Payment[] payments;
7
     Payment[] payments;
32
 
33
 
33
     public String toStringById(Payment[] payments){
34
     public String toStringById(Payment[] payments){
34
         StringBuilder output = new StringBuilder();
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
         for (int i=0; i<payments.length; i++) {
38
         for (int i=0; i<payments.length; i++) {
38
             output.append(payments[i].getShortDescription()+"\n");
39
             output.append(payments[i].getShortDescription()+"\n");

+ 1
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Datei anzeigen

10
     public int compare(Payment o1, Payment o2) {
10
     public int compare(Payment o1, Payment o2) {
11
         return o1.getPayerName().compareTo(o2.getPayerName());
11
         return o1.getPayerName().compareTo(o2.getPayerName());
12
     }
12
     }
13
+
13
 }
14
 }

+ 1
- 1
src/test/java/com/zipcoder/payment/CheckTest.java Datei anzeigen

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

+ 3
- 5
src/test/java/com/zipcoder/payment/CreditCardTest.java Datei anzeigen

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
-import org.junit.Before;
5
 import org.junit.Test;
4
 import org.junit.Test;
6
 
5
 
7
 public class CreditCardTest {
6
 public class CreditCardTest {
10
 
9
 
11
     @Test
10
     @Test
12
     public void getIdTest(){
11
     public void getIdTest(){
13
-
12
+        test.setId(1L);
14
         Long expected= 1L;
13
         Long expected= 1L;
15
         Long actual= test.getId();
14
         Long actual= test.getId();
16
         Assert.assertEquals(expected,actual);
15
         Assert.assertEquals(expected,actual);
59
     @Test
58
     @Test
60
     public void compareToTest(){
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 Datei anzeigen

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

+ 17
- 5
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java Datei anzeigen

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
+import org.junit.Before;
4
 import org.junit.Test;
5
 import org.junit.Test;
5
 
6
 
6
 public class PaymentSortByPayerTest {
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
     @Test
21
     @Test
12
     public void compareTest(){
22
     public void compareTest(){
23
+        //Given
13
 
24
 
14
-        int expected= 1;
25
+        //When
15
         int actual= test.compare(test1,test2);
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 Datei anzeigen

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
+import org.junit.Before;
4
 import org.junit.Test;
5
 import org.junit.Test;
5
 
6
 
7
+
6
 public class PaypalTest {
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
     @Test
26
     @Test
10
     public void getIdTest(){
27
     public void getIdTest(){
11
 
28
 
41
     @Test
58
     @Test
42
     public void compareToTest(){
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
 }