Aleena Rose-Mathew 8 лет назад
Родитель
Сommit
6e13f92010

+ 8
- 0
pom.xml Просмотреть файл

7
     <groupId>com.zipcoder</groupId>
7
     <groupId>com.zipcoder</groupId>
8
     <artifactId>payment</artifactId>
8
     <artifactId>payment</artifactId>
9
     <version>1.0-SNAPSHOT</version>
9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>org.junit.jupiter</groupId>
13
+            <artifactId>junit-jupiter-api</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+    </dependencies>
10
 
18
 
11
 
19
 
12
 </project>
20
 </project>

+ 60
- 0
src/main/java/com/zipcoder/payment/Check.java Просмотреть файл

1
+package com.zipcoder.payment;
2
+
3
+public class Check implements Payment {
4
+    public Check(Long id,String PayerName,String routingNumber,String accountNumber)
5
+    {
6
+        this.id=id;
7
+        this.payerName=PayerName;
8
+        this.routingNumber=routingNumber;
9
+        this.accountNumber=accountNumber;
10
+
11
+    }
12
+    long id;
13
+    String payerName;
14
+    String routingNumber;
15
+    String accountNumber;
16
+    public long getId()
17
+    {
18
+        return this.id;
19
+    }
20
+    public void setId(Long id)
21
+    {
22
+        this.id=id;
23
+    }
24
+    public String getPayerName()
25
+    {
26
+        return this.payerName;
27
+    }
28
+    public void setPayerName(String name)
29
+    {
30
+        this.payerName=name;
31
+    }
32
+    public String getroutingNumber()
33
+    {
34
+        return this.routingNumber;
35
+    }
36
+    public void setroutingNumber(String routingNumber)
37
+    {
38
+        this.routingNumber=routingNumber;
39
+    }
40
+    public String getaccountNumber()
41
+    {
42
+        return this.accountNumber;
43
+    }
44
+    public void setaccountNumber(String accountNumber)
45
+    {
46
+        this.accountNumber=accountNumber;
47
+    }
48
+    public String getShortDescription()
49
+    {
50
+        String number=getaccountNumber();
51
+        StringBuilder br =new StringBuilder();
52
+        br.append("Check").append(" ").append(this.getPayerName()).append(" ").
53
+                append(" ").append("****").append(number.substring(number.length()-4));
54
+        System.out.println(br.toString());
55
+        return br.toString();
56
+    }
57
+    public int compareTo(Payment o) {
58
+       return this.getShortDescription().compareTo(o.getShortDescription());
59
+    }
60
+}

+ 72
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Просмотреть файл

1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment{
4
+    private long id;
5
+    private String payer;
6
+    private String number;
7
+    private int expiredMonth;
8
+    private int expiredYear;
9
+    public CreditCard(long id,String payer,String number,int expiredMonth,int expiredYear)
10
+    {
11
+        this.id=id;
12
+        this.payer=payer;
13
+        this.number=number;
14
+        this.expiredMonth=expiredMonth;
15
+        this.expiredYear=expiredYear;
16
+    }
17
+    public String getPayerName()
18
+    {
19
+        return this.payer;
20
+    }
21
+    public void setPayerName(String name)
22
+    {
23
+        this.payer=name;
24
+    }
25
+    public String getShortDescription()
26
+    {
27
+        String number=getNumber();
28
+        StringBuilder br =new StringBuilder();
29
+        br.append("CC").append(" ").append(this.getPayerName()).append(" ")
30
+                .append(number.substring(number.length()-4)).append(" ").append(getexpiredMonth())
31
+                .append("/").append(getexpiredYear());
32
+
33
+        System.out.println(br.toString());
34
+        return br.toString();
35
+    }
36
+    public long getId()
37
+    {
38
+        return this.id;
39
+    }
40
+    public void setId(Long id)
41
+    {
42
+        this.id=id;
43
+    }
44
+    public void setNumber(String number)
45
+    {
46
+        this.number=number;
47
+    }
48
+    public String getNumber()
49
+    {
50
+        return this.number;
51
+    }
52
+    public void setexpiredMonth(int expiredMonth)
53
+    {
54
+        this.expiredMonth=expiredMonth;
55
+    }
56
+    public int getexpiredMonth()
57
+    {
58
+        return this.expiredMonth;
59
+    }
60
+    public void setexpiredYear(int expiredYear)
61
+    {
62
+        this.expiredYear=expiredYear;
63
+    }
64
+    public int getexpiredYear()
65
+    {
66
+        return this.expiredYear;
67
+    }
68
+
69
+    public int compareTo(Payment o) {
70
+        return this.getShortDescription().compareTo(o.getShortDescription());
71
+    }
72
+}

