Android Open Source - u2020-v2 Main Activity Test






From Project

Back to project page u2020-v2.

License

The source code is released under:

Apache License

If you think the Android project u2020-v2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gabor.recyclerview;
/*ww  w.  ja  v a2  s.  c  om*/
import android.app.Instrumentation;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

/**
 * Tests to verify that the behavior of {@link MainActivity} is correct.
 * could also remove any flakiness (timing errors) using https://gist.github.com/xrigau/11284124
 */
public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {

    public MainActivityTest() {
        super(MainActivity.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    /**
     * Clicks on a row and checks that the activity detected the click.
     */
    public void test() {

        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_VIEW);
        try {
            intentFilter.addDataType("application/pdf");
        } catch (IntentFilter.MalformedMimeTypeException e) {
            Log.d("Test log: ", e.getMessage());
        }
        Instrumentation.ActivityMonitor monitor = getInstrumentation().
                addMonitor(intentFilter, null, false);

        onView(withId(R.id.recyclerView)).perform(
                RecyclerViewActions.scrollToPosition(3));
        onView(withId(R.id.recyclerView)).perform(
                RecyclerViewActions.actionOnItemAtPosition(3, click()));
        
        monitor.waitForActivityWithTimeout(5000);
        assertEquals(1, monitor.getHits());
        getInstrumentation().removeMonitor(monitor);
    }
}




Java Source Code List

com.gabor.common.io.IOUtils.java
com.gabor.database.CarT.java
com.gabor.database.Car.java
com.gabor.database.Car_.java
com.gabor.database.DbHelper.java
com.gabor.database.ImagesT.java
com.gabor.recyclerview.CustomAdapter.java
com.gabor.recyclerview.MainActivityTest.java
com.gabor.recyclerview.MainActivity.java
com.gabor.recyclerview.RecyclerViewFragment.java