Search in sources :

Example 11 with RobolectricPackageManager

use of org.robolectric.res.builder.RobolectricPackageManager in project Parse-SDK-Android by ParsePlatform.

the class ParseInstallationTest method mocksForUpdateBeforeSave.

// TODO(mengyan): Add testFetchAsync, right now we can not test super methods inside
// testFetchAsync
private static void mocksForUpdateBeforeSave() {
    // Mock currentInstallationController to make setAsync work
    ParseCurrentInstallationController controller = mock(ParseCurrentInstallationController.class);
    when(controller.isCurrent(any(ParseInstallation.class))).thenReturn(true);
    ParseCorePlugins.getInstance().registerCurrentInstallationController(controller);
    // Mock package manager
    RobolectricPackageManager packageManager = spy(RuntimeEnvironment.getRobolectricPackageManager());
    doReturn("parseTest").when(packageManager).getApplicationLabel(any(ApplicationInfo.class));
    RuntimeEnvironment.setRobolectricPackageManager(packageManager);
    ParsePlugins.Android plugins = mock(ParsePlugins.Android.class);
    // Mock installationId
    InstallationId installationId = mock(InstallationId.class);
    when(installationId.get()).thenReturn("installationId");
    when(plugins.installationId()).thenReturn(installationId);
    // Mock application context
    when(plugins.applicationContext()).thenReturn(RuntimeEnvironment.application);
    ParsePlugins.set(plugins);
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RobolectricPackageManager(org.robolectric.res.builder.RobolectricPackageManager)

Aggregations

RobolectricPackageManager (org.robolectric.res.builder.RobolectricPackageManager)11 Test (org.junit.Test)7 Intent (android.content.Intent)5 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)4 ApplicationInfo (android.content.pm.ApplicationInfo)3 TestWebItem (io.github.hidroh.materialistic.test.TestWebItem)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Before (org.junit.Before)2 SuppressLint (android.annotation.SuppressLint)1 ActivityInfo (android.content.pm.ActivityInfo)1 ResolveInfo (android.content.pm.ResolveInfo)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 ViewGroup (android.view.ViewGroup)1 WebView (android.webkit.WebView)1 ImageView (android.widget.ImageView)1 Lifecycle (com.bumptech.glide.manager.Lifecycle)1 RequestManagerTreeNode (com.bumptech.glide.manager.RequestManagerTreeNode)1 SizeReadyCallback (com.bumptech.glide.request.target.SizeReadyCallback)1