+ 14
- 0
src/main/java/com/zipcoder/payment/Payment.java Просмотреть файл

1
+package com.zipcoder.payment;
2
+
3
+import java.util.Locale;
4
+
5
+public interface Payment extends Comparable<Payment>
6
+    //Comparable<Payment>  is a generic abstract class
7
+{
8
+
9
+    public long getId();
10
+    public String getPayerName();
11
+    public String getShortDescription();
12
+
13
+
14
+}

+ 12
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Просмотреть файл

1
+package com.zipcoder.payment;
2
+
3
+public class PaymentSortByPayer implements Comparable<Payment> {
4
+    public int compareTo(Payment o) {
5
+        return 0;
6
+    }
7
+    public int compare(Payment o1,Payment o2)
8
+
9
+    {
10
+     return o1.getPayerName().compareTo(o2.getPayerName());
11
+    }
12
+}

+ 51
- 0
src/main/java/com/zipcoder/payment/Paypal.java Просмотреть файл

1
+package com.zipcoder.payment;
2
+
3
+public class Paypal implements Payment {
4
+    private long id;
5
+    private String payerName;
6
+    private String email;
7
+    public Paypal(int id,String payerName,String email)
8
+    {
9
+        this.id=id;
10
+        this.payerName=payerName;
11
+        this.email=email;
12
+    }
13
+
14
+    public long getId()
15
+    {
16
+        return this.id;
17
+    }
18
+    public void setId(Long id)
19
+    {
20
+        this.id=id;
21
+    }
22
+    public String getPayerName()
23
+    {
24
+        return this.payerName;
25
+    }
26
+    public void setPayerName(String name)
27
+    {
28
+        this.payerName=name;
29
+    }
30
+    public String getemail()
31
+    {
32
+        return this.email;
33
+    }
34
+    public void setemail(String email)
35
+    {
36
+        this.email=email;
37
+    }
38
+    public String getShortDescription()
39
+    {
40
+       // String number=getNumber();
41
+        StringBuilder br =new StringBuilder();
42
+        br.append("Paypal").append(" ").append(getPayerName()).append(" ")
43
+                .append(getemail());
44
+        System.out.println(br.toString());
45
+        return br.toString();
46
+    }
47
+
48
+    public int compareTo(Payment o) {
49
+        return this.getShortDescription().compareTo(o.getShortDescription());
50
+    }
51
+}

+ 50
- 0
src/test/java/com/zipcoder/payment/CheckTest.java Просмотреть файл

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.assertEquals;
6
+
7
+public class CheckTest
8
+{
9
+    Check check=new Check((long) 1,"Aleena","123456","76543");
10
+    Check check1=new Check((long) 2,"Boby","987653","98678");
11
+    @Test
12
+    public void testcheckGetID(){
13
+
14
+        long expected = 1;
15
+        long actual = check.getId();
16
+        assertEquals(expected,actual);
17
+    }
18
+    @Test
19
+    public void testCheckPayer()
20
+    {
21
+        String expected="aleen";
22
+        check.setPayerName("aleen");
23
+        String actual=check.getPayerName();
24
+        assertEquals(expected, actual);
25
+    }
26
+    @Test
27
+    public void testCheckRoutingNumber()
28
+    {
29
+        String expected="123456789";
30
+        check.setroutingNumber("123456789");
31
+        String actual=check.getroutingNumber();
32
+        assertEquals(expected, actual);
33
+    }
34
+    @Test
35
+    public void testCheckAccountNumber()
36
+    {
37
+        String expected="123456780";
38
+        check.setaccountNumber("123456780");
39
+        String actual=check.getaccountNumber();
40
+        assertEquals(expected, actual);
41
+    }
42
+    @Test
43
+    public void compareToTest()
44
+    {
45
+        int expected=-1;
46
+        int actual=check.getShortDescription().compareTo(check1.getShortDescription());
47
+        assertEquals(expected,actual);
48
+    }
49
+
50
+}

