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


Java ShadowHandler类代码示例

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


ShadowHandler类属于org.robolectric.shadows包,在下文中一共展示了ShadowHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testAutoReverseReverse_switchesDirectionAndSelects

import org.robolectric.shadows.ShadowHandler; //导入依赖的package包/类
@Test
public void testAutoReverseReverse_switchesDirectionAndSelects() {
    mAutoScanControllerForOptionScanning.autoScanActivated(false);
    ShadowHandler.runMainLooperOneTask();
    verify(mOptionManager, times(2)).selectOption(1);

    mAutoScanControllerForOptionScanning.autoScanActivated(true);
    ShadowHandler.runMainLooperOneTask();
    verify(mOptionManager, times(2)).selectOption(1);

    mAutoScanControllerForOptionScanning.autoScanActivated(true);
    verify(mOptionManager, times(2)).selectOption(1);
    verify(mOptionManager, times(1)).moveToParent(true);
    verify(mOptionManager, times(1))
            .addOptionManagerListener((OptionManager.OptionManagerListener) anyObject());
}
 
开发者ID:google,项目名称:talkback,代码行数:17,代码来源:AutoScanControllerTest.java

示例6: testReverseAutoAuto_switchesDirectionAndSelects

import org.robolectric.shadows.ShadowHandler; //导入依赖的package包/类
@Test
public void testReverseAutoAuto_switchesDirectionAndSelects() {
    mAutoScanControllerForOptionScanning.autoScanActivated(true);
    ShadowHandler.runMainLooperOneTask();
    verify(mOptionManager, times(2)).moveToParent(true);

    mAutoScanControllerForOptionScanning.autoScanActivated(false);
    ShadowHandler.runMainLooperOneTask();
    verify(mOptionManager, times(2)).moveToParent(true);

    mAutoScanControllerForOptionScanning.autoScanActivated(false);
    verify(mOptionManager, times(2)).moveToParent(true);
    verify(mOptionManager, times(1)).selectOption(1);
    verify(mOptionManager, times(1))
            .addOptionManagerListener((OptionManager.OptionManagerListener) anyObject());
}
 
开发者ID:google,项目名称:talkback,代码行数:17,代码来源:AutoScanControllerTest.java

示例7: testThatIfAllDispensingItemsHaveQuantitiesNoToastIsMade

import org.robolectric.shadows.ShadowHandler; //导入依赖的package包/类
@Test
public void testThatIfAllDispensingItemsHaveQuantitiesNoToastIsMade() throws Exception {

    DispenseActivity dispenseActivity = getDispenseActivity();

    GridView mockGridView = mock(GridView.class);
    SelectedCommoditiesAdapter mockCommoditiesAdapter = mock(SelectedCommoditiesAdapter.class);
    View mockListItemView = mock(View.class);
    EditText mockEditText = new EditText(application);
    mockEditText.setText("12");

    when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
    when(mockGridView.getChildAt(anyInt())).thenReturn(mockListItemView);
    when(mockGridView.getChildCount()).thenReturn(1);
    when(mockCommoditiesAdapter.getItem(anyInt())).thenReturn(new BaseCommodityViewModel(new Commodity("food")));
    when(mockGridView.getAdapter()).thenReturn(mockCommoditiesAdapter);

    dispenseActivity.gridViewSelectedCommodities = mockGridView;
    dispenseActivity.findViewById(R.id.buttonSubmitDispense).performClick();
    ShadowHandler.idleMainLooper();

    assertThat(ShadowToast.getTextOfLatestToast(), is(Matchers.nullValue()));


}
 
开发者ID:clintonhealthaccess,项目名称:chailmis-android,代码行数:26,代码来源:DispenseActivityTest.java

示例8: testThatIfAnyOfTheDispensingItemsHaveErrorsAToastIsMade

import org.robolectric.shadows.ShadowHandler; //导入依赖的package包/类
@Test
public void testThatIfAnyOfTheDispensingItemsHaveErrorsAToastIsMade() throws Exception {
    DispenseActivity dispenseActivity = getDispenseActivity();

    GridView mockGridView = mock(GridView.class);
    View mockListItemView = mock(View.class);
    EditText mockEditText = new EditText(application);

    mockEditText.setText("12");
    mockEditText.setError("error");
    SelectedCommoditiesAdapter mockSelectedCommoditiesAdapter = mock(SelectedCommoditiesAdapter.class);

    when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
    when(mockSelectedCommoditiesAdapter.getItem(anyInt())).thenReturn(new BaseCommodityViewModel(new Commodity("food")));
    when(mockSelectedCommoditiesAdapter.getCount()).thenReturn(1);
    when(mockSelectedCommoditiesAdapter.getView(anyInt(), org.mockito.Matchers.any(View.class), org.mockito.Matchers.any(ViewGroup.class))).thenReturn(mockListItemView);
    when(mockGridView.getAdapter()).thenReturn(mockSelectedCommoditiesAdapter);
    when(mockGridView.getChildAt(anyInt())).thenReturn(mockListItemView);
    when(mockGridView.getChildCount()).thenReturn(1);

    dispenseActivity.gridViewSelectedCommodities = mockGridView;
    dispenseActivity.findViewById(R.id.buttonSubmitDispense).performClick();
    ShadowHandler.idleMainLooper();

    assertThat(ShadowToast.getTextOfLatestToast(), equalTo(application.getString(R.string.dispense_submit_validation_message_errors)));
}
 
