Search in sources :

Example 1 with ActivityInstrumentationTestCase2

use of android.test.ActivityInstrumentationTestCase2 in project cucumber-jvm by cucumber.

the class AndroidObjectFactory method decorate.

private void decorate(final Object instance) {
    if (instance instanceof ActivityInstrumentationTestCase2) {
        final ActivityInstrumentationTestCase2 activityInstrumentationTestCase2 = (ActivityInstrumentationTestCase2) instance;
        activityInstrumentationTestCase2.injectInstrumentation(instrumentation);
        final Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        activityInstrumentationTestCase2.setActivityIntent(intent);
    } else if (instance instanceof InstrumentationTestCase) {
        ((InstrumentationTestCase) instance).injectInstrumentation(instrumentation);
    } else if (instance instanceof AndroidTestCase) {
        ((AndroidTestCase) instance).setContext(instrumentation.getTargetContext());
    }
}
Also used : ActivityInstrumentationTestCase2(android.test.ActivityInstrumentationTestCase2) InstrumentationTestCase(android.test.InstrumentationTestCase) AndroidTestCase(android.test.AndroidTestCase) Intent(android.content.Intent)

Example 2 with ActivityInstrumentationTestCase2

use of android.test.ActivityInstrumentationTestCase2 in project cucumber-jvm by cucumber.

the class AndroidObjectFactoryTest method sets_activity_intent_with_FLAG_ACTIVITY_CLEAR_TOP_to_prevent_stalling_when_calling_getActivity_if_the_activity_is_already_running.

@Test
public void sets_activity_intent_with_FLAG_ACTIVITY_CLEAR_TOP_to_prevent_stalling_when_calling_getActivity_if_the_activity_is_already_running() {
    // given
    final Class<?> activityInstrumentationTestCase2Class = ActivityInstrumentationTestCase2.class;
    final ActivityInstrumentationTestCase2 activityInstrumentationTestCase2 = mock(ActivityInstrumentationTestCase2.class);
    when(delegate.getInstance(activityInstrumentationTestCase2Class)).thenReturn(activityInstrumentationTestCase2);
    final Intent intent = new Intent().addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // when
    androidObjectFactory.getInstance(activityInstrumentationTestCase2Class);
    // then
    verify(activityInstrumentationTestCase2).setActivityIntent(intent);
}
Also used : ActivityInstrumentationTestCase2(android.test.ActivityInstrumentationTestCase2) Intent(android.content.Intent) Test(org.junit.Test)

Example 3 with ActivityInstrumentationTestCase2

use of android.test.ActivityInstrumentationTestCase2 in project cucumber-jvm by cucumber.

the class AndroidObjectFactoryTest method injects_instrumentation_into_ActivityInstrumentationTestCase2.

@Test
public void injects_instrumentation_into_ActivityInstrumentationTestCase2() {
    // given
    final Class<?> activityInstrumentationTestCase2Class = ActivityInstrumentationTestCase2.class;
    final ActivityInstrumentationTestCase2 activityInstrumentationTestCase2 = mock(ActivityInstrumentationTestCase2.class);
    when(delegate.getInstance(activityInstrumentationTestCase2Class)).thenReturn(activityInstrumentationTestCase2);
    // when
    androidObjectFactory.getInstance(activityInstrumentationTestCase2Class);
    // then
    verify(activityInstrumentationTestCase2).injectInstrumentation(instrumentation);
}
Also used : ActivityInstrumentationTestCase2(android.test.ActivityInstrumentationTestCase2) Test(org.junit.Test)

Aggregations

ActivityInstrumentationTestCase2 (android.test.ActivityInstrumentationTestCase2)3 Intent (android.content.Intent)2 Test (org.junit.Test)2 AndroidTestCase (android.test.AndroidTestCase)1 InstrumentationTestCase (android.test.InstrumentationTestCase)1