package com.android.settings.applications;
-import android.annotation.IdRes;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
-import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.support.v7.preference.Preference;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.ImageView;
import android.widget.TextView;
import com.android.settings.R;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.EnumSet;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AppHeaderControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mShadowContext = ShadowApplication.getInstance().getApplicationContext();
+ mShadowContext = RuntimeEnvironment.application;
+ when(mFragment.getContext()).thenReturn(mShadowContext);
mLayoutInflater = LayoutInflater.from(mShadowContext);
mInfo = new PackageInfo();
mInfo.versionName = "1234";
assertThat(label.getText()).isEqualTo(
appHeader.getResources().getString(R.string.install_type_instant));
}
+
+ @Test
+ public void initAppHeaderController_appHeaderNull_useFragmentContext() {
+ mController = new AppHeaderController(mContext, mFragment, null);
+
+ // Fragment.getContext() is invoked to inflate the view
+ verify(mFragment).getContext();
+ }
}
PreferenceManager mManager;
PreferenceScreen mScreen;
+ Context mShadowContext;
public TestFragment() {
mPm = mock(PackageManager.class);
mScreen = mock(PreferenceScreen.class);
mPackageInfo = new PackageInfo();
mPackageInfo.applicationInfo = new ApplicationInfo();
+ mShadowContext = ShadowApplication.getInstance().getApplicationContext();
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
(InstantAppDataProvider) (info -> false));
- when(mManager.getContext())
- .thenReturn(ShadowApplication.getInstance().getApplicationContext());
+ when(mManager.getContext()).thenReturn(mShadowContext);
}
@Override
public PreferenceManager getPreferenceManager() {
return mManager;
}
+
+ @Override
+ public Context getContext() {
+ return mShadowContext;
+ }
}
}