當前位置: 首頁>>代碼示例>>Java>>正文


Java RuntimeEnvironment類代碼示例

本文整理匯總了Java中org.robolectric.RuntimeEnvironment的典型用法代碼示例。如果您正苦於以下問題:Java RuntimeEnvironment類的具體用法?Java RuntimeEnvironment怎麽用?Java RuntimeEnvironment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RuntimeEnvironment類屬於org.robolectric包,在下文中一共展示了RuntimeEnvironment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: migratePgpInlineEncryptedMessage

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Test
public void migratePgpInlineEncryptedMessage() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertPgpInlineEncryptedMessage(db);
    db.close();

    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);

    LocalMessage msg = localStore.getFolder("dev").getMessage("7");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);

    Assert.assertEquals(6, msg.getDatabaseId());
    Assert.assertEquals(12, msg.getHeaderNames().size());
    Assert.assertEquals("text/plain", msg.getMimeType());
    Assert.assertEquals(0, msg.getAttachmentCount());
    Assert.assertTrue(msg.getBody() instanceof BinaryMemoryBody);

    String msgTextContent = MessageExtractor.getTextFromPart(msg);
    Assert.assertEquals(OpenPgpUtils.PARSE_RESULT_MESSAGE, OpenPgpUtils.parseMessage(msgTextContent));
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:23,代碼來源:MigrationTest.java

