/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.lifecycle;

import static androidx.lifecycle.TestUtils.OrderedTuples.CREATE;
import static androidx.lifecycle.TestUtils.OrderedTuples.DESTROY;
import static androidx.lifecycle.TestUtils.OrderedTuples.PAUSE;
import static androidx.lifecycle.TestUtils.OrderedTuples.RESUME;
import static androidx.lifecycle.TestUtils.OrderedTuples.START;
import static androidx.lifecycle.TestUtils.OrderedTuples.STOP;
import static androidx.lifecycle.TestUtils.flatMap;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import android.app.Activity;

import androidx.core.util.Pair;
import androidx.lifecycle.Lifecycle.Event;
import androidx.lifecycle.testapp.CollectingLifecycleOwner;
import androidx.lifecycle.testapp.CollectingSupportActivity;
import androidx.lifecycle.testapp.FrameworkLifecycleRegistryActivity;
import androidx.lifecycle.testapp.TestEvent;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.List;

@LargeTest
@RunWith(Parameterized.class)
public class ActivityFullLifecycleTest {
    @Rule
    public final ActivityTestRule<? extends CollectingLifecycleOwner> activityTestRule;

    @Parameterized.Parameters
    public static Class[] params() {
        return new Class[]{CollectingSupportActivity.class,
                FrameworkLifecycleRegistryActivity.class};
    }

    public ActivityFullLifecycleTest(Class<? extends Activity> activityClass) {
        //noinspection unchecked
        activityTestRule = new ActivityTestRule(activityClass);
    }


    @Test
    public void testFullLifecycle() throws Throwable {
        CollectingLifecycleOwner owner = activityTestRule.getActivity();
        TestUtils.waitTillResumed(owner, activityTestRule);
        activityTestRule.finishActivity();

        TestUtils.waitTillDestroyed(owner, activityTestRule);
        List<Pair<TestEvent, Event>> results = owner.copyCollectedEvents();
        assertThat(results, is(flatMap(CREATE, START, RESUME, PAUSE, STOP, DESTROY)));
    }
}

@@ -1543,94 +1543,75 @@
 est.
-filters.LargeTest;%0Aimport androidx.test.rule.ActivityTestRule;%0A%0Aimport org.junit.Rule;
+core.app.ActivityScenario;%0Aimport androidx.test.filters.LargeTest;%0A
 %0Aimp
@@ -1818,82 +1818,46 @@
     
-@Rule%0A    public final ActivityTestRule%3C? extends CollectingLifecycleOwner
+private final Class%3C? extends Activity
 %3E ac
@@ -1862,24 +1862,21 @@
 activity
-TestRule
+Class
 ;%0A%0A    @
@@ -2155,81 +2155,29 @@
     
-//noinspection unchecked%0A        activityTestRule = new ActivityTestRule(
+this.activityClass = 
 acti
@@ -2185,17 +2185,16 @@
 ityClass
-)
 ;%0A    %7D%0A
@@ -2244,25 +2244,8 @@
 le()
- throws Throwable
  %7B%0A 
@@ -2251,16 +2251,22 @@
         
+final 
 Collecti
@@ -2281,16 +2281,18 @@
 cleOwner
+%5B%5D
  owner =
@@ -2296,186 +2296,266 @@
 r = 
-activityTestRule.getActivity();%0A        TestUtils.waitTillResumed(owner, activityTestRule);%0A        activityTestRule.finishActivity();%0A%0A        TestUtils.waitTillDestroyed(o
+new CollectingLifecycleOwner%5B1%5D;%0A        try (ActivityScenario%3C? extends Activity%3E scenario =%0A                     ActivityScenario.launch(activityClass)) %7B%0A            scenario.onActivity(activity -%3E%0A                    owner%5B0%5D = (CollectingLifecycleO
 wner
-,
+)
  act
@@ -2563,18 +2563,21 @@
 vity
-TestRule);
+);%0A        %7D%0A
 %0A   
@@ -2625,16 +2625,19 @@
  = owner
+%5B0%5D
 .copyCol

Use ActivityScenario for ActivityFullLifecycleTest