+ 73
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java Просмотреть файл

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.assertEquals;
6
+
7
+public class CreditCardTest {
8
+
9
+    CreditCard credit=new CreditCard(1,"bleena","12345",10,2020);
10
+    CreditCard credit1=new CreditCard(2,"anju","00101",2,2019);
11
+    Check check=new Check((long) 1,"Aleena","123456","76543");
12
+    @Test
13
+    public void creditCardTestGetID(){
14
+        long expected = 1;
15
+        long actual = credit.getId();
16
+        assertEquals(expected,actual);
17
+    }
18
+    @Test
19
+    public void creditCardTestGetNumber(){
20
+
21
+        String expected = "12345";
22
+        String actual = credit.getNumber();
23
+        assertEquals(expected,actual);
24
+    }
25
+    @Test
26
+    public void creditPayerNameTest(){
27
+
28
+        String expected = "bleena";
29
+        String actual = credit.getPayerName();
30
+        assertEquals(expected,actual);
31
+    }
32
+    @Test
33
+    public void creditexpiredMonthTest(){
34
+
35
+        int expected = 10;
36
+        int actual = credit.getexpiredMonth();
37
+        assertEquals(expected,actual);
38
+    }
39
+    @Test
40
+    public void creditexpiredYearTest(){
41
+
42
+        int expected = 2020;
43
+        int actual = credit.getexpiredYear();
44
+        assertEquals(expected,actual);
45
+    }
46
+    @Test
47
+    public void compareToTest()//comparaing two different credit cards
48
+    {
49
+        int expected=1;
50
+        int actual=credit.getShortDescription().compareTo(credit1.getShortDescription());
51
+        assertEquals(expected,actual);
52
+    }
53
+    @Test
54
+    public void compareToTestCredit()//comparing same credit card->returns zero
55
+    {
56
+        int expected=0;
57
+        int actual=credit.getShortDescription().compareTo(credit.getShortDescription());
58
+        assertEquals(expected,actual);
59
+    }
60
+    @Test
61
+    public void compareToTestCheck()//comparing credit card with check->
62
+    //CC bleena 2345 10/2020
63
+    //Check Aleena  ****6543
64
+
65
+    {
66
+        int expected=-37;
67
+        int actual=credit.getShortDescription().compareTo(check.getShortDescription());
68
+        assertEquals(expected,actual);
69
+
70
+    }
71
+
72
+
73
+}

+ 61
- 0
src/test/java/com/zipcoder/payment/PaypalTest.java Просмотреть файл

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.BeforeAll;
4
+import org.junit.jupiter.api.Test;
5
+
6
+import static org.junit.jupiter.api.Assertions.assertEquals;
7
+
8
+public class PaypalTest {
9
+    Paypal paypal=new Paypal(1,"boby","boby@gmail.com");
10
+    Paypal paypal1=new Paypal(2,"aleena","aleenarm@gmail.com");
11
+    Check check=new Check((long) 1,"Aleena","123456","76543");
12
+    CreditCard credit=new CreditCard(1,"bleena","12345",10,2020);
13
+    @Test
14
+    public void testPaypalGetID(){
15
+
16
+        long expected = 1;
17
+        long actual = paypal.getId();
18
+        assertEquals(expected,actual);
19
+    }
20
+    @Test
21
+    public void testPaypalPayer()
22
+    {
23
+        String expected="boby";
24
+        String actual=paypal.getPayerName();
25
+        assertEquals(expected, actual);
26
+    }
27
+    @Test
28
+    public void testPaypalEmail()
29
+    {
30
+        String expected="boby@gmail.com";
31
+        String actual=paypal.getemail();
32
+        assertEquals(expected, actual);
33
+    }
34
+    @Test
35
+    public void compareToTest()//compare two paypal
36
+    //Paypal boby boby@gmail.com
37
+    //Paypal aleena aleenarm@gmail.com
38
+    {
39
+        int expected=1;
40
+        int actual=paypal.getShortDescription().compareTo(paypal1.getShortDescription());
41
+        assertEquals(expected,actual);
42
+    }
43
+    @Test
44
+    public void compareToCheck()//compare two paypal
45
+    //Paypal boby boby@gmail.com
46
+    //Check Aleena  ****6543
47
+    {
48
+        int expected=13;//(P-C)->(16-3)->13
49
+        int actual=paypal.getShortDescription().compareTo(check.getShortDescription());
50
+        assertEquals(expected,actual);
51
+    }
52
+    @Test
53
+    public void compareToCredit()//compare two credit
54
+    //Paypal boby boby@gmail.com
55
+    //CC bleena 2345 10/2020
56
+    {
57
+        int expected=13;//(P-C)->(16-3)->13
58
+        int actual=paypal.getShortDescription().compareTo(credit.getShortDescription());
59
+        assertEquals(expected,actual);
60
+    }
61
+}