开发者ID:clintonhealthaccess,项目名称:chailmis-android,代码行数:27,代码来源:DispenseActivityTest.java

示例9: testThatIfAllDispensingItemsHaveNoQuantitiesAToastIsMade

import org.robolectric.shadows.ShadowHandler; //导入依赖的package包/类
@Test
public void testThatIfAllDispensingItemsHaveNoQuantitiesAToastIsMade() throws Exception {
    DispenseActivity dispenseActivity = getDispenseActivity();

    GridView mockGridView = mock(GridView.class);
    View mockListItemView = mock(View.class);
    EditText mockEditText = new EditText(application);
    SelectedCommoditiesAdapter mockSelectedCommoditiesAdapter = mock(SelectedCommoditiesAdapter.class);

    when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
    when(mockGridView.getAdapter()).thenReturn(mockSelectedCommoditiesAdapter);
    when(mockSelectedCommoditiesAdapter.getItem(anyInt())).thenReturn(new BaseCommodityViewModel(new Commodity("food")));
    when(mockSelectedCommoditiesAdapter.getCount()).thenReturn(1);
    when(mockSelectedCommoditiesAdapter.getView(anyInt(), org.mockito.Matchers.any(View.class), org.mockito.Matchers.any(ViewGroup.class))).thenReturn(mockListItemView);
    when(mockGridView.getChildAt(anyInt())).thenReturn(mockListItemView);
    when(mockGridView.getChildCount()).thenReturn(1);

    dispenseActivity.gridViewSelectedCommodities = mockGridView;
    dispenseActivity.findViewById(R.id.buttonSubmitDispense).performClick();
    ShadowHandler.idleMainLooper();
    assertThat(ShadowToast.getTextOfLatestToast(), equalTo(application.getString(R.string.dispense_submit_validation_message_filled)));
}
 
开发者ID:clintonhealthaccess,项目名称:chailmis-android,代码行数:23,代码来源:DispenseActivityTest.java

示例10: testThatIfAllDispensingItemsHaveZeroQuantitiesAToastIsMade

import org.robolectric.shadows.ShadowHandler; //导入依赖的package包/类
@Test
public void testThatIfAllDispensingItemsHaveZeroQuantitiesAToastIsMade() throws Exception {
    DispenseActivity dispenseActivity = getDispenseActivity();

    GridView mockGridView = mock(GridView.class);
    View mockListItemView = mock(View.class);
    SelectedCommoditiesAdapter mockSelectedCommoditiesAdapter = mock(SelectedCommoditiesAdapter.class);
    EditText mockEditText = new EditText(application);

    mockEditText.setText("0");

    when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
    when(mockListItemView.findViewById(R.id.editTextQuantity)).thenReturn(mockEditText);
    when(mockGridView.getAdapter()).thenReturn(mockSelectedCommoditiesAdapter);
    when(mockSelectedCommoditiesAdapter.getItem(anyInt())).thenReturn(new BaseCommodityViewModel(new Commodity("food")));
    when(mockSelectedCommoditiesAdapter.getCount()).thenReturn(1);
    when(mockSelectedCommoditiesAdapter.getView(anyInt(), org.mockito.Matchers.any(View.class), org.mockito.Matchers.any(ViewGroup.class))).thenReturn(mockListItemView);
    when(mockGridView.getChildAt(anyInt())).thenReturn(mockListItemView);
    when(mockGridView.getChildCount()).thenReturn(1);

    dispenseActivity.gridViewSelectedCommodities = mockGridView;
    dispenseActivity.findViewById(R.id.buttonSubmitDispense).performClick();
    ShadowHandler.idleMainLooper();
    assertThat(ShadowToast.getTextOfLatestToast(), equalTo(application.getString(R.string.dispense_submit_validation_message_zero)));
}
 
开发者ID:clintonhealthaccess,项目名称:chailmis-android,代码行数:26,代码来源:DispenseActivityTest.java

示例11: shouldShowErrorToastIfNotAVaccine

import org.robolectric.shadows.ShadowHandler; //导入依赖的package包/类
@Ignore("WIP-JOB")
public void shouldShowErrorToastIfNotAVaccine() throws Exception {
    ArrayList<AdjustmentsViewModel> commodities = new ArrayList<>();

    Commodity commodity = mock(Commodity.class);
    when(commodity.isVaccine()).thenReturn(false);
    when(commodity.getName()).thenReturn("Panadol");

    AdjustmentsViewModel adjustmentsViewModel = new AdjustmentsViewModel(commodity, 12, false);
    adjustmentsViewModel.setAdjustmentReason(AdjustmentReason.RETURNED_TO_LGA);
    commodities.add(adjustmentsViewModel);

    AdjustmentsActivity activity = getAdjustmentsActivity();
    EventBus.getDefault().post(new CommodityToggledEvent(adjustmentsViewModel));
    activity.spinnerAdjustmentReason.setSelection(4);

    Button submitButton = activity.getSubmitButton();
    submitButton.performClick();
    ShadowHandler.idleMainLooper();
    assertThat(ShadowToast.getTextOfLatestToast(), is(application.getResources().getString(R.string.not_related_to_vaccine)));
}
 
开发者ID:clintonhealthaccess,项目名称:chailmis-android,代码行数:22,代码来源:AdjustmentsActivityTest.java

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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