package com.yelp.clientlib.integration;

import com.yelp.clientlib.connection.YelpAPI;
import com.yelp.clientlib.connection.YelpAPIFactory;
import com.yelp.clientlib.entities.Business;
import com.yelp.clientlib.util.AsyncTestUtil;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import retrofit.Call;
import retrofit.Callback;
import retrofit.Response;
import retrofit.Retrofit;

/**
 * TODO: Move this class to other directory so src/java/test only contains unit-tests related files.
 */
public class BusinessIntegrationTest {
    private String businessId = "yelp-san-francisco";
    private YelpAPI yelpAPI;

    @Before
    public void setUp() {
        YelpAPIFactory yelpAPIFactory = new YelpAPIFactory(
                Credential.getConsumerKey(),
                Credential.getConsumerSecret(),
                Credential.getToken(),
                Credential.getTokenSecret()
        );

        // Make API requests to be executed in main thread so we can verify it easily.
        yelpAPIFactory = AsyncTestUtil.setToRunInMainThread(yelpAPIFactory);

        yelpAPI = yelpAPIFactory.createAPI();
    }

    @Test
    public void testGetBusiness() throws IOException {
        Call<Business> call = yelpAPI.getBusiness(businessId);
        Response<Business> response = call.execute();
        Assert.assertEquals(200, response.code());

        Business business = response.body();
        Assert.assertNotNull(business);
        Assert.assertEquals(businessId, business.id());
    }

    @Test
    public void testGetBusinessWithParams() throws IOException {
        Map<String, String> params = new HashMap<>();
        params.put("cc", "US");
        params.put("lang", "en");
        params.put("lang_filter", "true");
        params.put("actionlinks", "true");
        params.put("whatsoever", "well");

        Call<Business> call = yelpAPI.getBusiness(businessId, params);
        Response<Business> response = call.execute();
        Assert.assertEquals(200, response.code());

        Business business = response.body();
        Assert.assertNotNull(business);
        Assert.assertEquals(businessId, business.id());
    }

    @Test
    public void testGetBusinessParamsBeURLEncoded() throws IOException {
        Map<String, String> params = new HashMap<>();
        params.put("whatsoever", "well it's encoded");

        Call<Business> call = yelpAPI.getBusiness(businessId, params);
        Response<Business> response = call.execute();
        Assert.assertEquals(200, response.code());

        Business business = response.body();
        Assert.assertNotNull(business);
        Assert.assertEquals(businessId, business.id());
    }

    @Test
    public void testGetBusinessAsynchronous() {
        final ArrayList<Response<Business>> responseWrapper = new ArrayList<>();
        Callback<Business> businessCallback = new Callback<Business>() {
            @Override
            public void onResponse(Response<Business> response, Retrofit retrofit) {
                responseWrapper.add(response);
            }

            @Override
            public void onFailure(Throwable t) {

            }
        };

        Call<Business> call = yelpAPI.getBusiness(businessId);
        call.enqueue(businessCallback);

        Response<Business> response = responseWrapper.get(0);
        Assert.assertEquals(200, response.code());

        Business business = response.body();
        Assert.assertNotNull(business);
        Assert.assertEquals(businessId, business.id());
    }
}

@@ -1907,568 +1907,8 @@
 e%22);
-%0A        params.put(%22whatsoever%22, %22well%22);%0A%0A        Call%3CBusiness%3E call = yelpAPI.getBusiness(businessId, params);%0A        Response%3CBusiness%3E response = call.execute();%0A        Assert.assertEquals(200, response.code());%0A%0A        Business business = response.body();%0A        Assert.assertNotNull(business);%0A        Assert.assertEquals(businessId, business.id());%0A    %7D%0A%0A    @Test%0A    public void testGetBusinessParamsBeURLEncoded() throws IOException %7B%0A        Map%3CString, String%3E params = new HashMap%3C%3E();%0A        params.put(%22whatsoever%22, %22well it's encoded%22);
 %0A%0A  

Remove redundant tests.