Files
app_Settings/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
Binyi Wu d43ecab8f7 Update survey triggering mechanisms
Settings will send the Settings screen to a central decision-making
place instead of each page handling its own.

Bug: 236662190
Test: robotest, manual

Change-Id: Ibfbdd421c723158d8d317aa4a02d9b51f877316a
2022-08-22 17:38:23 +08:00

53 lines
1.7 KiB
Java

package com.android.settings.survey;
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.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.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class SurveyMixinTest {
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);
}
@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);
mixin.onResume();
verify(mProvider, times(0)).sendActivityIfAvailable(FAKE_KEY);
}
}