示例2: migrateTextHtml

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Test
public void migrateTextHtml() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertMultipartAlternativeMessage(db);
    db.close();

    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);

    LocalMessage msg = localStore.getFolder("dev").getMessage("9");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);

    Assert.assertEquals(8, msg.getDatabaseId());
    Assert.assertEquals(9, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/alternative", msg.getMimeType());
    Assert.assertEquals(0, msg.getAttachmentCount());

    Multipart msgBody = (Multipart) msg.getBody();
    Assert.assertEquals("------------060200010509000000040004", msgBody.getBoundary());
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:22,代碼來源:MigrationTest.java

示例3: check

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
/**
 * Verify assets can be read with robolectric.
 *
 * @throws IOException if failed.
 */
@Test
public void check() throws IOException {
    final InputStream s = RuntimeEnvironment.application.getAssets()
        .open(new File("check.txt").getPath());
    Assert.assertNotNull(s);
    try {
        MatcherAssert.assertThat(
            IOUtils.toString(s),
            Matchers.equalTo("check")
        );
    } finally {
        //noinspection ThrowFromFinallyBlock
        s.close();
    }
}
 
開發者ID:g4s8,項目名稱:Android-Migrator,代碼行數:21,代碼來源:AssetsTest.java

示例4: testGetProxiedUrlForPartialCache

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Test
public void testGetProxiedUrlForPartialCache() throws Exception {
    File cacheDir = RuntimeEnvironment.application.getExternalCacheDir();
    File file = new File(cacheDir, new Md5FileNameGenerator().generate(HTTP_DATA_URL));
    int partialCacheSize = 1000;
    byte[] partialData = ProxyCacheTestUtils.generate(partialCacheSize);
    File partialCacheFile = ProxyCacheTestUtils.getTempFile(file);
    IoUtils.saveToFile(partialData, partialCacheFile);

    HttpProxyCacheServer proxy = newProxy(cacheFolder);
    String expectedUrl = "http://127.0.0.1:" + getPort(proxy) + "/" + ProxyCacheUtils.encode(HTTP_DATA_URL);

    assertThat(proxy.getProxyUrl(HTTP_DATA_URL)).isEqualTo(expectedUrl);
    assertThat(proxy.getProxyUrl(HTTP_DATA_URL, true)).isEqualTo(expectedUrl);
    assertThat(proxy.getProxyUrl(HTTP_DATA_URL, false)).isEqualTo(expectedUrl);

    proxy.shutdown();
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:19,代碼來源:HttpProxyCacheServerTest.java

示例5: testReuseSourceInfo

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Test
public void testReuseSourceInfo() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    File cacheFile = newCacheFile();
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(cacheFile));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");

    HttpUrlSource notOpenableSource = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache2 = new HttpProxyCache(notOpenableSource, new FileCache(cacheFile));
    Response response = processRequest(proxyCache2, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();

    assertThat(response.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
    assertThat(response.contentLength).isEqualTo(HTTP_DATA_SIZE);
    assertThat(response.contentType).isEqualTo("image/jpeg");
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:18,代碼來源:HttpProxyCacheTest.java

示例6: create_with_custom_sharables

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Test
public void create_with_custom_sharables() {
    final List<Shareable> shareables = Stream.generate(() -> mock(Shareable.class)).limit(2)
            .collect(Collectors.toList());

    final PhialBuilder builder = new PhialBuilder(RuntimeEnvironment.application);
    shareables.forEach(builder::addShareable);

    final PhialCore phialCore = PhialCore.create(builder);
    final List<Shareable> createdShareables = phialCore.getShareManager()
            .getUserShareItems()
            .stream()
            .map(item -> (UserShareItem) item)
            .map(UserShareItem::getShareable)
            .collect(Collectors.toList());

    assertEquals(shareables, createdShareables);
}
 
開發者ID:roshakorost,項目名稱:Phial,代碼行數:19,代碼來源:PhialCoreTest.java

示例7: setUp

import org.robolectric.RuntimeEnvironment; //導入依賴的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

示例8: createIntentForAction_matchingPackage

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Test
public void createIntentForAction_matchingPackage() {
    shadowPackageManager.addResolveInfoForIntent(
            saveIntent,
            createResolveInfo(EXAMPLE_PROVIDER_PACKAGE, EXAMPLE_PROVIDER_ACTIVITY_CLASS));

    Intent intentForAction = ProviderResolver.createIntentForAction(
            RuntimeEnvironment.application,
            EXAMPLE_PROVIDER_PACKAGE,
            ProtocolConstants.SAVE_CREDENTIAL_ACTION);

    assertThat(intentForAction).isNotNull();
    assertThat(intentForAction.getAction())
            .isEqualTo(ProtocolConstants.SAVE_CREDENTIAL_ACTION);
    assertThat(intentForAction.getCategories())
            .containsExactly(ProtocolConstants.OPENYOLO_CATEGORY);
    assertThat(intentForAction.getComponent()).isNotNull();
    assertThat(intentForAction.getComponent().getPackageName())
            .isEqualTo(EXAMPLE_PROVIDER_PACKAGE);
    assertThat(intentForAction.getComponent().getClassName())
            .isEqualTo(EXAMPLE_PROVIDER_ACTIVITY_CLASS);
}
 
開發者ID:openid,項目名稱:OpenYOLO-Android,代碼行數:23,代碼來源:ProviderResolverTest.java

示例9: testCustomTabIntent

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Test
public void testCustomTabIntent() {
    final SessionManager sessionManager = SessionManager.getInstance();

    final SafeIntent intent = new SafeIntent(new CustomTabsIntent.Builder()
            .setToolbarColor(Color.GREEN)
            .addDefaultShareMenuItem()
            .build()
            .intent
            .setData(Uri.parse(TEST_URL)));

    sessionManager.handleIntent(RuntimeEnvironment.application, intent, null);

    final List<Session> sessions = sessionManager.getSessions().getValue();
    assertNotNull(sessions);
    assertEquals(1, sessions.size());

    final Session session = sessions.get(0);
    assertEquals(TEST_URL, session.getUrl().getValue());

    assertTrue(sessionManager.hasSession());
}
 
開發者ID:mozilla-mobile,項目名稱:firefox-tv,代碼行數:23,代碼來源:SessionManagerTest.java

示例10: testHandlesPaths

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Test
public void testHandlesPaths() throws IOException {
  // TODO on windows it will fail with schema being the drive letter (C:\... -> C)
  assumeTrue(!Util.isWindows());

  File f = RuntimeEnvironment.application.getCacheDir();
  Uri expected = Uri.fromFile(f);
  when(uriLoader.buildLoadData(eq(expected), eq(IMAGE_SIDE), eq(IMAGE_SIDE), eq(options)))
      .thenReturn(new ModelLoader.LoadData<>(key, fetcher));

  assertTrue(loader.handles(f.getAbsolutePath()));
  assertEquals(
      fetcher,
      Preconditions.checkNotNull(
          loader.buildLoadData(f.getAbsolutePath(), IMAGE_SIDE, IMAGE_SIDE, options)).fetcher);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:StringLoaderTest.java

示例11: testDispatchDraw

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Test
public void testDispatchDraw(){

    Canvas canvas = Mockito.mock(Canvas.class);
    ShadowSelectorView view = new ShadowSelectorView(RuntimeEnvironment.application);
    view.setIndicatorPoint(new PointF(0, 0));
    view.setSelectorCircleSize(20);
    view.triggerOnLayout(true, 0, 0, 500, 500);
    view.triggerDispatchDraw(canvas);

    final ArgumentCaptor<Paint> captor = ArgumentCaptor.forClass(Paint.class);

    verify(canvas).drawCircle(eq(0f), eq(0f), eq(20f), captor.capture());

    Paint paint = captor.getValue();
    Assert.assertEquals(Color.LTGRAY, paint.getColor());
    verify(canvas).drawLine(eq(0f), eq(0f), eq(250f), eq(250f), captor.capture());

}
 
開發者ID:Kaufland,項目名稱:andcircularselect,代碼行數:20,代碼來源:SelectorViewTest.java

示例12: setUp

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);
  options = new Options();
  DisplayMetrics displayMetrics =
      RuntimeEnvironment.application.getResources().getDisplayMetrics();
  when(byteArrayPool.get(anyInt(), Matchers.eq(byte[].class)))
      .thenReturn(new byte[ArrayPool.STANDARD_BUFFER_SIZE_BYTES]);

  List<ImageHeaderParser> parsers = new ArrayList<ImageHeaderParser>();
  parsers.add(new DefaultImageHeaderParser());

  downsampler = new Downsampler(parsers, displayMetrics, bitmapPool, byteArrayPool);

  initialSdkVersion = Build.VERSION.SDK_INT;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:DownsamplerTest.java

示例13: testReturnsOpenedInputStreamWhenFileFound

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Test
public void testReturnsOpenedInputStreamWhenFileFound() throws FileNotFoundException {
  InputStream expected = new ByteArrayInputStream(new byte[0]);
  Shadows.shadowOf(RuntimeEnvironment.application.getContentResolver())
      .registerInputStream(harness.uri, expected);
  assertEquals(expected, harness.get().open(harness.uri));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:ThumbnailStreamOpenerTest.java

示例14: setUp

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  context = RuntimeEnvironment.application;
  connectivityMonitor = mock(ConnectivityMonitor.class);
  ConnectivityMonitorFactory factory = mock(ConnectivityMonitorFactory.class);
  when(factory.build(isA(Context.class), isA(ConnectivityMonitor.ConnectivityListener.class)))
      .thenAnswer(new Answer<ConnectivityMonitor>() {
        @Override
        public ConnectivityMonitor answer(InvocationOnMock invocation) throws Throwable {
          connectivityListener = (ConnectivityListener) invocation.getArguments()[1];
          return connectivityMonitor;
        }
      });

   target = new BaseTarget<Drawable>() {
     @Override
     public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
       // Empty.
     }
     @Override
     public void getSize(SizeReadyCallback cb) {
       // Empty.
     }
     @Override
     public void removeCallback(SizeReadyCallback cb) {
       // Empty.
     }
  };

  requestTracker = mock(RequestTracker.class);
  manager =
      new RequestManager(
          Glide.get(RuntimeEnvironment.application),
          lifecycle,
          treeNode,
          requestTracker,
          factory,
          context);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:41,代碼來源:RequestManagerTest.java

示例15: testDoesNotWorkWithoutCustomProxySelector

import org.robolectric.RuntimeEnvironment; //導入依賴的package包/類
@Test // https://github.com/danikula/AndroidVideoCache/issues/28
public void testDoesNotWorkWithoutCustomProxySelector() throws Exception {
    HttpProxyCacheServer httpProxyCacheServer = new HttpProxyCacheServer(RuntimeEnvironment.application);
    // IgnoreHostProxySelector is set in HttpProxyCacheServer constructor. So let reset it by custom.
    installExternalSystemProxy();

    String proxiedUrl = httpProxyCacheServer.getProxyUrl(HTTP_DATA_URL);
    // server can't proxy this url due to it is not alive (can't ping itself), so it returns original url
    assertThat(proxiedUrl).isEqualTo(HTTP_DATA_URL);
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:11,代碼來源:HttpProxyCacheServerTest.java


注:本文中的org.robolectric.RuntimeEnvironment類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。