Search in sources :

Example 6 with RobolectricPackageManager

use of org.robolectric.res.builder.RobolectricPackageManager in project materialistic by hidroh.

the class BaseListActivityTest method testSelectItemStartActionView.

@Test
public void testSelectItemStartActionView() {
    RobolectricPackageManager packageManager = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.browser", "DefaultActivity"));
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_external), true).commit();
    controller.pause().resume();
    activity.onItemSelected(new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
Also used : Intent(android.content.Intent) RobolectricPackageManager(org.robolectric.res.builder.RobolectricPackageManager) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 7 with RobolectricPackageManager

use of org.robolectric.res.builder.RobolectricPackageManager in project materialistic by hidroh.

the class BaseListActivityTest method testSelectItemOpenExternal.

@Test
public void testSelectItemOpenExternal() {
    RobolectricPackageManager packageManager = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_external), true).commit();
    controller.pause().resume();
    activity.onItemSelected(new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
Also used : Intent(android.content.Intent) RobolectricPackageManager(org.robolectric.res.builder.RobolectricPackageManager) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 8 with RobolectricPackageManager

use of org.robolectric.res.builder.RobolectricPackageManager in project materialistic by hidroh.

the class BaseListActivityTest method testSelectItemOpenChooser.

@Test
public void testSelectItemOpenChooser() {
    RobolectricPackageManager packageManager = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://news.ycombinator.com/item?id=1")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://news.ycombinator.com/item?id=1")), ShadowResolveInfo.newResolveInfo("label", "com.android.browser", "DefaultActivity"));
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_external), true).commit();
    controller.pause().resume();
    activity.onItemSelected(new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://news.ycombinator.com/item?id=1";
        }
    });
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_CHOOSER);
}
Also used : Intent(android.content.Intent) RobolectricPackageManager(org.robolectric.res.builder.RobolectricPackageManager) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 9 with RobolectricPackageManager

use of org.robolectric.res.builder.RobolectricPackageManager in project robolectric by robolectric.

the class RobolectricTestRunnerSelfTest method clearOrder.

@Before
public void clearOrder() {
    onTerminateCalledFromMain = null;
    order.clear();
    RobolectricPackageManager mockManager = mock(RobolectricPackageManager.class);
    doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            order.add("reset");
            return null;
        }
    }).when(mockManager).reset();
    RuntimeEnvironment.setRobolectricPackageManager(mockManager);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) RobolectricPackageManager(org.robolectric.res.builder.RobolectricPackageManager) Before(org.junit.Before)

Example 10 with RobolectricPackageManager

use of org.robolectric.res.builder.RobolectricPackageManager in project robolectric by robolectric.

the class ParallelUniverseTest method tearDownApplication_shouldNotResetPackageManager.

@Test
public void tearDownApplication_shouldNotResetPackageManager() {
    RobolectricPackageManager pm = mock(RobolectricPackageManager.class);
    RuntimeEnvironment.setRobolectricPackageManager(pm);
    pu.tearDownApplication();
    verify(pm, never()).reset();
}
Also used : RobolectricPackageManager(org.robolectric.res.builder.RobolectricPackageManager) Test(org.junit.Test)

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