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


Java AssertableSubscriber类代码示例

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


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

示例1: addItem_ShouldNotBeSkipped_When_AddRequestFailedOnceAlready

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void addItem_ShouldNotBeSkipped_When_AddRequestFailedOnceAlready() {
    ItemId itemId = mock(ItemId.class);
    Throwable throwable = new RuntimeException();
    when(api.addItem(itemId))
            .thenReturn(Single.error(throwable))
            .thenReturn(Single.just(ApiResponse.createSuccessfulResponse()));

    Response.Cause cause = mock(Response.Cause.class);
    when(apiErrorConverter.convertApiError(new ExceptionApiError(throwable))).thenReturn(cause);

    itemRepository.addItem(itemId).test();
    AssertableSubscriber<Response> subscriber = itemRepository.addItem(itemId).test();

    RxJavaSchedulerUtils.advanceOneSecond();
    verify(api, times(2)).addItem(itemId);
    subscriber.assertResult(Response.createSuccessfulResponse())
            .assertCompleted();
    assertTrue(itemRepository.hasItem(itemId));
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:21,代码来源:ItemRepositoryTest_Part4_ApiCallsOptimisation.java

示例2: removeItem_ShouldNotBeSkipped_When_RemoveRequestFailedOnceAlready

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void removeItem_ShouldNotBeSkipped_When_RemoveRequestFailedOnceAlready() {
    ItemId itemId = addNewItemSuccessfully();
    Throwable throwable = new RuntimeException();
    when(api.removeItem(itemId))
            .thenReturn(Single.error(throwable))
            .thenReturn(Single.just(ApiResponse.createSuccessfulResponse()));

    Response.Cause cause = mock(Response.Cause.class);
    when(apiErrorConverter.convertApiError(new ExceptionApiError(throwable))).thenReturn(cause);

    itemRepository.removeItem(itemId).test();
    AssertableSubscriber<Response> subscriber = itemRepository.removeItem(itemId).test();

    RxJavaSchedulerUtils.advanceOneSecond();
    verify(api, times(2)).removeItem(itemId);
    subscriber.assertResult(Response.createSuccessfulResponse())
            .assertCompleted();
    assertFalse(itemRepository.hasItem(itemId));
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:21,代码来源:ItemRepositoryTest_Part4_ApiCallsOptimisation.java

示例3: twoAdditions_ShouldBeExecutedInParallel_When_ItemIdsAreDifferent

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void twoAdditions_ShouldBeExecutedInParallel_When_ItemIdsAreDifferent() {
    ItemId itemId1 = mock(ItemId.class);
    ItemId itemId2 = mock(ItemId.class);

    when(api.addItem(itemId1)).thenReturn(RxJavaUtils.createNeverCompletedSingle());
    when(api.addItem(itemId2)).thenReturn(RxJavaUtils.createNeverCompletedSingle());

    AssertableSubscriber<Response> subscriber1 = itemRepository.addItem(itemId1).test();
    AssertableSubscriber<Response> subscriber2 = itemRepository.addItem(itemId2).test();

    RxJavaSchedulerUtils.advanceOneSecond();
    subscriber1.assertNotCompleted();
    subscriber2.assertNotCompleted();

    verify(api).addItem(itemId1);
    verify(api).addItem(itemId2);
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:19,代码来源:ItemRepositoryTest_Part4_ApiCallsOptimisation.java

示例4: ARA_ReturnsSkippedResponsesForRemoveAndSecondAdd

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void ARA_ReturnsSkippedResponsesForRemoveAndSecondAdd() {
    ItemId itemId = mock(ItemId.class);

    when(api.addItem(itemId)).thenReturn(Single.just(ApiResponse.createSuccessfulResponse()));
    when(api.removeItem(itemId)).thenReturn(Single.just(ApiResponse.createSuccessfulResponse()));

    AssertableSubscriber<Response> firstAddSubscriber = itemRepository.addItem(itemId).test();
    AssertableSubscriber<Response> removeSubscriber = itemRepository.removeItem(itemId).test();
    AssertableSubscriber<Response> secondAddSubscriber = itemRepository.addItem(itemId).test();
    RxJavaSchedulerUtils.advanceOneSecond();

    assertTrue(firstAddSubscriber.getOnNextEvents().get(0).isSuccessful());
    assertTrue(removeSubscriber.getOnNextEvents().get(0).isSkipped());
    assertTrue(secondAddSubscriber.getOnNextEvents().get(0).isSkipped());
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:17,代码来源:ItemRepositoryTest_Part4_ApiCallsOptimisation.java

示例5: ARAR_ReturnsSkippedResponsesForFirstRemoveAndSecondAdd

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void ARAR_ReturnsSkippedResponsesForFirstRemoveAndSecondAdd() {
    ItemId itemId = mock(ItemId.class);

    when(api.addItem(itemId)).thenReturn(Single.just(ApiResponse.createSuccessfulResponse()));
    when(api.removeItem(itemId)).thenReturn(Single.just(ApiResponse.createSuccessfulResponse()));

    AssertableSubscriber<Response> firstAddSubscriber = itemRepository.addItem(itemId).test();
    AssertableSubscriber<Response> firstRemoveSubscriber = itemRepository.removeItem(itemId).test();
    AssertableSubscriber<Response> secondAddSubscriber = itemRepository.addItem(itemId).test();
    AssertableSubscriber<Response> secondRemoveSubscriber = itemRepository.removeItem(itemId).test();
    RxJavaSchedulerUtils.advanceOneSecond();

    assertTrue(firstAddSubscriber.getOnNextEvents().get(0).isSuccessful());
    assertTrue(firstRemoveSubscriber.getOnNextEvents().get(0).isSkipped());
    assertTrue(secondAddSubscriber.getOnNextEvents().get(0).isSkipped());
    assertTrue(secondRemoveSubscriber.getOnNextEvents().get(0).isSuccessful());
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:19,代码来源:ItemRepositoryTest_Part4_ApiCallsOptimisation.java

示例6: removeItem_CallsApiAndReturnFailed_When_ApiReturnFailed

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void removeItem_CallsApiAndReturnFailed_When_ApiReturnFailed() {
    ItemId itemId = addNewItemSuccessfully();

    ApiResponse.ApiError apiError = mock(ApiResponse.ApiError.class);

    when(api.removeItem(any())).thenReturn(Single.just(ApiResponse.createFailedResponse(HttpStatus.BAD_REQUEST.value(), apiError)));

    Response.Cause cause = mock(Response.Cause.class);
    when(apiErrorConverter.convertApiError(apiError)).thenReturn(cause);

    AssertableSubscriber<Response> subscriber = itemRepository.removeItem(itemId).test();
    RxJavaSchedulerUtils.advanceOneSecond();
    subscriber.assertResult(Response.createFailedResponse(cause))
            .assertCompleted();
    assertTrue(itemRepository.hasItem(itemId));
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:18,代码来源:ItemRepositoryTest_Part2_AddingAndRemoving.java

示例7: removeItem_CallsApiAndReturnSuccess_When_ApiReturnNotFound

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void removeItem_CallsApiAndReturnSuccess_When_ApiReturnNotFound() {
    ItemId itemId = addNewItemSuccessfully();

    ApiResponse.ApiError apiError = mock(ApiResponse.ApiError.class);

    when(api.removeItem(any())).thenReturn(Single.just(ApiResponse.createFailedResponse(HttpStatus.NOT_FOUND.value(), apiError)));

    Response.Cause cause = mock(Response.Cause.class);
    when(apiErrorConverter.convertApiError(apiError)).thenReturn(cause);

    AssertableSubscriber<Response> subscriber = itemRepository.removeItem(itemId).test();
    RxJavaSchedulerUtils.advanceOneSecond();
    subscriber.assertResult(Response.createSuccessfulResponse())
            .assertCompleted();
    assertFalse(itemRepository.hasItem(itemId));
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:18,代码来源:ItemRepositoryTest_Part2_AddingAndRemoving.java

示例8: ARAR_ResultIn01010Counter

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void ARAR_ResultIn01010Counter() {
    ItemId itemId = mock(ItemId.class);

    when(api.addItem(itemId)).thenReturn(Single.just(ApiResponse.createSuccessfulResponse()));
    when(api.removeItem(itemId)).thenReturn(Single.just(ApiResponse.createSuccessfulResponse()));

    AssertableSubscriber<Integer> counterTestSubscriber = itemRepository.getCounter().test();

    itemRepository.addItem(itemId).test();
    itemRepository.removeItem(itemId).test();
    itemRepository.addItem(itemId).test();
    itemRepository.removeItem(itemId).test();
    RxJavaSchedulerUtils.advanceOneSecond();

    counterTestSubscriber.assertReceivedOnNext(Arrays.asList(0, 1, 0, 1, 0));
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:18,代码来源:ItemRepositoryTest_Part3_CounterChanges.java

示例9: AR_ResultIn0101Counter_When_LastRemovalFails

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void AR_ResultIn0101Counter_When_LastRemovalFails() {
    ItemId itemId = mock(ItemId.class);

    when(api.addItem(itemId)).thenReturn(Single.just(ApiResponse.createSuccessfulResponse()));
    when(api.removeItem(itemId)).thenReturn(Single.just(
            ApiResponse.createFailedResponse(HttpStatus.BAD_REQUEST.value(), mock(ApiResponse.ApiError.class))));

    AssertableSubscriber<Integer> counterTestSubscriber = itemRepository.getCounter().test();

    itemRepository.addItem(itemId).test();
    itemRepository.removeItem(itemId).test();
    RxJavaSchedulerUtils.advanceOneSecond();

    counterTestSubscriber.assertReceivedOnNext(Arrays.asList(0, 1, 0, 1));
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:17,代码来源:ItemRepositoryTest_Part3_CounterChanges.java

示例10: shouldCreateExecutableFromEndpointMethodWithRxJavaCompletableReturnType

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void shouldCreateExecutableFromEndpointMethodWithRxJavaCompletableReturnType() throws Exception {
	EndpointCallExecutable<Completable, Void> executable = factory
			.create(new SimpleEndpointMethod(SomeType.class.getMethod("completable")));

	Completable completable = executable.execute(endpointCallMock, null);

	assertNotNull(completable);

	AssertableSubscriber<Void> subscriber = completable.subscribeOn(scheduler).test();

	subscriber.assertCompleted()
		.assertNoErrors()
		.assertNoValues();

	verify(endpointCallMock).execute();
}
 
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:18,代码来源:RxJavaCompletableEndpointCallExecutableFactoryTest.java

示例11: addItem_CallsApiAndReturnSuccess_When_ApiReturnSuccess

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void addItem_CallsApiAndReturnSuccess_When_ApiReturnSuccess() {
    ItemId itemId = mock(ItemId.class);
    when(api.addItem(itemId)).thenReturn(Single.just(ApiResponse.createSuccessfulResponse()));

    AssertableSubscriber<Response> subscriber = itemRepository.addItem(itemId).test();
    RxJavaSchedulerUtils.advanceOneSecond();

    subscriber.assertResult(Response.createSuccessfulResponse())
            .assertCompleted();
    assertTrue(itemRepository.hasItem(itemId));
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:13,代码来源:ItemRepositoryTest_Part2_AddingAndRemoving.java

示例12: addItem_CallsApiAndReturnFailed_When_ApiReturnBadRequest

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void addItem_CallsApiAndReturnFailed_When_ApiReturnBadRequest() {
    ItemId itemId = mock(ItemId.class);
    ApiResponse.ApiError apiError = mock(ApiResponse.ApiError.class);
    when(api.addItem(any())).thenReturn(Single.just(ApiResponse.createFailedResponse(HttpStatus.BAD_REQUEST.value(), apiError)));
    Response.Cause cause = mock(Response.Cause.class);
    when(apiErrorConverter.convertApiError(apiError)).thenReturn(cause);

    AssertableSubscriber<Response> subscriber = itemRepository.addItem(itemId).test();
    RxJavaSchedulerUtils.advanceOneSecond();

    subscriber.assertResult(Response.createFailedResponse(cause))
            .assertCompleted();
    assertFalse(itemRepository.hasItem(itemId));
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:16,代码来源:ItemRepositoryTest_Part2_AddingAndRemoving.java

示例13: addItem_CallsApiAndReturnSuccess_When_ApiReturnConflict

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void addItem_CallsApiAndReturnSuccess_When_ApiReturnConflict() {
    ItemId itemId = mock(ItemId.class);
    ApiResponse.ApiError apiError = mock(ApiResponse.ApiError.class);
    when(api.addItem(any())).thenReturn(Single.just(ApiResponse.createFailedResponse(HttpStatus.CONFLICT.value(), apiError)));
    Response.Cause cause = mock(Response.Cause.class);
    when(apiErrorConverter.convertApiError(apiError)).thenReturn(cause);

    AssertableSubscriber<Response> subscriber = itemRepository.addItem(itemId).test();
    RxJavaSchedulerUtils.advanceOneSecond();

    subscriber.assertResult(Response.createSuccessfulResponse())
            .assertCompleted();
    assertTrue(itemRepository.hasItem(itemId));
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:16,代码来源:ItemRepositoryTest_Part2_AddingAndRemoving.java

示例14: addItem_CallsApiAndReturnFailed_When_ApiThrowsException

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void addItem_CallsApiAndReturnFailed_When_ApiThrowsException() {
    ItemId itemId = mock(ItemId.class);
    Throwable throwable = new RuntimeException();
    when(api.addItem(itemId)).thenReturn(Single.error(throwable));
    Response.Cause cause = mock(Response.Cause.class);
    when(apiErrorConverter.convertApiError(new ExceptionApiError(throwable))).thenReturn(cause);

    AssertableSubscriber<Response> subscriber = itemRepository.addItem(itemId).test();
    RxJavaSchedulerUtils.advanceOneSecond();

    subscriber.assertResult(Response.createFailedResponse(cause))
            .assertCompleted();
    assertFalse(itemRepository.hasItem(itemId));
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:16,代码来源:ItemRepositoryTest_Part2_AddingAndRemoving.java

示例15: removeItem_CallsApiAndReturnSuccess_When_ApiReturnSuccess

import rx.observers.AssertableSubscriber; //导入依赖的package包/类
@Test
public void removeItem_CallsApiAndReturnSuccess_When_ApiReturnSuccess() {
    ItemId itemId = addNewItemSuccessfully();
    when(api.removeItem(itemId)).thenReturn(Single.just(ApiResponse.createSuccessfulResponse()));

    AssertableSubscriber<Response> subscriber = itemRepository.removeItem(itemId).test();
    RxJavaSchedulerUtils.advanceOneSecond();

    subscriber.assertReceivedOnNext(Collections.singletonList(Response.createSuccessfulResponse()))
            .assertCompleted();
    assertFalse(itemRepository.hasItem(itemId));
}
 
开发者ID:NikitaKozlov,项目名称:Switchman,代码行数:13,代码来源:ItemRepositoryTest_Part2_AddingAndRemoving.java


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