List of usage examples for android.app Instrumentation invokeMenuActionSync
public boolean invokeMenuActionSync(Activity targetActivity, int id, int flag)
From source file:au.com.cybersearch2.classyfy.MainActivityTest.java
public void test_search() throws Throwable { final MainActivity mainActivity = getActivity(); Instrumentation instrumentation = getInstrumentation(); ActivityMonitor am = instrumentation.addMonitor(TitleSearchResultsActivity.class.getName(), null, false); assertThat(instrumentation.invokeMenuActionSync(mainActivity, R.id.action_search, 0)).isTrue(); ActionBar actionBar = mainActivity.getSupportActionBar(); assertThat(actionBar).isNotNull();// w w w .j av a 2 s . co m final FragmentManager sfm = mainActivity.getSupportFragmentManager(); runTestOnUiThread(new Runnable() { public void run() { sfm.executePendingTransactions(); } }); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_I); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_N); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_F); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_ENTER); runTestOnUiThread(new Runnable() { public void run() { sfm.executePendingTransactions(); } }); TitleSearchResultsActivity titleSearchResultsActivity = (TitleSearchResultsActivity) getInstrumentation() .waitForMonitorWithTimeout(am, 10000); assertThat(titleSearchResultsActivity).isNotNull(); assertThat(titleSearchResultsActivity.taskHandle).isNotNull(); synchronized (titleSearchResultsActivity.taskHandle) { titleSearchResultsActivity.taskHandle.wait(10000); } assertThat(titleSearchResultsActivity.taskHandle.getStatus()).isEqualTo(WorkStatus.FINISHED); SimpleCursorAdapter adapter = titleSearchResultsActivity.adapter; for (int i = 0; i < adapter.getCount(); i++) { Cursor cursor = (Cursor) adapter.getItem(i); int column = cursor.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_1); assertThat(INF_LIST[i]).isEqualTo(cursor.getString(column)); } }