<commit_before>package com.stolets.rxdiffutil.diffrequest;

import android.support.v7.util.DiffUtil;

import com.stolets.rxdiffutil.BaseTest;
import com.stolets.rxdiffutil.DefaultDiffCallback;
import com.stolets.rxdiffutil.RxDiffResult;

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

import io.reactivex.Single;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Predicate;
import io.reactivex.observers.TestObserver;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Mockito.mock;

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

    @Before
    public void setup() {
        mDiffRequestManager = new DiffRequestManager();
    }

    @Mock
    DiffUtil.Callback mCallback;

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

        // When
        mDiffRequestManager.addPendingRequest(diffRequest);

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

    @Test
    public void execute_GiveDiffUtilCallback_ReturnsNull() {
        // Given
        final DiffRequest diffRequest = new DiffRequest(true, TEST_TAG, mCallback);
        mDiffRequestManager.addPendingRequest(diffRequest);

        // When
        final Single<RxDiffResult> single = mDiffRequestManager.execute(TEST_TAG);

        // Then
        assertThat(single, notNullValue());

        final TestObserver<RxDiffResult> testObserver = new TestObserver<>();
        assert single != null;
        single.subscribe(testObserver);

        testObserver.assertValue(new Predicate<RxDiffResult>() {
            @Override
            public boolean test(@NonNull RxDiffResult rxDiffResult) throws Exception {
                return rxDiffResult.getTag().equals(TEST_TAG);
            }
        });
    }

    @Test
    public void execute_GivenDefaultDiffCallback_ReturnsSingle() {
        // Given
        final DefaultDiffCallback defaultDiffCallback = mock(DefaultDiffCallback.class);
        final DiffRequest diffRequest = new DiffRequest(true, TEST_TAG, defaultDiffCallback);

        mDiffRequestManager.addPendingRequest(diffRequest);

        // When
        final Single<RxDiffResult> single = mDiffRequestManager.execute(TEST_TAG);

        // Then
        assertThat(single, nullValue());
    }
}
<commit_msg>Add removing pending request unit test<commit_after>package com.stolets.rxdiffutil.diffrequest;

import android.support.v7.util.DiffUtil;

import com.stolets.rxdiffutil.BaseTest;
import com.stolets.rxdiffutil.RxDiffResult;

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

import io.reactivex.Single;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Predicate;
import io.reactivex.observers.TestObserver;

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;
    private DiffRequestManager mDiffRequestManager;

    @Before
    public void setup() {
        mDiffRequestManager = new DiffRequestManager();
    }

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

        // When
        mDiffRequestManager.addPendingRequest(diffRequest);

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

    @Test
    public void execute_RemovesPendingRequest() {
        // Given
        final DiffRequest diffRequest = new DiffRequest(true, TEST_TAG, mCallback);
        mDiffRequestManager.addPendingRequest(diffRequest);

        // When
        mDiffRequestManager.execute(TEST_TAG);

        // Then
        assertThat(mDiffRequestManager.getPendingRequests().size(), is(0));
    }

    @Test
    public void execute_ReturnsSharedSingle() {
        // Given
        final DiffRequest diffRequest = new DiffRequest(true, TEST_TAG, mCallback);
        mDiffRequestManager.addPendingRequest(diffRequest);

        // When
        final Single<RxDiffResult> single = mDiffRequestManager.execute(TEST_TAG);

        // Then
        assertThat(single, notNullValue());

        final TestObserver<RxDiffResult> testObserver = new TestObserver<>();
        single.subscribe(testObserver);

        testObserver.assertValue(new Predicate<RxDiffResult>() {
            @Override
            public boolean test(@NonNull RxDiffResult rxDiffResult) throws Exception {
                return rxDiffResult.getTag().equals(TEST_TAG);
            }
        });
    }
}

{'fraction_non_alphanumeric': 0.08904499715207899, 'fraction_numerical': 0.0009493070058857034, 'mean_word_length': 3.3681592039800994, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6004174', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1425, 'n_words': 285}