package com.atlassian.stash.internal.rest.filter;

import com.atlassian.bitbucket.rest.enrich.AvatarEnricher;
import com.atlassian.bitbucket.rest.enrich.LinkEnricher;
import com.atlassian.bitbucket.avatar.AvatarRequest;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import javax.ws.rs.core.MultivaluedMap;

import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class EnricherResponseFilterTest {

    @Mock
    private AvatarEnricher avatarEnricher;
    @Mock
    private LinkEnricher linkEnricher;
    @InjectMocks
    private EnricherResponseFilter filter;

    @Test
    public void testEnriches() {
        @SuppressWarnings("unchecked")
        MultivaluedMap<String, String> headers = mock(MultivaluedMap.class);

        ContainerRequest request = mock(ContainerRequest.class);
        when(request.getQueryParameters()).thenReturn(headers);

        Object entity = new Object();

        ContainerResponse response = mock(ContainerResponse.class);
        when(response.getEntity()).thenReturn(entity);

        assertSame(response, filter.filter(request, response));
        verify(avatarEnricher).enrich(same(entity), any(AvatarRequest.class));
        verify(linkEnricher).enrich(same(entity));
    }
}
