#25 All but one

Open
BDefrancis wil 1 commits van BDefrancis/InterfaceComparableLab:master samenvoegen met master

+ 8
- 0
pom.xml Bestand weergeven

@@ -11,5 +11,13 @@
11 11
         <maven.compiler.source>1.8</maven.compiler.source>
12 12
         <maven.compiler.target>1.8</maven.compiler.target>
13 13
     </properties>
14
+    <dependencies><!-- https://mvnrepository.com/artifact/junit/junit -->
15
+        <dependency>
16
+            <groupId>junit</groupId>
17
+            <artifactId>junit</artifactId>
18
+            <version>4.12</version>
19
+            <scope>test</scope>
20
+        </dependency>
21
+    </dependencies>
14 22
 
15 23
 </project>

+ 64
- 0
src/main/java/com/zipcoder/payment/Check.java Bestand weergeven

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

+ 60
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Bestand weergeven

@@ -0,0 +1,60 @@
1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment {
4
+
5
+    private long id;
6
+    private String playerName;
7
+    private String number;
8
+    private int expiredMonth;
9
+    private int expiredYear;
10
+
11
+    public void setId(long id) {
12
+        this.id = id;
13
+    }
14
+
15
+    public void setPlayerName(String playerName) {
16
+        this.playerName = playerName;
17
+    }
18
+
19
+    public String getNumber() {
20
+        return number;
21
+    }
22
+
23
+    public void setNumber(String number) {
24
+        this.number = number;
25
+    }
26
+
27
+    public int getExpiredMonth() {
28
+        return expiredMonth;
29
+    }
30
+
31
+    public void setExpiredMonth(int expiredMonth) {
32
+        this.expiredMonth = expiredMonth;
33
+    }
34
+
35
+    public int getExpiredYear() {
36
+        return expiredYear;
37
+    }
38
+
39
+    public void setExpiredYear(int expiredYear) {
40
+        this.expiredYear = expiredYear;
41
+    }
42
+
43
+    public long getId() {
44
+        return id;
45
+    }
46
+
47
+    public String getPlayerName() {
48
+        return playerName;
49
+    }
50
+
51
+    public String getShortDescription() {
52
+        return "CC " + playerName + " " + number.substring(number.length() - 4) + " " + expiredMonth + "/" + expiredYear;
53
+    }
54
+
55
+
56
+    @Override
57
+    public int compareTo(Payment o) {
58
+        return this.getShortDescription().compareTo(o.getShortDescription());
59
+    }
60
+}

+ 11
- 0
src/main/java/com/zipcoder/payment/Payment.java Bestand weergeven

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

+ 12
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java Bestand weergeven

@@ -3,4 +3,16 @@ package com.zipcoder.payment;
3 3
 public class PaymentPresenter {
4 4
 
5 5
 
6
+    public String toString(Payment[] payments) {
7
+        return payments.toString();
8
+    }
9
+
10
+    public String toStringByPayerName(Payment[] payments) {
11
+        return null;
12
+    }
13
+
14
+    public String toStringById(Payment[] payments) {
15
+        return null;
16
+    }
17
+
6 18
 }

+ 11
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPlayer.java Bestand weergeven

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

+ 54
- 0
src/main/java/com/zipcoder/payment/Paypal.java Bestand weergeven

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

+ 54
- 0
src/test/java/com/zipcoder/payment/CheckTest.java Bestand weergeven

@@ -0,0 +1,54 @@
1
+package com.zipcoder.payment;
2
+
3
+
4
+import org.junit.Assert;
5
+import org.junit.Test;
6
+import org.junit.runner.RunWith;
7
+
8
+import static org.junit.Assert.*;
9
+
10
+public class CheckTest {
11
+    Check check = new Check();
12
+
13
+    @Test
14
+    public void setId() {
15
+        check.setId(465);
16
+        int expected = 465;
17
+
18
+        Assert.assertEquals(expected, check.getId());
19
+    }
20
+
21
+    @Test
22
+    public void setPlayerName() {
23
+        check.setPlayerName("Brandon");
24
+        String expected = "Brandon";
25
+
26
+        Assert.assertEquals(expected, check.getPlayerName());
27
+    }
28
+
29
+    @Test
30
+    public void setRoutingNumber() {
31
+        check.setRoutingNumber("123456789");
32
+        String expected = "123456789";
33
+
34
+        Assert.assertEquals(expected, check.getRoutingNumber());
35
+    }
36
+
37
+    @Test
38
+    public void setAccountNumber() {
39
+        check.setAccountNumber("0000222333444");
40
+        String expected = "0000222333444";
41
+
42
+        Assert.assertEquals(expected, check.getAccountNumber());
43
+    }
44
+
45
+    @Test
46
+    public void getShortDescription() {
47
+        check.setPlayerName("Joe Shmoe");
48
+        check.setAccountNumber("2482049200");
49
+
50
+        String expected = "Check Joe Shmoe ***9200";
51
+
52
+        Assert.assertEquals(expected, check.getShortDescription());
53
+    }
54
+}

