/*
 * Copyright 2014 Danilo Reinert
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.reinert.requestor;

import java.util.Collection;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;

/**
 * Unit tests of {@link ResponseProcessor}.
 */
@RunWith(MockitoJUnitRunner.class)
public class ResponseProcessorTest {

    @Mock private SerializationEngine serializationEngine;
    @Mock private FilterEngine filterEngine;

    private ResponseProcessor processor;

    @Before
    public void setUp() {
        processor = new ResponseProcessor(serializationEngine, filterEngine);
    }

    @Test
    public void process_OneClass_ShouldApplyFiltersThenSerialize() {
        // Given
        final Class<Object> clazz = Object.class;
        Request request = mock(Request.class);
        SerializedResponse response = mock(SerializedResponse.class);

        // When
        processor.process(request, response, clazz);

        // Then
        InOrder inOrder = inOrder(serializationEngine, filterEngine);
        inOrder.verify(serializationEngine).deserializeResponse(request, response, clazz);
        inOrder.verify(filterEngine).filterResponse(eq(request), any(DeserializedResponse.class));
    }

    @Test
    public void process_TwoClasses_ShouldApplyFiltersThenSerialize() {
        // Given
        final Class<Collection> collectionClazz = Collection.class;
        final Class<Object> clazz = Object.class;
        Request request = mock(Request.class);
        SerializedResponse response = mock(SerializedResponse.class);

        // When
        processor.process(request, response, clazz, collectionClazz);

        // Then
        InOrder inOrder = inOrder(serializationEngine, filterEngine);
        inOrder.verify(serializationEngine).deserializeResponse(request, response, clazz, collectionClazz);
        inOrder.verify(filterEngine).filterResponse(eq(request), any(DeserializedResponse.class));
    }
}

@@ -995,16 +995,56 @@
 to.mock;
+%0Aimport static org.mockito.Mockito.when;
 %0A%0A/**%0A *
@@ -1582,55 +1582,8 @@
 ss;%0A
-        Request request = mock(Request.class);%0A
     
@@ -1639,32 +1639,153 @@
 Response.class);
+%0A        Request request = mock(Request.class);%0A        when(request.getResponseType()).thenReturn(ResponseType.DEFAULT);
 %0A%0A        // Whe
@@ -2343,55 +2343,8 @@
 ss;%0A
-        Request request = mock(Request.class);%0A
     
@@ -2408,16 +2408,137 @@
 .class);
+%0A        Request request = mock(Request.class);%0A        when(request.getResponseType()).thenReturn(ResponseType.DEFAULT);
 %0A%0A      

Fix test.