<commit_before>package de.nenick.espressomacchiato.elements;

import android.support.test.espresso.NoMatchingViewException;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import junit.framework.AssertionFailedError;

import org.junit.Test;

import de.nenick.espressomacchiato.test.views.BaseActivity;
import de.nenick.espressomacchiato.testbase.EspressoTestCase;

public class EspViewTest extends EspressoTestCase<BaseActivity> {

    private static final String VIEW_WAS_CLICKED_MESSAGE = "view was clicked";

    private int viewId = android.R.id.button1;
    private EspView espView = EspView.byId(viewId);
    private Button view;

    private int messageViewId = android.R.id.text1;
    private TextView messageView;
    private EspTextView espTextView = EspTextView.byId(messageViewId);

    @Test
    public void testAssertions() {
        espTextView.assertNotExist();

        givenClickableView();

        espView.assertIsVisible();
        espView.assertIsEnabled();
        espView.assertIsDisplayedOnScreen();

        givenViewIsDisabled();
        espView.assertIsDisabled();

        givenViewIsInvisible();
        espView.assertIsHidden();

        givenViewIsGone();
        espView.assertIsHidden();
    }

    @Test
    public void testAssertIsDisplayedOnScreenFailure() {
        givenViewOutsideOfScreen(android.R.id.text2);
        EspView.byId(android.R.id.text2).assertIsVisible();

        exception.expect(AssertionFailedError.class);
        EspView.byId(android.R.id.text2).assertIsDisplayedOnScreen();
    }

    @Test
    public void testClick() {
        givenClickableView();
        givenClickFeedbackTextView();

        espView.click();
        espTextView.assertTextIs(VIEW_WAS_CLICKED_MESSAGE);
    }

    @Test
    public void testClickFailureWhenNotVisible() {
        exception.expect(NoMatchingViewException.class);
        exception.expectMessage("No views in hierarchy found matching: (with id: android:id/button1 and is displayed on the screen to the user)");

        givenClickableView();
        view.setVisibility(View.INVISIBLE);
        espView.click();
    }

    @Test
    public void testClickSelectsOnlyVisibleView() {
        givenClickableView();
        view.setVisibility(View.INVISIBLE);
        givenClickableView();
        givenClickFeedbackTextView();

        espView.click();
        espTextView.assertTextIs(VIEW_WAS_CLICKED_MESSAGE);
    }

    private void givenViewIsInvisible() {
        performOnUiThread(new Runnable() {
            @Override
            public void run() {
                view.setVisibility(View.INVISIBLE);
            }
        });
    }

    private void givenViewIsGone() {
        performOnUiThread(new Runnable() {
            @Override
            public void run() {
                view.setVisibility(View.GONE);<commit_msg>visibility changes only in main thread<commit_after>package de.nenick.espressomacchiato.elements;

import android.support.test.espresso.NoMatchingViewException;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import junit.framework.AssertionFailedError;

import org.junit.Test;

import de.nenick.espressomacchiato.test.views.BaseActivity;
import de.nenick.espressomacchiato.testbase.EspressoTestCase;

public class EspViewTest extends EspressoTestCase<BaseActivity> {

    private static final String VIEW_WAS_CLICKED_MESSAGE = "view was clicked";

    private int viewId = android.R.id.button1;
    private EspView espView = EspView.byId(viewId);
    private Button view;

    private int messageViewId = android.R.id.text1;
    private TextView messageView;
    private EspTextView espTextView = EspTextView.byId(messageViewId);

    @Test
    public void testAssertions() {
        espTextView.assertNotExist();

        givenClickableView();

        espView.assertIsVisible();
        espView.assertIsEnabled();
        espView.assertIsDisplayedOnScreen();

        givenViewIsDisabled();
        espView.assertIsDisabled();

        givenViewIsInvisible();
        espView.assertIsHidden();

        givenViewIsGone();
        espView.assertIsHidden();
    }

    @Test
    public void testAssertIsDisplayedOnScreenFailure() {
        givenViewOutsideOfScreen(android.R.id.text2);
        EspView.byId(android.R.id.text2).assertIsVisible();

        exception.expect(AssertionFailedError.class);
        EspView.byId(android.R.id.text2).assertIsDisplayedOnScreen();
    }

    @Test
    public void testClick() {
        givenClickableView();
        givenClickFeedbackTextView();

        espView.click();
        espTextView.assertTextIs(VIEW_WAS_CLICKED_MESSAGE);
    }

    @Test
    public void testClickFailureWhenNotVisible() {
        exception.expect(NoMatchingViewException.class);
        exception.expectMessage("No views in hierarchy found matching: (with id: android:id/button1 and is displayed on the screen to the user)");

        givenClickableView();
        givenViewIsInvisible();
        espView.click();
    }

    @Test
    public void testClickSelectsOnlyVisibleView() {
        givenClickableView();
        givenViewIsInvisible();
        givenClickableView();
        givenClickFeedbackTextView();

        espView.click();
        espTextView.assertTextIs(VIEW_WAS_CLICKED_MESSAGE);
    }

    private void givenViewIsInvisible() {
        performOnUiThread(new Runnable() {
            @Override
            public void run() {
                view.setVisibility(View.INVISIBLE);
            }
        });
    }

    private void givenViewIsGone() {
        performOnUiThread(new Runnable() {
            @Override
            public void run() {
                view.setVisibility(View.GONE);
{'fraction_non_alphanumeric': 0.0916535981878376, 'fraction_numerical': 0.0020909566126502874, 'mean_word_length': 2.997214484679666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4630850', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1589, 'n_words': 284}