Fix SurveyMixinTest

The test doesn't need to mock fragment at all, just need to pass in a fragment without activity.

Bug: 314929422

Test: atest
Change-Id: I9fb2f38c9c00109dd0d74c8f1e0d405022f634e3
diff --git a/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java b/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
index 635343e..c38e36a 100644
--- a/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
+++ b/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
@@ -2,53 +2,56 @@
 
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
 
-import android.content.Context;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.testing.FragmentScenario;
+import androidx.test.core.app.ApplicationProvider;
 
-import androidx.fragment.app.FragmentActivity;
-
-import com.android.settings.core.InstrumentedPreferenceFragment;
 import com.android.settings.overlay.SurveyFeatureProvider;
 import com.android.settings.testutils.FakeFeatureFactory;
 
 import org.junit.Before;
-import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.Robolectric;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
 import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
 
 @RunWith(RobolectricTestRunner.class)
 public class SurveyMixinTest {
+    @Rule
+    public final MockitoRule mMockitoRule = MockitoJUnit.rule();
 
     private static final String FAKE_KEY = "fake_key";
-
-    private Context mContext;
     private SurveyFeatureProvider mProvider;
-    @Mock
-    private InstrumentedPreferenceFragment mFragment;
 
     @Before
     public void setUp() {
         // set up the fakefeature factory to mock out the survey provider
-        MockitoAnnotations.initMocks(this);
-        mContext = RuntimeEnvironment.application;
-        mProvider = FakeFeatureFactory.setupForTest().getSurveyFeatureProvider(mContext);
+        mProvider = FakeFeatureFactory.setupForTest().getSurveyFeatureProvider(
+                ApplicationProvider.getApplicationContext());
     }
 
-    @Ignore("b/314929422")
     @Test
     public void onResume_noActionIfActivityDoesNotExist() {
-        // Pretend we are an activity that is starting up
-        FragmentActivity temp = Robolectric.setupActivity(FragmentActivity.class);
-        when(mFragment.getActivity()).thenReturn(null);
-        SurveyMixin mixin = new SurveyMixin(mFragment, FAKE_KEY);
+        // Initialize a fragment without associating with an activity
+        Fragment fragment = new Fragment();
+        SurveyMixin mixin = new SurveyMixin(fragment, FAKE_KEY);
         mixin.onResume();
 
         verify(mProvider, times(0)).sendActivityIfAvailable(FAKE_KEY);
     }
+
+    @Test
+    public void onResume_sendActivityWhenSurveyFeatureExists() {
+        try (var fragmentScenario = FragmentScenario.launch(Fragment.class)) {
+            fragmentScenario.onFragment(fragment -> {
+                SurveyMixin mixin = new SurveyMixin(fragment, FAKE_KEY);
+                mixin.onResume();
+            });
+        }
+        // Verify one send activity action is attempted
+        verify(mProvider).sendActivityIfAvailable(FAKE_KEY);
+    }
 }