Java 类org.robolectric.RuntimeEnvironment 实例源码

项目:q-mail    文件:MigrationTest.java   
@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));
}
项目:q-mail    文件:MigrationTest.java   
@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());
}
项目:Android-Migrator    文件:AssetsTest.java   
/**
 * 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();
    }
}
项目:AndroidVideoCache    文件:HttpProxyCacheServerTest.java   
@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();
}
项目:AndroidVideoCache    文件:HttpProxyCacheTest.java   
@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");
}
项目:Phial    文件:PhialCoreTest.java   
@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);
}
项目:GitHub    文件:GlideTest.java   
@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();
}
项目:OpenYOLO-Android    文件:ProviderResolverTest.java   
@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);
}
项目:firefox-tv    文件:SessionManagerTest.java   
@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());
}
项目:GitHub    文件:StringLoaderTest.java   
@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);
}
项目:andcircularselect    文件:SelectorViewTest.java   
@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());

}
项目:GitHub    文件:DownsamplerTest.java   
@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;
}
项目:GitHub    文件:ThumbnailStreamOpenerTest.java   
@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));
}
项目:GitHub    文件:RequestManagerTest.java   
@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);
}
项目:AndroidVideoCache    文件:HttpProxyCacheServerTest.java   
@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);
}
项目:GitHub    文件:MemorySizeCalculatorTest.java   
MemorySizeCalculator getCalculator() {
  when(screenDimensions.getWidthPixels()).thenReturn(pixelSize);
  when(screenDimensions.getHeightPixels()).thenReturn(pixelSize);
  return new MemorySizeCalculator.Builder(RuntimeEnvironment.application)
      .setMemoryCacheScreens(memoryCacheScreens)
      .setBitmapPoolScreens(bitmapPoolScreens)
      .setMaxSizeMultiplier(sizeMultiplier)
      .setActivityManager(activityManager)
      .setScreenDimensions(screenDimensions)
      .setArrayPoolSize(byteArrayPoolSizeBytes)
      .build();
}
项目:q-mail    文件:MessageViewInfoExtractorTest.java   
@Before
public void setUp() throws Exception {
    context = RuntimeEnvironment.application;

    GlobalsHelper.setContext(context);

    HtmlProcessor htmlProcessor = createFakeHtmlProcessor();
    attachmentInfoExtractor = spy(AttachmentInfoExtractor.getInstance());
    iCalendarInfoExtractor = spy(ICalendarInfoExtractor.getInstance());
    messageViewInfoExtractor = new MessageViewInfoExtractor(context, attachmentInfoExtractor,
            iCalendarInfoExtractor, htmlProcessor);
}
项目:q-mail    文件:MigrationTest.java   
@Test
public void migrateTextPlain() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertSimplePlaintextMessage(db);
    db.close();

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

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

    Assert.assertEquals("text/plain", msg.getMimeType());
    Assert.assertEquals(2, msg.getDatabaseId());
    Assert.assertEquals(13, msg.getHeaderNames().size());
    Assert.assertEquals(0, msg.getAttachmentCount());

    Assert.assertEquals(1, msg.getHeader("User-Agent").length);
    Assert.assertEquals("Mutt/1.5.24 (2015-08-30)", msg.getHeader("User-Agent")[0]);
    Assert.assertEquals(1, msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE).length);
    Assert.assertEquals("text/plain",
            MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], null));
    Assert.assertEquals("utf-8",
            MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], "charset"));

    Assert.assertTrue(msg.getBody() instanceof BinaryMemoryBody);

    String msgTextContent = MessageExtractor.getTextFromPart(msg);
    Assert.assertEquals("nothing special here.\r\n", msgTextContent);
}
项目:weex-uikit    文件:WXEmbedTest.java   
@Before
public void setUp() throws Exception {

  WXEnvironment.sApplication = RuntimeEnvironment.application;
  WXDiv div = WXDivTest.create();
  ComponentTest.create(div);
  component = new WXEmbed(div.getInstance(),new TestDomObject(),div);
  ComponentTest.create(component);
  component.getDomObject().getStyles().put(Constants.Name.VISIBILITY, Constants.Value.VISIBLE);
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
/**
 * Assuming no other views have been created, the root view will have tag 1, Text tag 2, and
 * RawText tag 3.
 */
