@Before
    public void stubCameraIntent() {
        // Initializes Intents and begins recording intents.
        Intents.init();

        ActivityResult result = createImageCaptureActivityResultStub();

        // Stub the Intent.
        intending(hasAction(MediaStore.ACTION_IMAGE_CAPTURE)).respondWith(result);
    }
Use {@link ActivityScenarioRule} to create and launch the activity under test, and close it
after test completes. This is a replacement for {@link androidx.test.rule.ActivityTestRule}.
ui/espresso/IntentsAdvancedSample/app/src/androidTest/java/com/example/android/testing/espresso/intents/AdvancedSample/ImageViewerActivityTest.java