Make a strong reference to LifecycleOwner in tests

Change-Id: Id3b26ded6c903b67b9880dbfe1a0656a564c8947
Fixes: 71867776
Test: rerun tests
This commit is contained in:
Fan Zhang
2018-01-11 14:30:16 -08:00
parent 66898b0cc9
commit 4e08869e1a
45 changed files with 190 additions and 54 deletions

View File

@@ -21,6 +21,7 @@ import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
import android.arch.lifecycle.LifecycleOwner;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -56,6 +57,7 @@ public class AutoRotatePreferenceControllerTest {
private Context mContext;
@Mock
private PackageManager mPackageManager;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private SwitchPreference mPreference;
private ContentResolver mContentResolver;
@@ -66,7 +68,8 @@ public class AutoRotatePreferenceControllerTest {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest();
mContentResolver = RuntimeEnvironment.application.getContentResolver();
mLifecycle = new Lifecycle(() -> mLifecycle);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
mPreference = new SwitchPreference(RuntimeEnvironment.application);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getContentResolver()).thenReturn(mContentResolver);