Browse Source

Merge commit '92b1faa9c3ea4778e1c29f062e6019bcf75ef2b9' into HEAD

dev
JenkinsSonaImron 3 years ago
parent
commit
96f1326326
  1. 36
      src/main/java/hs/fulda/de/ci/exam/project/BankTransaction.java
  2. 12
      src/main/java/hs/fulda/de/ci/exam/project/CashTransaction.java
  3. 20
      src/main/java/hs/fulda/de/ci/exam/project/CreditCardTransaction.java
  4. 15
      src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java
  5. 4
      src/main/java/hs/fulda/de/ci/exam/project/Payment.java
  6. 41
      src/test/java/hs/fulda/de/ci/exam/project/PaymentTest.java

36
src/main/java/hs/fulda/de/ci/exam/project/BankTransaction.java

@ -0,0 +1,36 @@
package hs.fulda.de.ci.exam.project;
public class BankTransaction extends Payment {
String bankName;
String iban;
public BankTransaction(int id, String amount, PaymentStatus status, String bankName, String iban) {
super(id, amount, status);
this.bankName = bankName;
this.iban = iban;
}
public String getBankName() {
return bankName;
}
public void setBankName(String bankName) {
this.bankName = bankName;
}
public String getIban() {
return iban;
}
public void setIban(String iban) {
this.iban = iban;
}
@Override
public boolean isValid() {
if (this.iban.length() != 22) {
return false;
}
return true;
}
}

12
src/main/java/hs/fulda/de/ci/exam/project/CashTransaction.java

@ -0,0 +1,12 @@
package hs.fulda.de.ci.exam.project;
public class CashTransaction extends Payment {
public CashTransaction(int id, String amount, PaymentStatus status) {
super(id, amount, status);
}
@Override
public boolean isValid() {
return true;
}
}

20
src/main/java/hs/fulda/de/ci/exam/project/CreditCardTransaction.java

@ -1,10 +1,24 @@
package hs.fulda.de.ci.exam.project;
public class CreditCardTransaction extends Payment {
String nameOnCard;
String cardNumber;
public CreditCardTransaction(int id, String amount, PaymentStatus status, String nameOnCard) {
public CreditCardTransaction(int id, String amount, PaymentStatus status, String cardNumber) {
super(id, amount, status);
this.nameOnCard = nameOnCard;
this.cardNumber = cardNumber;
}
public String getCardNumber() {
return cardNumber;
}
public void setCardNumber(String cardNumber) {
this.cardNumber = cardNumber;
}
@Override
public boolean isValid() {
if (this.cardNumber.length() != 20) return false;
return true;
}
}

15
src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java

@ -3,6 +3,8 @@ package hs.fulda.de.ci.exam.project;
import java.util.HashMap;
import static hs.fulda.de.ci.exam.project.PaymentStatus.Completed;
import static hs.fulda.de.ci.exam.project.PaymentStatus.Failed;
import static hs.fulda.de.ci.exam.project.ReservationStatus.Cancelled;
import static hs.fulda.de.ci.exam.project.ReservationStatus.Confirmed;
public class FlightReservation {
@ -55,10 +57,17 @@ public class FlightReservation {
this.status = status;
}
public void makePayment(Payment credit_card_payment) {
public void makePayment(Payment payment) {
System.out.println("processing payment");
credit_card_payment.status = Completed;
status = Confirmed;
if (payment.isValid()) {
payment.status = Completed;
setStatus(Confirmed);
} else {
payment.status = Failed;
setStatus(Cancelled);
}
}
public boolean notifyUser(String type, String to, String content) {

4
src/main/java/hs/fulda/de/ci/exam/project/Payment.java

@ -1,6 +1,6 @@
package hs.fulda.de.ci.exam.project;
public class Payment {
public abstract class Payment {
int id;
String amount;
PaymentStatus status;
@ -34,4 +34,6 @@ public class Payment {
public void setStatus(PaymentStatus status) {
this.status = status;
}
public abstract boolean isValid();
}

41
src/test/java/hs/fulda/de/ci/exam/project/PaymentTest.java

@ -9,10 +9,49 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class PaymentTest {
@Test
public void should_be_possible_to_pay_with_credit_card(){
Payment credit_card_payment = new CreditCardTransaction(11, "139€", Unpaid, "Imron Gamidli");
Payment credit_card_payment = new CreditCardTransaction(11, "139€", Unpaid, "01234567890123456789");
FlightReservation reservation = new FlightReservation();
reservation.makePayment(credit_card_payment);
assertEquals(Confirmed, reservation.getStatus());
assertEquals(Completed, credit_card_payment.status);
}
@Test
public void should_be_possible_to_pay_with_bank_account(){
FlightReservation reservation = new FlightReservation();
BankTransaction payment = new BankTransaction(11, "139€", Unpaid, "Sparkasse Fulda", "DE01234567890123456789");
reservation.makePayment(payment);
assertEquals(Confirmed, reservation.getStatus());
assertEquals(Completed, payment.status);
}
@Test
public void paymentShould_not_be_possible_if_credit_card_deatils_is_wrong(){
CreditCardTransaction credit_card_payment = new CreditCardTransaction(11, "139€", Unpaid, "123");
FlightReservation reservation = new FlightReservation();
reservation.makePayment(credit_card_payment);
assertEquals(ReservationStatus.Cancelled, reservation.getStatus());
assertEquals(Failed, credit_card_payment.status);
}
@Test
public void paymentShould_not_be_possible_if_iban_is_wrong(){
BankTransaction bank_payment = new BankTransaction(11, "139€", Unpaid, "Sparkasse Fulda", "DE012");
FlightReservation reservation = new FlightReservation();
reservation.makePayment(bank_payment);
assertEquals(ReservationStatus.Cancelled, reservation.getStatus());
assertEquals(Failed, bank_payment.status);
}
@Test
public void cashPaymentShouldBePossible(){
CashTransaction cash_payment = new CashTransaction(11, "139€", Unpaid);
FlightReservation reservation = new FlightReservation();
reservation.makePayment(cash_payment);
assertEquals(Confirmed, reservation.getStatus());
assertEquals(Completed, cash_payment.status);
}
}
Loading…
Cancel
Save