package com.ncornette.rx.test;

import com.ncornette.rx.test.RetrofitSpamServiceWrapper.LogSpamSubscriber;
import com.ncornette.rx.test.service.SpamRXService;

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

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/*
 * This Java source file was auto generated by running 'gradle init --type java-library'
 * by 'nic' at '7/11/16 2:14 PM' with Gradle 2.13
 *
 * @author nic, @date 7/11/16 2:14 PM
 */
public class RetrofitSpamServiceTest {

    protected SpamRXService testServiceClient;
    protected RxTestSchedulers rxTestSchedulers;
    protected RxTestOkHttp rxTestOkhttp;
    private SpamServiceAssertions spamServiceTest;

    @Before
    public void setUp() throws Exception {

        // testing schedulers
        rxTestOkhttp = new RxTestOkHttp();
        rxTestSchedulers = rxTestOkhttp.testSchedulers();

        rxTestSchedulers.newTestSubscriber(new LogSpamSubscriber());

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
        OkHttpClient okHttpClient = rxTestOkhttp.okHttpClient().newBuilder()
                .addInterceptor(loggingInterceptor)
                .build();

        Retrofit build = new Retrofit.Builder()
                .client(okHttpClient)
                .baseUrl(rxTestOkhttp.mockWebServer().url("/"))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        RetrofitSpamService retrofitService = build.create(RetrofitSpamService.class);

        testServiceClient = new RetrofitSpamServiceWrapper(
                rxTestSchedulers.testBackgroundScheduler(),
                rxTestSchedulers.testForegroundScheduler(),
                retrofitService
        );

        spamServiceTest = new SpamServiceAssertions(testServiceClient, rxTestSchedulers);
    }

    @Test
    public void test_SIMPLE_CALL() throws Exception {
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=1.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_12_page=1.json");

        spamServiceTest.assertSimpleCall();
    }

    @Test
    public void test_DISTINCT_PAGE_UNTIL_CHANGED() throws Exception {
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=1.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=2.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=3.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=EMPTY.json");

        spamServiceTest.assertDistinctPageUntilChanged();
    }

    @Test
    public void test_LOAD_3_PAGES() throws Exception {
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=1.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=2.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=3.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=EMPTY.json");

        spamServiceTest.assertLoad3Pages();
    }

    @Test
    public void test_COMPLETES_AT_FIRST_EMPTYLIST() throws Exception {
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=1.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=2.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=3.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=EMPTY.json");

        spamServiceTest.assertCompletesAtFirstEmptyList();
    }

    @Test
    public void test_CACHED_RESULT() throws Exception {
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=1.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=2.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=3.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=EMPTY.json");

        spamServiceTest.assertCachedResult();
    }

    @Test
    public void test_CACHED_RESULT_COMPLETED() throws Exception {
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=1.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=2.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=3.json");
        rxTestOkhttp.enqueueResponseFromFile("/spam_results_6_page=EMPTY.json");

        spamServiceTest.assertCachedResultAfterComplete();
    }

}

@@ -29,83 +29,8 @@
 t;%0A%0A
-import com.ncornette.rx.test.RetrofitSpamServiceWrapper.LogSpamSubscriber;%0A
 impo
@@ -951,78 +951,8 @@
 );%0A%0A
-        rxTestSchedulers.newTestSubscriber(new LogSpamSubscriber());%0A%0A
     

Remove custom logger