Search in sources :

Example 1 with AndroidTestCase

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

the class AndroidObjectFactoryTest method injects_instrumentation_context_into_AndroidTestCase.

@Test
public void injects_instrumentation_context_into_AndroidTestCase() {
    // given
    final Class<?> androidTestCaseClass = AndroidTestCase.class;
    final AndroidTestCase androidTestCase = mock(AndroidTestCase.class);
    when(delegate.getInstance(androidTestCaseClass)).thenReturn(androidTestCase);
    final Context context = mock(Context.class);
    when(instrumentation.getTargetContext()).thenReturn(context);
    // when
    androidObjectFactory.getInstance(androidTestCaseClass);
    // then
    verify(androidTestCase).setContext(context);
}
Also used : Context(android.content.Context) AndroidTestCase(android.test.AndroidTestCase) Test(org.junit.Test)

Example 2 with AndroidTestCase

use of android.test.AndroidTestCase 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)

Aggregations

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