diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemWriter.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemWriter.java index 95dc8953b..4fa5e9d0f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemWriter.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemWriter.java @@ -36,9 +36,11 @@ public abstract class AbstractLoanItemWriter extends RepositoryItemWriter @Override public void write(@NotNull List items) throws Exception { - super.write(items); - List loanIds = items.stream().map(AbstractPersistableCustom::getId).toList(); - accountLockRepository.deleteByLoanIdInAndLockOwner(loanIds, getLockOwner()); + if (!items.isEmpty()) { + super.write(items); + List loanIds = items.stream().map(AbstractPersistableCustom::getId).toList(); + accountLockRepository.deleteByLoanIdInAndLockOwner(loanIds, getLockOwner()); + } } protected abstract LockOwner getLockOwner(); diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemWriterStepDefinitions.java b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemWriterStepDefinitions.java index 9ec051544..36ca22972 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemWriterStepDefinitions.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemWriterStepDefinitions.java @@ -18,7 +18,6 @@ */ package org.apache.fineract.cob.loan; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -27,7 +26,6 @@ import io.cucumber.java8.En; import java.util.Collections; import java.util.List; import org.apache.fineract.cob.domain.LoanAccountLockRepository; -import org.apache.fineract.cob.domain.LockOwner; import org.apache.fineract.portfolio.loanaccount.domain.Loan; import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository; import org.mockito.Mockito; @@ -48,8 +46,6 @@ public class LoanItemWriterStepDefinitions implements En { lenient().when(loan.getId()).thenReturn(1L); if (action.equals("error")) { this.items = Collections.emptyList(); - lenient().doThrow(new RuntimeException("fail")).when(this.accountLockRepository) - .deleteByLoanIdInAndLockOwner(Collections.emptyList(), LockOwner.LOAN_COB_CHUNK_PROCESSING); } else { this.items = Collections.singletonList(loan); lenient().doNothing().when(this.accountLockRepository).deleteByLoanIdInAndLockOwner(Mockito.anyList(), Mockito.any()); @@ -65,10 +61,8 @@ public class LoanItemWriterStepDefinitions implements En { verify(this.accountLockRepository, Mockito.times(1)).deleteByLoanIdInAndLockOwner(Mockito.any(), Mockito.any()); }); - Then("throw exception LoanItemWriter.write method", () -> { - assertThrows(RuntimeException.class, () -> { - this.loanItemWriter.write(items); - }); + Then("LoanItemWriter.write should not call repository", () -> { + verify(this.accountLockRepository, Mockito.times(0)).deleteByLoanIdInAndLockOwner(Mockito.any(), Mockito.any()); }); } } diff --git a/fineract-provider/src/test/resources/features/cob/loan/cob.loan.writer.feature b/fineract-provider/src/test/resources/features/cob/loan/cob.loan.writer.feature index 1ecccaef1..fba14efc5 100644 --- a/fineract-provider/src/test/resources/features/cob/loan/cob.loan.writer.feature +++ b/fineract-provider/src/test/resources/features/cob/loan/cob.loan.writer.feature @@ -32,8 +32,8 @@ Feature: COB Writer @cob Scenario Outline: LoanItemWriter - run test: exception Given The LoanItemWriter.write method with action - Then throw exception LoanItemWriter.write method + Then LoanItemWriter.write should not call repository Examples: |action| - |error| \ No newline at end of file + |error|