private ViewGroup createSimpleTextHierarchy(UIManagerModule uiManager, String text) {
  ReactRootView rootView =
      new ReactRootView(RuntimeEnvironment.application.getApplicationContext());
  int rootTag = uiManager.addMeasuredRootView(rootView);
  int textTag = rootTag + 1;
  int rawTextTag = textTag + 1;

  uiManager.createView(
      textTag,
      ReactTextViewManager.REACT_CLASS,
      rootTag,
      JavaOnlyMap.of("collapsable", false));
  uiManager.createView(
      rawTextTag,
      ReactRawTextManager.REACT_CLASS,
      rootTag,
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, text, "collapsable", false));

  uiManager.manageChildren(
      textTag,
      null,
      null,
      JavaOnlyArray.of(rawTextTag),
      JavaOnlyArray.of(0),
      null);

  uiManager.manageChildren(
      rootTag,
      null,
      null,
      JavaOnlyArray.of(textTag),
      JavaOnlyArray.of(0),
      null);

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();

  return rootView;
}
项目:weex-uikit    文件:WXBridgeManagerTest.java   
@Before
public void setUp() throws Exception {
  WXSDKEngine.initialize(RuntimeEnvironment.application,new InitConfig.Builder().build());
  instance = WXSDKInstanceTest.createInstance();
  WXRenderManager rednerManager = new WXRenderManager();
  rednerManager.registerInstance(instance);//
  WXSDKManagerTest.setRenderManager(rednerManager);
}
项目:Phial    文件:PhialCoreTest.java   
@Test
public void create_with_custom_attachers() {
    final PhialBuilder builder = new PhialBuilder(RuntimeEnvironment.application);
    builder.attachKeyValues(false).attachScreenshot(false);

    final List<ListAttacher> attachers = Stream.generate(() -> mock(ListAttacher.class)).limit(2)
            .collect(Collectors.toList());
    attachers.forEach(builder::addAttachmentProvider);

    final PhialCore phialCore = PhialCore.create(builder);
    assertEquals(attachers, phialCore.getAttachmentManager().getProviders());
}
项目:RNLearn_Project1    文件:SimpleViewPropertyTest.java   
@Before
public void setup() {
  mContext = new ReactApplicationContext(RuntimeEnvironment.application);
  mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
  mContext.initializeWithInstance(mCatalystInstanceMock);
  mThemedContext = new ThemedReactContext(mContext, mContext);
  mManager = new ConcreteViewManager();
}
项目:q-mail    文件:SettingsImporterTest.java   
@Test(expected = SettingsImportExportException.class)
public void importSettings_throwsExceptionOnBlankFile() throws SettingsImportExportException {
    InputStream inputStream = new StringInputStream("");
    List<String> accountUuids = new ArrayList<>();

    SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true);
}
项目:GitHub    文件:RequestCreatorTest.java   
@Test
public void intoImageViewSetsPlaceholderDrawable() {
  Picasso picasso =
      spy(new Picasso(RuntimeEnvironment.application, mock(Dispatcher.class), Cache.NONE, null,
          IDENTITY, null, mock(Stats.class), ARGB_8888, false, false));
  ImageView target = mockImageViewTarget();
  Drawable placeHolderDrawable = mock(Drawable.class);
  new RequestCreator(picasso, URI_1, 0).placeholder(placeHolderDrawable).into(target);
  verify(target).setImageDrawable(placeHolderDrawable);
  verify(picasso).enqueueAndSubmit(actionCaptor.capture());
  assertThat(actionCaptor.getValue()).isInstanceOf(ImageViewAction.class);
}
项目:q-mail    文件:SettingsImporterTest.java   
@Test(expected = SettingsImportExportException.class)
public void importSettings_throwsExceptionOnInvalidVersion() throws SettingsImportExportException {
    InputStream inputStream = new StringInputStream("<k9settings format=\"1\" version=\"A\"></k9settings>");
    List<String> accountUuids = new ArrayList<>();

    SettingsImporter.importSettings(RuntimeEnvironment.application, inputStream, true, accountUuids, true);
}
项目:weex-3d-map    文件:DefaultWXStorageTest.java   
@Before
public void setup() throws Exception{
  supplier = Mockito.mock(WXSQLiteOpenHelper.class);
  listener = Mockito.mock(IWXStorageAdapter.OnResultReceivedListener.class);
  storage = new DefaultWXStorage(RuntimeEnvironment.application);

  mockStatic(WXSQLiteOpenHelper.class);
  PowerMockito.whenNew(WXSQLiteOpenHelper.class)
          .withArguments(RuntimeEnvironment.application)
          .thenReturn(supplier);
}
项目:RNLearn_Project1    文件:TextInputTest.java   
@Test
public void testPropsApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application);
  rootView.setLayoutParams(new ReactRootView.LayoutParams(100, 100));
  int rootTag = uiManager.addMeasuredRootView(rootView);
  int textInputTag = rootTag + 1;
  final String hintStr = "placeholder text";

  uiManager.createView(
      textInputTag,
      ReactTextInputManager.REACT_CLASS,
      rootTag,
      JavaOnlyMap.of(
          ViewProps.FONT_SIZE, 13.37, ViewProps.HEIGHT, 20.0, "placeholder", hintStr));

  uiManager.manageChildren(
      rootTag,
      null,
      null,
      JavaOnlyArray.of(textInputTag),
      JavaOnlyArray.of(0),
      null);

  uiManager.onBatchComplete();
  executePendingChoreographerCallbacks();

  EditText editText = (EditText) rootView.getChildAt(0);
  assertThat(editText.getHint()).isEqualTo(hintStr);
  assertThat(editText.getTextSize()).isEqualTo((float) Math.ceil(13.37));
  assertThat(editText.getHeight()).isEqualTo(20);
}
项目:StaggeredAnimationGroup    文件:UtilsTest.java   
@Test
public void getConstraintLayoutParent_returnsNull_ifParent_isNotConstraintLayout() {
    //given
    StaggeredAnimationGroup spiedGroup = prepareSpiedGroup();
    ViewParent parent = new FrameLayout(RuntimeEnvironment.application);
    when(spiedGroup.getParent()).thenReturn(parent);

    //when
    ConstraintLayout result = Utils.getConstraintLayoutParent(spiedGroup);

    //then
    assertThat(result).isNull();
}
项目:GitHub    文件:VolleyStreamFetcherServerTest.java   
@Before
public void setUp() throws IOException {
  MockitoAnnotations.initMocks(this);

  waitForResponseLatch = new CountDownLatch(1);
  doAnswer(new CountDown()).when(callback).onDataReady(any(InputStream.class));
  doAnswer(new CountDown()).when(callback).onLoadFailed(any(Exception.class));
  requestQueue = Volley.newRequestQueue(RuntimeEnvironment.application);
  mockWebServer = new MockWebServer();
  mockWebServer.start();

  streamCaptor = ArgumentCaptor.forClass(InputStream.class);
}
项目:GitHub    文件:RequestBuilderTest.java   
@Test(expected = RuntimeException.class)
public void testThrowsIfIntoViewCalledOnBackgroundThread() throws InterruptedException {
  final ImageView imageView = new ImageView(RuntimeEnvironment.application);
  testInBackground(new BackgroundUtil.BackgroundTester() {
    @Override
    public void runTest() throws Exception {
      getNullModelRequest().into(imageView);

    }
  });
}
项目:weex-uikit    文件:WXDivTest.java   
@Before
public void setUp() throws Exception {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);

    WXDomObject divDom = new WXDomObject();
    WXDomObject spy = Mockito.spy(divDom);
    Mockito.when(spy.getPadding()).thenReturn(new Spacing());
    Mockito.when(spy.getEvents()).thenReturn(new WXEvent());
    Mockito.when(spy.clone()).thenReturn(divDom);
    TestDomObject.setRef(divDom,"1");
    mWXDiv = new WXDiv(instance, divDom, null);
    mWXDiv.initView();
}
项目:firefox-tv    文件:SessionManagerTest.java   
@Test
public void testNoSessionIsCreatedIfWeAreRestoring() {
    final SessionManager sessionManager = SessionManager.getInstance();

    final Bundle instanceState = new Bundle();

    final SafeIntent intent = new SafeIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(TEST_URL)));
    sessionManager.handleIntent(RuntimeEnvironment.application, intent, instanceState);

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

    assertFalse(sessionManager.hasSession());
}
项目:AndroidVerify    文件:FormTest.java   
@Before
public void setUp() {
    mContext = RuntimeEnvironment.application.getApplicationContext();
    mEmailEditText = new EditText(mContext);
    mEmailEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    mPasswordEditText = new EditText(mContext);
}
项目:q-mail    文件:CertificateErrorNotificationsTest.java   
private NotificationController createFakeNotificationController(NotificationManagerCompat notificationManager,
        NotificationCompat.Builder builder) {
    NotificationController controller = mock(NotificationController.class);
    when(controller.getContext()).thenReturn(RuntimeEnvironment.application);
    when(controller.getNotificationManager()).thenReturn(notificationManager);
    when(controller.createNotificationBuilder()).thenReturn(builder);
    return controller;
}
项目:q-mail    文件:LockScreenNotificationTest.java   
@Before
public void setUp() throws Exception {
    Context context = RuntimeEnvironment.application;
    builder = createFakeNotificationBuilder();
    publicBuilder = createFakeNotificationBuilder();
    NotificationController controller = createFakeController(context, publicBuilder);
    Account account = createFakeAccount();
    notificationData = createFakeNotificationData(account);
    lockScreenNotification = new LockScreenNotification(controller);
}
项目:q-mail    文件:SendFailedNotificationsTest.java   
private NotificationController createFakeNotificationController(NotificationManagerCompat notificationManager,
        Builder builder) {
    NotificationController controller = mock(NotificationController.class);
    when(controller.getContext()).thenReturn(RuntimeEnvironment.application);
    when(controller.getNotificationManager()).thenReturn(notificationManager);
    when(controller.createNotificationBuilder()).thenReturn(builder);
    return controller;
}
项目:MDRXL    文件:RxCursorLoaderTest.java   
@Before
public void setUp() {
    rxCursorLoader = new RxCursorLoader<Cursor>(RuntimeEnvironment.systemContext) {
        @Override
        protected Observable<Cursor> create(final String query) {
            return null;
        }
    };
    cursor = mock(Cursor.class);
}
项目:Goalie_Android    文件:BaseTest.java   
@Before
public void init() throws Exception {
    assertTrue(BuildConfig.DEBUG); // unit test should only be run on debug at this time

    FlowManager.init(new FlowConfig.Builder(RuntimeEnvironment.application).build());
    VolleyRequestQueue.getInstance().initialize(RuntimeEnvironment.application);
    setInternalState(VolleyRequestQueue.getInstance(), "mRequestQueue",
            newVolleyRequestQueueForTest(RuntimeEnvironment.application));

    ImageHelper.getInstance().initialize(RuntimeEnvironment.application);
    UserHelper.getInstance().initialize();
    GoalHelper.getInstance().initialize();
    PreferenceHelper.getInstance().initialize(RuntimeEnvironment.application);
    UserHelper.getInstance().LoadContacts();
}
项目:GitHub    文件:AppWidgetTargetTest.java   
@Test
public void testSetsBitmapOnRemoteViewsWithViewIdWhenCreatedWithWidgetIds() {
  int[] widgetIds = new int[] { 1 };
  AppWidgetTarget target =
      new AppWidgetTarget(RuntimeEnvironment.application, viewId, views, widgetIds);

  Bitmap bitmap = Bitmap.createBitmap(100, 200, Bitmap.Config.RGB_565);
  target.onResourceReady(bitmap, null /*glideAnimation*/);

  verify(views).setImageViewBitmap(eq(viewId), eq(bitmap));
}