package com.commercetools.pspadapter.payone.domain.ctp;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import io.sphere.sdk.client.SphereClient;
import io.sphere.sdk.payments.Payment;
import io.sphere.sdk.payments.queries.PaymentQuery;
import io.sphere.sdk.queries.PagedQueryResult;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.concurrent.CompletionStage;

/**
 * @author fhaertig
 * @date 03.12.15
 */
@RunWith(MockitoJUnitRunner.class)
public class CommercetoolsClientTest {

    @Mock
    private SphereClient sphereClient;

    private PaymentQuery paymentSphereRequest = PaymentQuery.of();

    @InjectMocks
    private CommercetoolsClient client;

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Test
    public void sphereClientRequestDelegation() throws CommercetoolsApiException {
        @SuppressWarnings("unchecked")
        CompletionStage<PagedQueryResult<Payment>> paymentCompletionStage =
                (CompletionStage<PagedQueryResult<Payment>>) mock(CompletionStage.class);

        when(sphereClient.execute(same(paymentSphereRequest))).thenReturn(paymentCompletionStage);
        assertThat(client.execute(paymentSphereRequest), is(sameInstance(paymentCompletionStage)));
    }

    @Test
    public void throwExceptionWhenSphereClient() throws CommercetoolsApiException {
        RuntimeException runtimeException = new RuntimeException();
        when(sphereClient.execute(same(paymentSphereRequest))).thenThrow(runtimeException);
        thrown.expect(instanceOf(CommercetoolsApiException.class));
        thrown.expectCause(sameInstance(runtimeException));

        client.execute(paymentSphereRequest);
    }

}
@@ -54,60 +54,8 @@
 p;%0A%0A
-import static org.hamcrest.CoreMatchers.instanceOf;%0A
 impo
@@ -524,77 +524,12 @@
 nit.
-Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ExpectedException
+Test
 ;%0Aim
@@ -1011,83 +1011,8 @@
 t;%0A%0A
-    @Rule%0A    public ExpectedException thrown = ExpectedException.none();%0A%0A
     
@@ -1069,40 +1069,8 @@
 n() 
-throws CommercetoolsApiException
  %7B%0A 
@@ -1484,441 +1484,5 @@
  %7D%0A%0A
-    @Test%0A    public void throwExceptionWhenSphereClient() throws CommercetoolsApiException %7B%0A        RuntimeException runtimeException = new RuntimeException();%0A        when(sphereClient.execute(same(paymentSphereRequest))).thenThrow(runtimeException);%0A        thrown.expect(instanceOf(CommercetoolsApiException.class));%0A        thrown.expectCause(sameInstance(runtimeException));%0A%0A        client.execute(paymentSphereRequest);%0A    %7D%0A%0A
 %7D

Remove CTApiException Test because unnecessary