package com.stolets.rxdiffutil.diffrequest;

import android.support.v7.util.DiffUtil;

import com.stolets.rxdiffutil.BaseTest;

import org.junit.Test;
import org.mockito.Mock;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

public class DiffRequestManagerTest extends BaseTest {
    private static final String TEST_TAG = "TEST_TAG";

    @Mock
    DiffUtil.Callback mCallback;

    @Test
    public void addPendingRequest_AddsRequestToMap() {
        // Given
        final DiffRequestManager manager = new DiffRequestManager();
        final DiffRequest diffRequest = new DiffRequest(true, TEST_TAG, mCallback);

        // When
        manager.addPendingRequest(diffRequest);

        // Then
        assertThat(manager.getPendingRequests().size(), is(1));
        assertThat(manager.getPendingRequests().get(TEST_TAG), notNullValue());
    }
}

@@ -124,55 +124,610 @@
 st;%0A
-%0Aimport org.junit.Test;%0Aimport org.mockito.Mock
+import com.stolets.rxdiffutil.DefaultDiffCallback;%0Aimport com.stolets.rxdiffutil.RxDiffResult;%0A%0Aimport org.junit.Before;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0Aimport org.mockito.Mock;%0A%0Aimport java.util.concurrent.Callable;%0A%0Aimport io.reactivex.Scheduler;%0Aimport io.reactivex.Single;%0Aimport io.reactivex.android.plugins.RxAndroidPlugins;%0Aimport io.reactivex.annotations.NonNull;%0Aimport io.reactivex.functions.Function;%0Aimport io.reactivex.functions.Predicate;%0Aimport io.reactivex.observers.TestObserver;%0Aimport io.reactivex.plugins.RxJavaPlugins;%0Aimport io.reactivex.schedulers.Schedulers
 ;%0A%0Ai
@@ -867,16 +867,103 @@
 llValue;
+%0Aimport static org.hamcrest.Matchers.nullValue;%0Aimport static org.mockito.Mockito.mock;
 %0A%0Apublic
@@ -1065,16 +1065,609 @@
 ST_TAG%22;
+%0A    private DiffRequestManager mDiffRequestManager;%0A%0A    @BeforeClass%0A    public static void setupClass() %7B%0A        RxJavaPlugins.onComputationScheduler(Schedulers.trampoline());%0A%0A        RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function%3CCallable%3CScheduler%3E, Scheduler%3E() %7B%0A            @Override%0A            public Scheduler apply(@NonNull Callable%3CScheduler%3E schedulerCallable) throws Exception %7B%0A                return Schedulers.trampoline();%0A            %7D%0A        %7D);%0A    %7D%0A%0A    @Before%0A    public void setup() %7B%0A        mDiffRequestManager = new DiffRequestManager();%0A    %7D
 %0A%0A    @M
@@ -1790,77 +1790,8 @@
 ven%0A
-        final DiffRequestManager manager = new DiffRequestManager();%0A
     
@@ -1896,16 +1896,28 @@
        m
+DiffRequestM
 anager.a
@@ -1976,32 +1976,44 @@
     assertThat(m
+DiffRequestM
 anager.getPendin
@@ -2060,16 +2060,28 @@
 rtThat(m
+DiffRequestM
 anager.g
@@ -2137,11 +2137,1328 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void execute_GiveDiffUtilCallback_ReturnsNull() %7B%0A        // Given%0A        final DiffRequest diffRequest = new DiffRequest(true, TEST_TAG, mCallback);%0A        mDiffRequestManager.addPendingRequest(diffRequest);%0A%0A        // When%0A        final Single%3CRxDiffResult%3E single = mDiffRequestManager.execute(TEST_TAG);%0A%0A        // Then%0A        assertThat(single, notNullValue());%0A%0A        final TestObserver%3CRxDiffResult%3E testObserver = new TestObserver%3C%3E();%0A        assert single != null;%0A        single.subscribe(testObserver);%0A%0A        testObserver.assertValue(new Predicate%3CRxDiffResult%3E() %7B%0A            @Override%0A            public boolean test(@NonNull RxDiffResult rxDiffResult) throws Exception %7B%0A                return rxDiffResult.getTag().equals(TEST_TAG);%0A            %7D%0A        %7D);%0A    %7D%0A%0A    @Test%0A    public void execute_GivenDefaultDiffCallback_ReturnsSingle() %7B%0A        // Given%0A        final DefaultDiffCallback defaultDiffCallback = mock(DefaultDiffCallback.class);%0A        final DiffRequest diffRequest = new DiffRequest(true, TEST_TAG, defaultDiffCallback);%0A%0A        mDiffRequestManager.addPendingRequest(diffRequest);%0A%0A        // When%0A        final Single%3CRxDiffResult%3E single = mDiffRequestManager.execute(TEST_TAG);%0A%0A        // Then%0A        assertThat(single, nullValue());%0A    %7D
 %0A%7D%0A

Add DiffRequestManager new unit tests