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

@@ -22,6 +22,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.provider.Settings;
@@ -54,6 +55,7 @@ public class LocationSwitchBarControllerTest {
private Context mContext;
private LocationSwitchBarController mController;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
@@ -61,7 +63,8 @@ public class LocationSwitchBarControllerTest {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
ReflectionHelpers.setField(mSwitchBar, "mSwitch", mSwitch);
mLifecycle = new Lifecycle(() -> mLifecycle);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new LocationSwitchBarController(
mContext, mSwitchBar, mLifecycle));
ReflectionHelpers.setField(mController, "mLocationEnabler", mEnabler);