Skip to content

Commit

Permalink
fix: Debt-position-status-checker (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
LarissaASLeite authored Jan 21, 2025
1 parent f4aca12 commit 307f036
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public boolean isToSync(List<E> childrenStatusList) {
return childrenStatusList.contains(syncStatus);
}

public boolean isPartiallyPaid(List<E> childrenStatusList) {
return childrenStatusList.contains(paidStatus) &&
(childrenStatusList.contains(unpaidStatus) || childrenStatusList.contains(expiredStatus));
}
protected abstract boolean isPartiallyPaid(List<E> childrenStatusList);

public boolean isUnpaid(List<E> childrenStatusList) {
return allMatch(childrenStatusList, unpaidStatus, allowedCancelledStatuses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public DebtPositionStatus calculateNewStatus(List<PaymentOptionStatus> paymentOp
}
}

@Override
public boolean isPartiallyPaid(List<PaymentOptionStatus> childrenStatusList) {
return childrenStatusList.contains(PARTIALLY_PAID);
}


@Override
protected List<PaymentOptionStatus> getChildStatuses(DebtPosition debtPosition) {
return debtPosition.getPaymentOptions().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ protected void setStatus(PaymentOption paymentOption, PaymentOptionStatus newSta
protected void storeStatus(PaymentOption paymentOption, PaymentOptionStatus newStatus) {
paymentOptionRepository.updateStatus(paymentOption.getPaymentOptionId(), newStatus);
}

@Override
protected boolean isPartiallyPaid(List<InstallmentStatus> childrenStatusList) {
return childrenStatusList.contains(InstallmentStatus.PAID) &&
(childrenStatusList.contains(InstallmentStatus.UNPAID) || childrenStatusList.contains(InstallmentStatus.EXPIRED));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,11 @@ void testCalculateNewStatus_ToSync() {
}

/**
* Test if the status is PARTIALLY_PAID when there is at least one PAID and one UNPAID paymentOption.
* Test if the status is PARTIALLY_PAID when there is at least one PARTIALLY_PAID paymentOption.
*/
@Test
void testCalculateNewStatus_PartiallyPaid() {
List<PaymentOptionStatus> paymentOptionStatusList = List.of(PaymentOptionStatus.PAID, PaymentOptionStatus.UNPAID);
DebtPositionStatus result = checker.calculateNewStatus(paymentOptionStatusList);
assertEquals(DebtPositionStatus.PARTIALLY_PAID, result);
}

/**
* Test if the status is PARTIALLY_PAID when there is at least one PAID and one EXPIRED paymentOption.
*/
@Test
void testDeterminePaymentOptionStatus_PartiallyPaid2() {
List<PaymentOptionStatus> paymentOptionStatusList = List.of(PaymentOptionStatus.PAID, PaymentOptionStatus.EXPIRED);
void testDeterminePaymentOptionStatus_PartiallyPaid() {
List<PaymentOptionStatus> paymentOptionStatusList = List.of(PaymentOptionStatus.EXPIRED, PaymentOptionStatus.PARTIALLY_PAID);
DebtPositionStatus result = checker.calculateNewStatus(paymentOptionStatusList);
assertEquals(DebtPositionStatus.PARTIALLY_PAID, result);
}
Expand Down

0 comments on commit 307f036

Please sign in to comment.