Example usage for android.app Instrumentation sendCharacterSync

List of usage examples for android.app Instrumentation sendCharacterSync

Introduction

In this page you can find the example usage for android.app Instrumentation sendCharacterSync.

Prototype

public void sendCharacterSync(int keyCode) 

Source Link

Document

Higher-level method for sending both the down and up key events for a particular character key code.

Usage

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();/*from  w  ww . ja  v  a2  s.com*/
    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));
    }
}