当前位置: 首页>>代码示例>>Java>>正文


Java RobolectricPackageManager类代码示例

本文整理汇总了Java中org.robolectric.res.builder.RobolectricPackageManager的典型用法代码示例。如果您正苦于以下问题:Java RobolectricPackageManager类的具体用法?Java RobolectricPackageManager怎么用?Java RobolectricPackageManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RobolectricPackageManager类属于org.robolectric.res.builder包,在下文中一共展示了RobolectricPackageManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  Glide.tearDown();

  RobolectricPackageManager pm = RuntimeEnvironment.getRobolectricPackageManager();
  ApplicationInfo info =
      pm.getApplicationInfo(RuntimeEnvironment.application.getPackageName(), 0);
  info.metaData = new Bundle();
  info.metaData.putString(SetupModule.class.getName(), "GlideModule");

  // Ensure that target's size ready callback will be called synchronously.
  target = mock(Target.class);
  imageView = new ImageView(RuntimeEnvironment.application);
  imageView.setLayoutParams(new ViewGroup.LayoutParams(100, 100));
  imageView.layout(0, 0, 100, 100);
  doAnswer(new CallSizeReady()).when(target).getSize(isA(SizeReadyCallback.class));

  Handler bgHandler = mock(Handler.class);
  when(bgHandler.post(isA(Runnable.class))).thenAnswer(new Answer<Boolean>() {
    @Override
    public Boolean answer(InvocationOnMock invocation) throws Throwable {
      Runnable runnable = (Runnable) invocation.getArguments()[0];
      runnable.run();
      return true;
    }
  });

  Lifecycle lifecycle = mock(Lifecycle.class);
  RequestManagerTreeNode treeNode = mock(RequestManagerTreeNode.class);
  requestManager = new RequestManager(Glide.get(getContext()), lifecycle, treeNode);
  requestManager.resumeRequests();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:GlideTest.java

示例2: registerMediaStoreIntentHandler

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
/**
 * Register a handler in the package manager for a image capture intent
 */
private void registerMediaStoreIntentHandler()
{
    // Add something that will 'handle' the media capture intent
    RobolectricPackageManager packageManager = shadowOf(RuntimeEnvironment.application.getPackageManager());

    ResolveInfo info = new ResolveInfo();
    info.isDefault = true;

    ApplicationInfo applicationInfo = new ApplicationInfo();
    applicationInfo.packageName = "does.not.matter";
    info.activityInfo = new ActivityInfo();
    info.activityInfo.applicationInfo = applicationInfo;
    info.activityInfo.name = "DoesNotMatter";

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    packageManager.addResolveInfoForIntent(intent, info);
}
 
开发者ID:brarcher,项目名称:gift-card-guard,代码行数:22,代码来源:GiftCardViewActivityTest.java

示例3: should_start_url_intent

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
@Test
public void should_start_url_intent() {
    // Given
    String url = "geo:22.5430883,114.1043205";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), ShadowResolveInfo.newResolveInfo("", "", ""));

    // When
    boolean result = Intents.startUri(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(result).isTrue();
    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData().toString()).isEqualTo(url);
}
 
开发者ID:Nilhcem,项目名称:droidconde-2016,代码行数:19,代码来源:IntentsTest.java

示例4: should_return_false_when_nothing_on_the_device_can_open_the_uri

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
@Test
public void should_return_false_when_nothing_on_the_device_can_open_the_uri() {
    // Given
    String url = "http://www.google.com";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), (ResolveInfo) null);

    // When
    boolean result = Intents.startUri(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(result).isFalse();
    assertThat(startedIntent).isNull();
}
 
开发者ID:Nilhcem,项目名称:droidconde-2016,代码行数:18,代码来源:IntentsTest.java

示例5: should_start_external_uri

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
@Test
public void should_start_external_uri() {
    // Given
    String url = "http://www.google.com";
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), ShadowResolveInfo.newResolveInfo("", "", ""));

    // When
    Intents.startExternalUrl(activity, url);

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData().toString()).isEqualTo(url);
}
 
开发者ID:Nilhcem,项目名称:droidconde-2016,代码行数:18,代码来源:IntentsTest.java

示例6: registerIntentHandler

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
private void registerIntentHandler(String handler)
{
    // Add something that will 'handle' the given intent type
    RobolectricPackageManager packageManager = shadowOf(RuntimeEnvironment.application.getPackageManager());

    ResolveInfo info = new ResolveInfo();
    info.isDefault = true;

    ApplicationInfo applicationInfo = new ApplicationInfo();
    applicationInfo.packageName = "does.not.matter";
    info.activityInfo = new ActivityInfo();
    info.activityInfo.applicationInfo = applicationInfo;
    info.activityInfo.name = "DoesNotMatter";
    info.activityInfo.exported = true;

    Intent intent = new Intent(handler);

    if(handler.equals(Intent.ACTION_GET_CONTENT))
    {
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
    }

    packageManager.addResolveInfoForIntent(intent, info);
}
 
开发者ID:brarcher,项目名称:loyalty-card-locker,代码行数:26,代码来源:ImportExportActivityTest.java

示例7: registerMediaStoreIntentHandler

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
/**
 * Register a handler in the package manager for a image capture intent
 */
private void registerMediaStoreIntentHandler()
{
    // Add something that will 'handle' the media capture intent
    RobolectricPackageManager packageManager = shadowOf(RuntimeEnvironment.application.getPackageManager());

    ResolveInfo info = new ResolveInfo();
    info.isDefault = true;

    ApplicationInfo applicationInfo = new ApplicationInfo();
    applicationInfo.packageName = "does.not.matter";
    info.activityInfo = new ActivityInfo();
    info.activityInfo.applicationInfo = applicationInfo;
    info.activityInfo.name = "DoesNotMatter";

    Intent intent = new Intent(Intents.Scan.ACTION);

    packageManager.addResolveInfoForIntent(intent, info);
}
 
