<commit_before>/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.support.v4.widget;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.v4.widget.SwipeRefreshLayoutActions.setEnabled;
import static android.support.v4.widget.SwipeRefreshLayoutActions.setRefreshing;
import static android.support.v4.widget.SwipeRefreshLayoutActions.setSize;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.support.coreui.test.R;
import android.support.test.espresso.action.ViewActions;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
import android.support.v4.BaseInstrumentationTestCase;
import android.support.v4.testutils.PollingCheck;
import android.view.View;

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

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * Tests SwipeRefreshLayout widget.
 */
public class SwipeRefreshLayoutTest
        extends BaseInstrumentationTestCase<SwipeRefreshLayoutActivity> {
    private static final long TIMEOUT = 1000;
    private static final int INVALID_SIZE = 1000;

    private SwipeRefreshLayout mSwipeRefresh;

    public SwipeRefreshLayoutTest() {
        super(SwipeRefreshLayoutActivity.class);
    }

    @Before
    public void setUp() {
        mSwipeRefresh = (SwipeRefreshLayout) mActivityTestRule.getActivity().findViewById(
                R.id.swipe_refresh);
    }

    @Test
    @MediumTest
    public void testStartAndStopRefreshing() throws Throwable {
        SwipeRefreshLayout.OnRefreshListener mockListener =
                mock(SwipeRefreshLayout.OnRefreshListener.class);
        mSwipeRefresh.setOnRefreshListener(mockListener);

        assertFalse(mSwipeRefresh.isRefreshing());
        for (int i = 0; i < 5; i++) {
            onView(withId(R.id.swipe_refresh)).perform(setRefreshing());
            assertTrue(mSwipeRefresh.isRefreshing());

            // onView(..).perform(..) does not work when views are animated.
            // Therefore this is using a posted task to turn off refreshing.
            mSwipeRefresh.getHandler().post(new Runnable() {
                @Override
                public void run() {
                    mSwipeRefresh.setRefreshing(false);
                }
            });

            new PollingCheck(TIMEOUT) {
                @Override
                protected boolean check() {
                    return mSwipeRefresh.isRefreshing();
                }
            }.run();
        }<commit_msg>Fix condition in one of the tests<commit_after>/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.support.v4.widget;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.v4.widget.SwipeRefreshLayoutActions.setEnabled;
import static android.support.v4.widget.SwipeRefreshLayoutActions.setRefreshing;
import static android.support.v4.widget.SwipeRefreshLayoutActions.setSize;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.support.coreui.test.R;
import android.support.test.espresso.action.ViewActions;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
import android.support.v4.BaseInstrumentationTestCase;
import android.support.v4.testutils.PollingCheck;
import android.view.View;

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

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * Tests SwipeRefreshLayout widget.
 */
public class SwipeRefreshLayoutTest
        extends BaseInstrumentationTestCase<SwipeRefreshLayoutActivity> {
    private static final long TIMEOUT = 1000;
    private static final int INVALID_SIZE = 1000;

    private SwipeRefreshLayout mSwipeRefresh;

    public SwipeRefreshLayoutTest() {
        super(SwipeRefreshLayoutActivity.class);
    }

    @Before
    public void setUp() {
        mSwipeRefresh = (SwipeRefreshLayout) mActivityTestRule.getActivity().findViewById(
                R.id.swipe_refresh);
    }

    @Test
    @MediumTest
    public void testStartAndStopRefreshing() throws Throwable {
        SwipeRefreshLayout.OnRefreshListener mockListener =
                mock(SwipeRefreshLayout.OnRefreshListener.class);
        mSwipeRefresh.setOnRefreshListener(mockListener);

        assertFalse(mSwipeRefresh.isRefreshing());
        for (int i = 0; i < 5; i++) {
            onView(withId(R.id.swipe_refresh)).perform(setRefreshing());
            assertTrue(mSwipeRefresh.isRefreshing());

            // onView(..).perform(..) does not work when views are animated.
            // Therefore this is using a posted task to turn off refreshing.
            mSwipeRefresh.getHandler().post(new Runnable() {
                @Override
                public void run() {
                    mSwipeRefresh.setRefreshing(false);
                }
            });

            PollingCheck.waitFor(TIMEOUT, new PollingCheck.PollingCheckCondition() {
                @Override
                public boolean canProceed() {
                    return !mSwipeRefresh.isRefreshing();
                }
            });
        }
{'fraction_non_alphanumeric': 0.08658313388708996, 'fraction_numerical': 0.0067577080106997044, 'mean_word_length': 3.2666666666666666, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '377159', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1906, 'n_words': 492}