// Path: adyenv6core/src/com/adyen/v6/actions/AbstractWaitableAction.java
// abstract public class AbstractWaitableAction<T extends BusinessProcessModel> extends AbstractAction<T> {
//     public enum Transition {
//         OK, NOK, WAIT;
// 
//         public static Set<String> getStringValues() {
//             Set<String> res = new HashSet<>();
//             for (final Transition transitions : Transition.values()) {
//                 res.add(transitions.toString());
//             }
//             return res;
//         }
//     }
// 
//     @Override
//     public Set<String> getTransitions() {
//         return Transition.getStringValues();
//     }
// }
// 
// Path: adyenv6core/testsrc/com/adyen/v6/actions/order/AbstractActionTest.java
// public class AbstractActionTest {
//     protected PaymentTransactionEntryModel createAuthorizedEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.AUTHORIZATION);
//         entry.setTransactionStatus(TransactionStatus.ACCEPTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.SUCCESFULL.name());
//         entry.setAmount(new BigDecimal("12.34"));
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createAuthorizedRejectedEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.AUTHORIZATION);
//         entry.setTransactionStatus(TransactionStatus.REJECTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.UNKNOWN_CODE.name());
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createCaptureReceivedEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.CAPTURE);
//         entry.setTransactionStatus(TransactionStatus.ACCEPTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.REVIEW_NEEDED.name());
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createCaptureSuccessEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.CAPTURE);
//         entry.setTransactionStatus(TransactionStatus.ACCEPTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.SUCCESFULL.name());
//         entry.setAmount(new BigDecimal("12.34"));
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createCaptureRejectedEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.CAPTURE);
//         entry.setTransactionStatus(TransactionStatus.REJECTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.GENERAL_SYSTEM_ERROR.name());
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createRefundRejectedEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.REFUND_FOLLOW_ON);
//         entry.setTransactionStatus(TransactionStatus.REJECTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.UNKNOWN_CODE.name());
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createRefundSuccessEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.REFUND_FOLLOW_ON);
//         entry.setTransactionStatus(TransactionStatus.ACCEPTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.SUCCESFULL.name());
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionModel createAdyenTransaction() {
//         PaymentTransactionModel adyenTransaction = new PaymentTransactionModel();
//         adyenTransaction.setPaymentProvider(PAYMENT_PROVIDER);
//         adyenTransaction.setEntries(new ArrayList<>());
// 
//         return adyenTransaction;
//     }
// }


import com.adyen.v6.actions.AbstractWaitableAction;
import com.adyen.v6.actions.order.AbstractActionTest;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.basecommerce.enums.ReturnStatus;
import de.hybris.platform.core.model.order.OrderModel;
import de.hybris.platform.core.model.order.payment.PaymentInfoModel;
import de.hybris.platform.payment.PaymentService;
import de.hybris.platform.payment.dto.TransactionStatus;
import de.hybris.platform.payment.dto.TransactionStatusDetails;
import de.hybris.platform.payment.model.PaymentTransactionEntryModel;
import de.hybris.platform.payment.model.PaymentTransactionModel;
import de.hybris.platform.returns.model.ReturnEntryModel;
import de.hybris.platform.returns.model.ReturnProcessModel;
import de.hybris.platform.returns.model.ReturnRequestModel;
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.warehousing.returns.service.RefundAmountCalculationService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

        Mockito.verify(returnRequestModelMock).setStatus(ReturnStatus.PAYMENT_REVERSAL_FAILED);
        Mockito.verify(modelServiceMock).save(returnRequestModelMock);
    }

    /**
     * Test when the full amount is not captured yet
     */
    @Test
    public void testWaitForFullAmount() {
        PaymentTransactionModel adyenTransaction = createAdyenTransaction();
        List<PaymentTransactionModel> transactions = new ArrayList<>();
        transactions.add(adyenTransaction);

        when(orderModelMock.getPaymentTransactions()).thenReturn(transactions);

        adyenTransaction.getEntries().add(createAuthorizedEntry());
        adyenTransaction.getEntries().add(createCaptureSuccessEntry());

        PaymentTransactionEntryModel refundReceivedTransaction = new PaymentTransactionEntryModel();
        refundReceivedTransaction.setTransactionStatus(TransactionStatus.ACCEPTED.name());
        refundReceivedTransaction.setTransactionStatusDetails(TransactionStatusDetails.REVIEW_NEEDED.name());
        when(paymentServiceMock.refundFollowOn(adyenTransaction, originalRefundAmount))
                .thenReturn(refundReceivedTransaction);

        assertEquals(
                AbstractWaitableAction.Transition.WAIT.toString(),
                adyenCaptureRefundAction.execute(returnProcessModelMock)
        );

// Path: adyenv6core/src/com/adyen/v6/actions/AbstractWaitableAction.java
// abstract public class AbstractWaitableAction<T extends BusinessProcessModel> extends AbstractAction<T> {
//     public enum Transition {
//         OK, NOK, WAIT;
// 
//         public static Set<String> getStringValues() {
//             Set<String> res = new HashSet<>();
//             for (final Transition transitions : Transition.values()) {
//                 res.add(transitions.toString());
//             }
//             return res;
//         }
//     }
// 
//     @Override
//     public Set<String> getTransitions() {
//         return Transition.getStringValues();
//     }
// }
// 
// Path: adyenv6core/testsrc/com/adyen/v6/actions/order/AbstractActionTest.java
// public class AbstractActionTest {
//     protected PaymentTransactionEntryModel createAuthorizedEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.AUTHORIZATION);
//         entry.setTransactionStatus(TransactionStatus.ACCEPTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.SUCCESFULL.name());
//         entry.setAmount(new BigDecimal("12.34"));
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createAuthorizedRejectedEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.AUTHORIZATION);
//         entry.setTransactionStatus(TransactionStatus.REJECTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.UNKNOWN_CODE.name());
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createCaptureReceivedEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.CAPTURE);
//         entry.setTransactionStatus(TransactionStatus.ACCEPTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.REVIEW_NEEDED.name());
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createCaptureSuccessEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.CAPTURE);
//         entry.setTransactionStatus(TransactionStatus.ACCEPTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.SUCCESFULL.name());
//         entry.setAmount(new BigDecimal("12.34"));
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createCaptureRejectedEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.CAPTURE);
//         entry.setTransactionStatus(TransactionStatus.REJECTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.GENERAL_SYSTEM_ERROR.name());
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createRefundRejectedEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.REFUND_FOLLOW_ON);
//         entry.setTransactionStatus(TransactionStatus.REJECTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.UNKNOWN_CODE.name());
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionEntryModel createRefundSuccessEntry() {
//         PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
//         entry.setType(PaymentTransactionType.REFUND_FOLLOW_ON);
//         entry.setTransactionStatus(TransactionStatus.ACCEPTED.name());
//         entry.setTransactionStatusDetails(TransactionStatusDetails.SUCCESFULL.name());
// 
//         return entry;
//     }
// 
//     protected PaymentTransactionModel createAdyenTransaction() {
//         PaymentTransactionModel adyenTransaction = new PaymentTransactionModel();
//         adyenTransaction.setPaymentProvider(PAYMENT_PROVIDER);
//         adyenTransaction.setEntries(new ArrayList<>());
// 
//         return adyenTransaction;
//     }
// }


// Path: adyenv6ordermanagement/testsrc/com/adyen/v6/actions/returns/AdyenCaptureRefundActionTest.java
import com.adyen.v6.actions.AbstractWaitableAction;
import com.adyen.v6.actions.order.AbstractActionTest;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.basecommerce.enums.ReturnStatus;
import de.hybris.platform.core.model.order.OrderModel;
import de.hybris.platform.core.model.order.payment.PaymentInfoModel;
import de.hybris.platform.payment.PaymentService;
import de.hybris.platform.payment.dto.TransactionStatus;
import de.hybris.platform.payment.dto.TransactionStatusDetails;
import de.hybris.platform.payment.model.PaymentTransactionEntryModel;
import de.hybris.platform.payment.model.PaymentTransactionModel;
import de.hybris.platform.returns.model.ReturnEntryModel;
import de.hybris.platform.returns.model.ReturnProcessModel;
import de.hybris.platform.returns.model.ReturnRequestModel;
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.warehousing.returns.service.RefundAmountCalculationService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;


        Mockito.verify(returnRequestModelMock).setStatus(ReturnStatus.PAYMENT_REVERSAL_FAILED);
        Mockito.verify(modelServiceMock).save(returnRequestModelMock);
    }

    /**
     * Test when the full amount is not captured yet
     */
    @Test
    public void testWaitForFullAmount() {
        PaymentTransactionModel adyenTransaction = createAdyenTransaction();
        List<PaymentTransactionModel> transactions = new ArrayList<>();
        transactions.add(adyenTransaction);

        when(orderModelMock.getPaymentTransactions()).thenReturn(transactions);

        adyenTransaction.getEntries().add(createAuthorizedEntry());
        adyenTransaction.getEntries().add(createCaptureSuccessEntry());

        PaymentTransactionEntryModel refundReceivedTransaction = new PaymentTransactionEntryModel();
        refundReceivedTransaction.setTransactionStatus(TransactionStatus.ACCEPTED.name());
        refundReceivedTransaction.setTransactionStatusDetails(TransactionStatusDetails.REVIEW_NEEDED.name());
        when(paymentServiceMock.refundFollowOn(adyenTransaction, originalRefundAmount))
                .thenReturn(refundReceivedTransaction);

        assertEquals(
                AbstractWaitableAction.Transition.WAIT.toString(),
                adyenCaptureRefundAction.execute(returnProcessModelMock)
        );

        PaymentTransactionEntryModel refundTransaction = createRefundSuccessEntry();