开发者ID:brarcher,项目名称:loyalty-card-locker,代码行数:22,代码来源:LoyaltyCardViewActivityTest.java

示例8: testDownloadContent

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
@Test
public void testDownloadContent() {
    ResolveInfo resolverInfo = new ResolveInfo();
    resolverInfo.activityInfo = new ActivityInfo();
    resolverInfo.activityInfo.applicationInfo = new ApplicationInfo();
    resolverInfo.activityInfo.applicationInfo.packageName =
            ListActivity.class.getPackage().getName();
    resolverInfo.activityInfo.name = ListActivity.class.getName();
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    final String url = "http://example.com/file.doc";
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), resolverInfo);

    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(webView);
    when(item.getUrl()).thenReturn(url);
    shadowWebView.getDownloadListener().onDownloadStart(url, "", "", "", 0l);
    assertThat((View) activity.findViewById(R.id.empty)).isVisible();
    activity.findViewById(R.id.download_button).performClick();
    assertNotNull(shadowOf(activity).getNextStartedActivity());
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:21,代码来源:WebFragmentTest.java

示例9: testDownloadPdf

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
@Test
public void testDownloadPdf() throws InterruptedException {
    ResolveInfo resolverInfo = new ResolveInfo();
    resolverInfo.activityInfo = new ActivityInfo();
    resolverInfo.activityInfo.applicationInfo = new ApplicationInfo();
    resolverInfo.activityInfo.applicationInfo.packageName = ListActivity.class.getPackage().getName();
    resolverInfo.activityInfo.name = ListActivity.class.getName();
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    when(item.getUrl()).thenReturn("http://example.com/file.pdf");
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(item.getUrl())), resolverInfo);

    WebView webView = activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(webView);
    WebFragment fragment = (WebFragment) activity.getSupportFragmentManager()
            .findFragmentByTag(WebFragment.class.getName());
    shadowWebView.getDownloadListener().onDownloadStart(item.getUrl(), "", "", "application/pdf", 0l);
    shadowWebView.getWebViewClient().onPageFinished(webView, PDF_LOADER_URL);
    verify(fragment.mFileDownloader).downloadFile(
        eq(item.getUrl()),
        eq("application/pdf"),
        any(FileDownloader.FileDownloaderCallback.class));
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:23,代码来源:WebFragmentTest.java

示例10: testSelectItemOpenExternal

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
@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);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:22,代码来源:BaseListActivityTest.java

示例11: testSelectItemStartActionView

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
@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);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:26,代码来源:BaseListActivityTest.java

示例12: testSelectItemOpenChooser

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
@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);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:26,代码来源:BaseListActivityTest.java

示例13: execute_whenUberAppInsalled_shouldPointToUberApp

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
@Test
public void execute_whenUberAppInsalled_shouldPointToUberApp() throws IOException {
    String expectedUri = readUriResourceWithUserAgentParam("src/test/resources/deeplinkuris/just_client_provided",
            USER_AGENT_DEEPLINK);

    Activity activity = Robolectric.setupActivity(Activity.class);
    ShadowActivity shadowActivity = shadowOf(activity);

    RobolectricPackageManager packageManager = RuntimeEnvironment.getRobolectricPackageManager();

    PackageInfo uberPackage = new PackageInfo();
    uberPackage.packageName = UBER_PACKAGE_NAME;
    packageManager.addPackage(uberPackage);

    RideParameters rideParameters = new RideParameters.Builder().build();

    RequestDeeplink requestDeeplink = new RequestDeeplink.Builder(activity)
            .setRideParameters(rideParameters)
            .setSessionConfiguration(new SessionConfiguration.Builder().setClientId("clientId").build())
            .build();

    requestDeeplink.execute();

    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertEquals(expectedUri, startedIntent.getData().toString());
}
 
开发者ID:uber,项目名称:rides-android-sdk,代码行数:27,代码来源:RequestDeeplinkTest.java

示例14: testAfterUpdateEvent

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
@Test
public void testAfterUpdateEvent() throws PackageManager.NameNotFoundException {
    Context context = RuntimeEnvironment.application;

    AfterUpdateEvent event = timeToAct.watchEvent(new AfterUpdateEvent(context, KEY));
    assertFalse(event.isHappened());

    RobolectricPackageManager packageManager = RuntimeEnvironment.getRobolectricPackageManager();
    packageManager.getPackageInfo(context.getPackageName(), 0).versionCode++;

    timeToAct.forceWatchEvent(event); // reinitialize
    assertTrue(event.isHappened());
}
 
开发者ID:seroperson,项目名称:itstimetoact,代码行数:14,代码来源:ExtrasTest.java

示例15: simulateAppUpdate

import org.robolectric.res.builder.RobolectricPackageManager; //导入依赖的package包/类
static void simulateAppUpdate() {
    RobolectricPackageManager rpm = RuntimeEnvironment.getRobolectricPackageManager();
    PackageInfo packageInfo = new PackageInfo();
    packageInfo.packageName = RuntimeEnvironment.application.getPackageName();
    packageInfo.lastUpdateTime = new Date().getTime();
    rpm.addPackage(packageInfo);
    Once.initialise(RuntimeEnvironment.application);
}
 
开发者ID:jonfinerty,项目名称:Once,代码行数:9,代码来源:TestUtils.java


注:本文中的org.robolectric.res.builder.RobolectricPackageManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。