<commit_before>package com.commercetools.pspadapter.payone.notification;

import com.commercetools.pspadapter.BaseTenantPropertyTest;
import com.commercetools.pspadapter.payone.config.PayoneConfig;
import com.commercetools.pspadapter.payone.domain.payone.model.common.Notification;
import com.commercetools.pspadapter.payone.domain.payone.model.common.NotificationAction;
import com.commercetools.pspadapter.payone.domain.payone.model.common.TransactionStatus;
import com.commercetools.pspadapter.payone.util.PayoneHash;
import com.commercetools.pspadapter.tenant.TenantFactory;
import com.commercetools.service.PaymentServiceImpl;
import com.google.common.collect.ImmutableMap;
import io.sphere.sdk.payments.Payment;
import io.sphere.sdk.payments.PaymentDraft;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import util.PaymentTestHelper;

import java.util.ConcurrentModificationException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

import static com.commercetools.pspadapter.payone.util.PayoneConstants.PAYONE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.ThrowableAssert.catchThrowable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.*;

/**
 * @author fhaertig
 * @author <NAME>
 * @since 05.01.16
 */
@RunWith(MockitoJUnitRunner.class)
public class NotificationDispatcherTest extends BaseTenantPropertyTest {

    private static final String dummyInterfaceId = "123";

    @Mock
    private TenantFactory tenantFactory;

    @Mock
    private PaymentServiceImpl paymentServiceImpl;

    @Mock
    private NotificationProcessor defaultNotificationProcessor;

    @Mock
    private NotificationProcessor specificNotificationProcessor;

    private final PaymentTestHelper testHelper = new PaymentTestHelper();

    private PayoneConfig config;

    private ImmutableMap<NotificationAction, NotificationProcessor> processors;

    @Before
    @SuppressWarnings("unchecked")
    public void setUp() throws Exception {
        super.setUp();

        when(tenantFactory.getPayoneInterfaceName()).thenReturn(PAYONE);
        when(tenantFactory.getPaymentService()).thenReturn(paymentServiceImpl);

        when(paymentServiceImpl.getByPaymentMethodAndInterfaceId(anyString(), anyString()))
                .then(a -> {

                    String interfaceId = a.getArgument(1, String.class);
                    Optional<Payment> payment = dummyInterfaceId.equals(interfaceId)
                            ? testHelper.getPaymentQueryResultFromFile("dummyPaymentQueryResult.json").head()
                            : Optional.empty();

                    return CompletableFuture.completedFuture(payment);
                });

        when(paymentServiceImpl.createPayment(anyObject())).then(
                answer -> {
                    PaymentDraft draft = answer.getArgumentAt(0, PaymentDraft.class);
                    Payment payment = dummyInterfaceId.equals(draft.getInterfaceId())
                            ? testHelper.getPaymentQueryResultFromFile("dummyPaymentQueryResult.json").head().get()
                            : testHelper.dummyPaymentCreatedByNotification();<commit_msg>Change method name for Mockito 3.3.3<commit_after>package com.commercetools.pspadapter.payone.notification;

import com.commercetools.pspadapter.BaseTenantPropertyTest;
import com.commercetools.pspadapter.payone.config.PayoneConfig;
import com.commercetools.pspadapter.payone.domain.payone.model.common.Notification;
import com.commercetools.pspadapter.payone.domain.payone.model.common.NotificationAction;
import com.commercetools.pspadapter.payone.domain.payone.model.common.TransactionStatus;
import com.commercetools.pspadapter.payone.util.PayoneHash;
import com.commercetools.pspadapter.tenant.TenantFactory;
import com.commercetools.service.PaymentServiceImpl;
import com.google.common.collect.ImmutableMap;
import io.sphere.sdk.payments.Payment;
import io.sphere.sdk.payments.PaymentDraft;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import util.PaymentTestHelper;

import java.util.ConcurrentModificationException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

import static com.commercetools.pspadapter.payone.util.PayoneConstants.PAYONE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.ThrowableAssert.catchThrowable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.*;

/**
 * @author fhaertig
 * @author <NAME>
 * @since 05.01.16
 */
@RunWith(MockitoJUnitRunner.class)
public class NotificationDispatcherTest extends BaseTenantPropertyTest {

    private static final String dummyInterfaceId = "123";

    @Mock
    private TenantFactory tenantFactory;

    @Mock
    private PaymentServiceImpl paymentServiceImpl;

    @Mock
    private NotificationProcessor defaultNotificationProcessor;

    @Mock
    private NotificationProcessor specificNotificationProcessor;

    private final PaymentTestHelper testHelper = new PaymentTestHelper();

    private PayoneConfig config;

    private ImmutableMap<NotificationAction, NotificationProcessor> processors;

    @Before
    @SuppressWarnings("unchecked")
    public void setUp() throws Exception {
        super.setUp();

        when(tenantFactory.getPayoneInterfaceName()).thenReturn(PAYONE);
        when(tenantFactory.getPaymentService()).thenReturn(paymentServiceImpl);

        when(paymentServiceImpl.getByPaymentMethodAndInterfaceId(anyString(), anyString()))
                .then(a -> {

                    String interfaceId = a.getArgument(1, String.class);
                    Optional<Payment> payment = dummyInterfaceId.equals(interfaceId)
                            ? testHelper.getPaymentQueryResultFromFile("dummyPaymentQueryResult.json").head()
                            : Optional.empty();

                    return CompletableFuture.completedFuture(payment);
                });

        when(paymentServiceImpl.createPayment(anyObject())).then(
                answer -> {
                    PaymentDraft draft = answer.getArgument(0, PaymentDraft.class);
                    Payment payment = dummyInterfaceId.equals(draft.getInterfaceId())
                            ? testHelper.getPaymentQueryResultFromFile("dummyPaymentQueryResult.json").head().get()
                            : testHelper.dummyPaymentCreatedByNotification();
{'fraction_non_alphanumeric': 0.09008473316485803, 'fraction_numerical': 0.0037163668797383677, 'mean_word_length': 3.8966521106259098, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7327133', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1801, 'n_words': 288}