+ 66
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java Bestand weergeven

@@ -0,0 +1,66 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import static org.junit.Assert.*;
6
+
7
+public class CreditCardTest {
8
+    CreditCard creditCard = new CreditCard();
9
+
10
+    @Test
11
+    public void setId1() {
12
+        creditCard.setId(50);
13
+        long expected = 50;
14
+
15
+        Assert.assertEquals(expected, creditCard.getId());
16
+    }
17
+
18
+    @Test
19
+    public void setPlayerName1() {
20
+        creditCard.setPlayerName("Brandon");
21
+        String expected = "Brandon";
22
+
23
+        Assert.assertEquals(expected, creditCard.getPlayerName());
24
+    }
25
+
26
+    @Test
27
+    public void setNumber1() {
28
+        creditCard.setNumber("1234");
29
+        String expected = "1234";
30
+
31
+        Assert.assertEquals(expected, creditCard.getNumber());
32
+    }
33
+
34
+    @Test
35
+    public void setExpiredMonth1() {
36
+        creditCard.setExpiredMonth(5);
37
+        int expected = 5;
38
+
39
+        Assert.assertEquals(expected, creditCard.getExpiredMonth());
40
+    }
41
+
42
+    @Test
43
+    public void setExpiredYear1() {
44
+        creditCard.setExpiredYear(2010);
45
+        int expected = 2010;
46
+
47
+        Assert.assertEquals(expected, creditCard.getExpiredYear());
48
+    }
49
+
50
+    @Test
51
+    public void getShortDescription1() {
52
+        creditCard.setId(40);
53
+        creditCard.setPlayerName("Brandon");
54
+        creditCard.setNumber("1234 5678 9101 1213");
55
+        creditCard.setExpiredMonth(6);
56
+        creditCard.setExpiredYear(2013);
57
+
58
+        String expected = "CC Brandon 1213 6/2013";
59
+
60
+        Assert.assertEquals(expected, creditCard.getShortDescription());
61
+    }
62
+
63
+    @Test
64
+    public void compareTo() {
65
+    }
66
+}

+ 62
- 0
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Bestand weergeven

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

+ 46
- 0
src/test/java/com/zipcoder/payment/PaypalTest.java Bestand weergeven

@@ -0,0 +1,46 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import org.junit.runner.RunWith;
6
+
7
+import static org.junit.Assert.*;
8
+
9
+public class PaypalTest {
10
+    Paypal paypal = new Paypal();
11
+
12
+    @Test
13
+    public void setId() {
14
+        paypal.setId(50);
15
+        long expected = 50;
16
+
17
+        Assert.assertEquals(expected, paypal.getId());
18
+    }
19
+
20
+    @Test
21
+    public void setPlayerName() {
22
+        paypal.setPlayerName("Brandon");
23
+        String expected = "Brandon";
24
+
25
+        Assert.assertEquals(expected, paypal.getPlayerName());
26
+    }
27
+
28
+    @Test
29
+    public void setEmail() {
30
+        paypal.setEmail("good@gmail.com");
31
+        String expected = "good@gmail.com";
32
+
33
+        Assert.assertEquals(expected, paypal.getEmail());
34
+    }
35
+
36
+    @Test
37
+    public void getShortDescription() {
38
+        paypal.setPlayerName("Brandon");
39
+        paypal.setEmail("good@gmail.com");
40
+
41
+        String expected = "Paypal Brandon good@gmail.com";
42
+
43
+        Assert.assertEquals(expected, paypal.getShortDescription());
44
+
45
+    }
46
+}