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


Java ShadowHandler.runMainLooperToEndOfTasks方法代码示例

本文整理汇总了Java中org.robolectric.shadows.ShadowHandler.runMainLooperToEndOfTasks方法的典型用法代码示例。如果您正苦于以下问题:Java ShadowHandler.runMainLooperToEndOfTasks方法的具体用法?Java ShadowHandler.runMainLooperToEndOfTasks怎么用?Java ShadowHandler.runMainLooperToEndOfTasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.robolectric.shadows.ShadowHandler的用法示例。


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

示例1: rejectionChaining

import org.robolectric.shadows.ShadowHandler; //导入方法依赖的package包/类
/** Tests that rejections propagate. */
@Test
public void rejectionChaining() {
    final Value value = new Value();
    Promise<Integer> promise = new Promise<Integer>();

    Promise<Integer> result =
            promise.then(this.<Integer>identity()).then(this.<Integer>identity());

    result.then(this.<Integer>pass(), this.<Exception>setValue(value, 5));

    promise.reject(new Exception());
    ShadowHandler.runMainLooperToEndOfTasks();

    assertEquals(value.get(), 5);
    assertTrue(result.isRejected());
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:18,代码来源:PromiseTest.java

示例2: rejectOnThrow

import org.robolectric.shadows.ShadowHandler; //导入方法依赖的package包/类
/** Tests that Promises get rejected if a Function throws. */
@Test
public void rejectOnThrow() {
    Value value = new Value();
    Promise<Integer> promise = new Promise<Integer>();
    promise.then(new Promise.Function<Integer, Integer>() {
        @Override
        public Integer apply(Integer argument) {
            throw new IllegalArgumentException();
        }
    }).then(this.<Integer>pass(), this.<Exception>setValue(value, 5));

    promise.fulfill(0);

    ShadowHandler.runMainLooperToEndOfTasks();
    assertEquals(value.get(), 5);
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:18,代码来源:PromiseTest.java

示例3: rejectOnAsyncThrow

import org.robolectric.shadows.ShadowHandler; //导入方法依赖的package包/类
/** Tests that Promises get rejected if an AsyncFunction throws. */
@Test
public void rejectOnAsyncThrow() {
    Value value = new Value();
    Promise<Integer> promise = new Promise<Integer>();

    promise.then(new Promise.AsyncFunction<Integer, Integer>() {
        @Override
        public Promise<Integer> apply(Integer argument) {
            throw new IllegalArgumentException();
        }
    }).then(this.<Integer>pass(), this.<Exception>setValue(value, 5));

    promise.fulfill(0);

    ShadowHandler.runMainLooperToEndOfTasks();
    assertEquals(value.get(), 5);
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:19,代码来源:PromiseTest.java

示例4: rejectOnAsyncReject

import org.robolectric.shadows.ShadowHandler; //导入方法依赖的package包/类
/** Tests that Promises get rejected if an AsyncFunction rejects. */
@Test
public void rejectOnAsyncReject() {
    Value value = new Value();
    Promise<Integer> promise = new Promise<Integer>();
    final Promise<Integer> inner = new Promise<Integer>();

    promise.then(new Promise.AsyncFunction<Integer, Integer>() {
        @Override
        public Promise<Integer> apply(Integer argument) {
            return inner;
        }
    }).then(this.<Integer>pass(), this.<Exception>setValue(value, 5));

    promise.fulfill(0);

    ShadowHandler.runMainLooperToEndOfTasks();
    assertEquals(value.get(), 0);

    inner.reject();

    ShadowHandler.runMainLooperToEndOfTasks();
    assertEquals(value.get(), 5);
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:25,代码来源:PromiseTest.java

示例5: promiseChainingAsyncFunctions

import org.robolectric.shadows.ShadowHandler; //导入方法依赖的package包/类
/** Tests that promises can chain asynchronous functions correctly. */
@Test
public void promiseChainingAsyncFunctions() {
    Promise<Integer> promise = new Promise<Integer>();
    final Value value = new Value();

    final Promise<String> innerPromise = new Promise<String>();

    promise.then(new Promise.AsyncFunction<Integer, String>() {
                @Override
                public Promise<String> apply(Integer arg) {
                    return innerPromise;
                }
            }).then(new Callback<String>(){
                @Override
                public void onResult(String result) {
                    value.set(result.length());
                }
            });

    assertEquals(0, value.get());

    promise.fulfill(5);
    ShadowHandler.runMainLooperToEndOfTasks();
    assertEquals(0, value.get());

    innerPromise.fulfill("abc");
    ShadowHandler.runMainLooperToEndOfTasks();
    assertEquals(3, value.get());
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:31,代码来源:PromiseTest.java

示例6: rejectPromiseNoCallbacks

import org.robolectric.shadows.ShadowHandler; //导入方法依赖的package包/类
/** Tests that a Promise that does not use its result does not throw on rejection. */
@Test
public void rejectPromiseNoCallbacks() {
    Promise<Integer> promise = new Promise<Integer>();

    boolean caught = false;
    try {
        promise.reject();
        ShadowHandler.runMainLooperToEndOfTasks();
    } catch (UnhandledRejectionException e) {
        caught = true;
    }
    assertFalse(caught);
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:15,代码来源:PromiseTest.java

示例7: rejectPromiseNoHandler

import org.robolectric.shadows.ShadowHandler; //导入方法依赖的package包/类
/** Tests that a Promise that uses its result throws on rejection if it has no handler. */
@Test
public void rejectPromiseNoHandler() {
    Promise<Integer> promise = new Promise<Integer>();
    promise.then(this.<Integer>identity()).then(this.<Integer>pass());

    boolean caught = false;
    try {
        promise.reject();
        ShadowHandler.runMainLooperToEndOfTasks();
    } catch (UnhandledRejectionException e) {
        caught = true;
    }
    assertTrue(caught);
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:16,代码来源:PromiseTest.java

示例8: rejectPromiseHandled

import org.robolectric.shadows.ShadowHandler; //导入方法依赖的package包/类
/** Tests that a Promise that handles rejection does not throw on rejection. */
@Test
public void rejectPromiseHandled() {
    Promise<Integer> promise = new Promise<Integer>();
    promise.then(this.<Integer>identity()).then(this.<Integer>pass(), this.<Exception>pass());

    boolean caught = false;
    try {
        promise.reject();
        ShadowHandler.runMainLooperToEndOfTasks();
    } catch (UnhandledRejectionException e) {
        caught = true;
    }
    assertFalse(caught);
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:16,代码来源:PromiseTest.java

示例9: rejectionInformation

import org.robolectric.shadows.ShadowHandler; //导入方法依赖的package包/类
/** Tests that rejections carry the exception information. */
@Test
public void rejectionInformation() {
    Promise<Integer> promise = new Promise<Integer>();
    promise.then(this.<Integer>pass());

    String message = "Promise Test";
    try {
        promise.reject(new NegativeArraySizeException(message));
        ShadowHandler.runMainLooperToEndOfTasks();
    } catch (UnhandledRejectionException e) {
        assertTrue(e.getCause() instanceof NegativeArraySizeException);
        assertEquals(e.getCause().getMessage(), message);
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:16,代码来源:PromiseTest.java

示例10: testOptionScanningEnabled_highlightsMenuButton

import org.robolectric.shadows.ShadowHandler; //导入方法依赖的package包/类
@Test
public void testOptionScanningEnabled_highlightsMenuButton() {
    mSharedPreferences.edit()
            .putString(mContext.getString(R.string.pref_scanning_methods_key),
                    mContext.getString(R.string.option_scanning_key))
            .commit();
    mOptionManager.onSharedPreferenceChanged(mSharedPreferences, null);
    when(mOverlayController.getMenuButtonLocation()).thenReturn(MENU_BUTTON_BOUNDS);

    /* add a context menu with two items to the tree */
    CharSequence globalActionLabel0 = "global action label 0";
    CharSequence globalActionLabel1 = "global action label 1";
    GlobalActionNode globalNode0 = new GlobalActionNode(0, null, globalActionLabel0);
    GlobalActionNode globalNode1 = new GlobalActionNode(1, null, globalActionLabel1);
    ContextMenuNode contextMenu = new ContextMenuNode(globalNode0, globalNode1);
    mSelectionNode = new OptionScanSelectionNode(mSelectionNode, contextMenu);

    mOptionManager.clearFocusIfNewTree(mSelectionNode);
    mOptionManager.selectOption(0);
    verify(mOverlayController, times(1)).drawMenuButton();

    ShadowHandler.runMainLooperToEndOfTasks();

    verify(mOverlayController, times(2)).highlightPerimeterOfRects(
            mHighlightCaptor.capture(), mPaintCaptor.capture());

    List<Collection<Rect>> capturedHighlights = mHighlightCaptor.getAllValues();
    assertTrue(capturedHighlights.get(0).contains(NODE_BOUNDS_1));
    assertTrue(capturedHighlights.get(0).contains(NODE_BOUNDS_2));
    assertTrue(capturedHighlights.get(1).contains(MENU_BUTTON_BOUNDS));
}
 
开发者ID:google,项目名称:talkback,代码行数:32,代码来源:OptionManagerTest.java

示例11: testShowSelections_highlightsButtons

import org.robolectric.shadows.ShadowHandler; //导入方法依赖的package包/类
@Test
public void testShowSelections_highlightsButtons() {
    LinearLayout addedLayout = getLinearLayoutAddedWithShowSelections();

    /* Set up bounds since nothing is actually doing a layout here. */
    setBoundsForView(addedLayout.getChildAt(0), BOUNDS_1);
    setBoundsForView(addedLayout.getChildAt(1), BOUNDS_2);
    setBoundsForView(addedLayout.getChildAt(2), BOUNDS_3);

    /* Allow handler to run */
    ShadowHandler.runMainLooperToEndOfTasks();

    /* Verify first highlight */
    verify(mMockOverlayController).highlightPerimeterOfRects(
            mRectSetCaptor.capture(), eq(mPaints[0]));
    Iterator<Rect> rectIterator1 = mRectSetCaptor.getValue().iterator();
    assertEquals(BOUNDS_1, rectIterator1.next());
    assertFalse(rectIterator1.hasNext());
    /* Verify second highlight */
    verify(mMockOverlayController).highlightPerimeterOfRects(
            mRectSetCaptor.capture(), eq(mPaints[1]));
    Iterator<Rect> rectIterator2 = mRectSetCaptor.getValue().iterator();
    Rect rect1 = rectIterator2.next();
    Rect rect2 = rectIterator2.next();
    assertFalse(rectIterator2.hasNext());
    assertTrue((rect1.equals(BOUNDS_2)) || (rect2.equals(BOUNDS_2)));
    assertTrue((rect1.equals(BOUNDS_3)) || (rect2.equals(BOUNDS_3)));
    /* Verify that Clear Focus was not added in the context menu */
    verify(mMockOverlayController).highlightPerimeterOfRects(
            mRectSetCaptor.capture(), eq(mPaints[2]));
    Iterator<Rect> rectIterator3 = mRectSetCaptor.getValue().iterator();
    assertFalse(rectIterator3.hasNext());
}
 
开发者ID:google,项目名称:talkback,代码行数:34,代码来源:ContextMenuNodeTest.java


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