Back to project page u2020-v2.
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.
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); } }