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


Java TestSubscriber.awaitTerminalEvent方法代碼示例

本文整理匯總了Java中rx.observers.TestSubscriber.awaitTerminalEvent方法的典型用法代碼示例。如果您正苦於以下問題:Java TestSubscriber.awaitTerminalEvent方法的具體用法?Java TestSubscriber.awaitTerminalEvent怎麽用?Java TestSubscriber.awaitTerminalEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rx.observers.TestSubscriber的用法示例。


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

示例1: testGetInvalidJobId

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@SuppressLint("ApplySharedPref")
@Test
public void testGetInvalidJobId() throws Exception {
    final Job test = createTestJob();
    final String json = gson.toJson(test);
    final String key = SimpleUploadDataStore.jobIdKey(test.id());
    final Set<String> keys = new HashSet<>();
    keys.add(key);

    final SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putStringSet(SimpleUploadDataStore.KEY_JOB_IDS, keys);
    editor.putString(key, json);
    editor.commit();

    final TestSubscriber<Job> ts = TestSubscriber.create();
    dataStore.get("bad_id").subscribe(ts);

    ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
    ts.assertNoErrors();
    ts.assertValueCount(1);
    ts.assertValue(Job.INVALID_JOB);
}
 
開發者ID:jsaund,項目名稱:RxUploader,代碼行數:23,代碼來源:SimpleUploadDataStoreTest.java

示例2: searchMakeUp_200OkResponse_InvokesCorrectApiCalls

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void searchMakeUp_200OkResponse_InvokesCorrectApiCalls() {
    // Given
    when(makeUpProductRestService.searchMakeUpProducts(anyString(), anyString())).thenReturn
            (Observable.just(makeUpList()).toList());

    // When
    TestSubscriber<List<MakeUp>> subscriber = new TestSubscriber<>();
    makeUpRepository.searchMakeUp(BRAND_COVERGIRL, PRODUCT_TYPE_LIPSTICK).subscribe(subscriber);

    // Then
    subscriber.awaitTerminalEvent();
    subscriber.assertNoErrors();

    List<List<MakeUp>> onNextEvents = subscriber.getOnNextEvents();
    List<MakeUp> makeup = onNextEvents.get(0);
    Assert.assertEquals(BRAND_COVERGIRL, makeup.get(0).getBrand());
    Assert.assertEquals(PRODUCT_TYPE_LIPSTICK, makeup.get(0).getProductType());
    verify(makeUpProductRestService).searchMakeUpProducts(BRAND_COVERGIRL,
            PRODUCT_TYPE_LIPSTICK);
}
 
開發者ID:moyheen,項目名稱:MakeUpSearch,代碼行數:22,代碼來源:MakeUpRepositoryImplTest.java

示例3: rxObservableIntFallback

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void rxObservableIntFallback() {
  server.enqueue(new MockResponse().setResponseCode(500));

  TestInterface api = target();

  Observable<Integer> observable = api.intObservable();

  assertThat(observable).isNotNull();
  assertThat(server.getRequestCount()).isEqualTo(0);

  TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>();
  observable.subscribe(testSubscriber);
  testSubscriber.awaitTerminalEvent();
  Assertions.assertThat(testSubscriber.getOnNextEvents().get(0)).isEqualTo(new Integer(0));
}
 
開發者ID:wenwu315,項目名稱:XXXX,代碼行數:17,代碼來源:HystrixBuilderTest.java

示例4: update

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void update() throws Exception {
    final Job test = createTestJob();
    final String json = gson.toJson(test);
    final String key = SimpleUploadDataStore.jobIdKey(test.id());
    final Set<String> keys = new HashSet<>();
    keys.add(key);

    final SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putStringSet(SimpleUploadDataStore.KEY_JOB_IDS, keys);
    editor.putString(key, json);
    editor.apply();

    final TestSubscriber<Job> ts = TestSubscriber.create();
    dataStore.update(Status.createCompleted(test.id(), null)).subscribe(ts);

    ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
    ts.assertNoErrors();
    ts.assertValueCount(1);
    ts.assertValue(test.withStatus(Status.createCompleted(test.id(), null)));
}
 
開發者ID:jsaund,項目名稱:RxUploader,代碼行數:22,代碼來源:SimpleUploadDataStoreTest.java

示例5: testUploadFailedUnhandledException

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUploadFailedUnhandledException() throws Exception {
    final File file = getFile(TEST_FILE);
    final String jobId = "job-id";
    final Job job = Job.builder()
            .setId(jobId)
            .setStatus(Status.createQueued(jobId))
            .setMetadata(Collections.emptyMap())
            .setFilepath(file.getPath())
            .setMimeType("text/plain")
            .build();

    final UploadService service = mock(UploadService.class);
    when(service.upload(anyMap(), any(MultipartBody.Part.class)))
            .thenThrow(new RuntimeException(""));

    final Uploader uploader = new Uploader(service, Schedulers.io());
    final TestSubscriber<Status> ts = TestSubscriber.create();
    uploader.upload(job, file).subscribe(ts);

    ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
    ts.assertError(RuntimeException.class);
    ts.assertNoValues();
}
 
開發者ID:jsaund,項目名稱:RxUploader,代碼行數:25,代碼來源:UploaderTest.java

示例6: searchMakeUp_IoExceptionThenSuccess_SearchMakeUpRetried

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void searchMakeUp_IoExceptionThenSuccess_SearchMakeUpRetried() {
    // Given
    when(makeUpProductRestService.searchMakeUpProducts(anyString(), anyString())).thenReturn
            (getIoExceptionError().toList(), Observable.just(makeUpList()).toList());

    // When
    TestSubscriber<List<MakeUp>> subscriber = new TestSubscriber<>();
    makeUpRepository.searchMakeUp(BRAND_COVERGIRL, PRODUCT_TYPE_LIPSTICK).subscribe(subscriber);

    // Then
    subscriber.awaitTerminalEvent();
    subscriber.assertNoErrors();

    verify(makeUpProductRestService, times(2)).searchMakeUpProducts(BRAND_COVERGIRL,
            PRODUCT_TYPE_LIPSTICK);
}
 
開發者ID:moyheen,項目名稱:MakeUpSearch,代碼行數:18,代碼來源:MakeUpRepositoryImplTest.java

示例7: searchUsers_200OKResponse_InvokesCorrectApiCalls

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void searchUsers_200OKResponse_InvokesCorrectApiCalls() {
    // Given
    when(githubUserRestService.searchGithubUsers(anyString())).thenReturn(Observable.just
            (githubUserList()));
    when(githubUserRestService.getUser(anyString())).thenReturn(Observable.just
            (user1FullDetails()), Observable.just(user2FullDetails()));

    // When
    TestSubscriber<List<User>> subscriber = new TestSubscriber<>();
    userRepository.searchUsers(USER_LOGIN_MOYHEEN).subscribe(subscriber);

    // Then
    subscriber.awaitTerminalEvent();
    subscriber.assertNoErrors();

    List<List<User>> onNextEvents = subscriber.getOnNextEvents();
    List<User> users = onNextEvents.get(0);
    Assert.assertEquals(USER_LOGIN_MOYHEEN, users.get(0).getLogin());
    Assert.assertEquals(USER_LOGIN_2_MOYHEEN, users.get(1).getLogin());
    verify(githubUserRestService).searchGithubUsers(USER_LOGIN_MOYHEEN);
    verify(githubUserRestService).getUser(USER_LOGIN_MOYHEEN);
    verify(githubUserRestService).getUser(USER_LOGIN_2_MOYHEEN);
}
 
開發者ID:moyheen,項目名稱:github-user-search,代碼行數:25,代碼來源:UserRepositoryImplTest.java

示例8: testUploadJobNotFound

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUploadJobNotFound() throws Exception {
    final String jobId = "job-id";
    when(dataStore.get(jobId)).thenReturn(Observable.just(Job.INVALID_JOB));

    final TestSubscriber<Status> ts = TestSubscriber.create();
    uploadInteractor.upload(jobId).subscribe(ts);

    testScheduler.triggerActions();

    ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
    ts.assertNoErrors();
    ts.assertValueCount(1);
    ts.assertValue(Status.createInvalid(jobId));

    verify(uploader, times(0)).upload(any(Job.class), any(File.class));
}
 
開發者ID:jsaund,項目名稱:RxUploader,代碼行數:18,代碼來源:UploadInteractorImplTest.java

示例9: rxObservableListFall_noFallback

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void rxObservableListFall_noFallback() {
  server.enqueue(new MockResponse().setResponseCode(500));

  TestInterface api = targetWithoutFallback();

  Observable<List<String>> observable = api.listObservable();

  assertThat(observable).isNotNull();
  assertThat(server.getRequestCount()).isEqualTo(0);

  TestSubscriber<List<String>> testSubscriber = new TestSubscriber<List<String>>();
  observable.subscribe(testSubscriber);
  testSubscriber.awaitTerminalEvent();

  assertThat(testSubscriber.getOnNextEvents()).isEmpty();
  assertThat(testSubscriber.getOnErrorEvents().get(0))
      .isInstanceOf(HystrixRuntimeException.class)
      .hasMessage("TestInterface#listObservable() failed and no fallback available.");
}
 
開發者ID:wenwu315,項目名稱:XXXX,代碼行數:21,代碼來源:HystrixBuilderTest.java

示例10: searchUsers_GetUserIOExceptionThenSuccess_SearchUsersRetried

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void searchUsers_GetUserIOExceptionThenSuccess_SearchUsersRetried() {
    //Given
    when(githubUserRestService.searchGithubUsers(anyString())).thenReturn(Observable.just(githubUserList()));
    when(githubUserRestService.getUser(anyString()))
            .thenReturn(getIOExceptionError(), Observable.just(user1FullDetails()),
                    Observable.just(user2FullDetails()));

    //When
    TestSubscriber<List<User>> subscriber = new TestSubscriber<>();
    userRepository.searchUsers(USER_LOGIN_MOYHEEN).subscribe(subscriber);

    //Then
    subscriber.awaitTerminalEvent();
    subscriber.assertNoErrors();

    verify(githubUserRestService, times(2)).searchGithubUsers(USER_LOGIN_MOYHEEN);
    verify(githubUserRestService, times(2)).getUser(USER_LOGIN_MOYHEEN);
    verify(githubUserRestService).getUser(USER_LOGIN_2_MOYHEEN);
}
 
開發者ID:moyheen,項目名稱:github-user-search,代碼行數:21,代碼來源:UserRepositoryImplTest.java

示例11: success

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test public void success() throws InterruptedException {
  TestSubscriber<Void> subscriber = new TestSubscriber<>();
  service.completable().subscribe(subscriber);
  assertFalse(subscriber.awaitValueCount(1, 1, SECONDS));

  server.enqueue(new MockResponse());
  subscriber.awaitTerminalEvent(1, SECONDS);
  subscriber.assertCompleted();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:AsyncTest.java

示例12: failure

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test public void failure() throws InterruptedException {
  TestSubscriber<Void> subscriber = new TestSubscriber<>();
  service.completable().subscribe(subscriber);
  assertFalse(subscriber.awaitValueCount(1, 1, SECONDS));

  server.enqueue(new MockResponse().setSocketPolicy(DISCONNECT_AFTER_REQUEST));
  subscriber.awaitTerminalEvent(1, SECONDS);
  subscriber.assertError(IOException.class);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:AsyncTest.java

示例13: validateSuccess

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
public static <T extends Resource> void validateSuccess(Observable<ResourceResponse<T>> observable,
        ResourceResponseValidator<T> validator, long timeout) throws InterruptedException {

    TestSubscriber<ResourceResponse<T>> testSubscriber = new TestSubscriber<ResourceResponse<T>>();

    observable.subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
    testSubscriber.assertNoErrors();
    testSubscriber.assertCompleted();
    testSubscriber.assertValueCount(1);
    validator.validate(testSubscriber.getOnNextEvents().get(0));
}
 
開發者ID:Azure,項目名稱:azure-documentdb-rxjava,代碼行數:13,代碼來源:TestSuiteBase.java

示例14: testUploadError

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUploadError() throws Exception {
    final String jobId = "job-id";
    final File file = getFile(TEST_FILE);
    final Job job = Job.builder()
            .setId(jobId)
            .setFilepath(file.getPath())
            .setMetadata(Collections.emptyMap())
            .setMimeType("text/plain")
            .setStatus(Status.createQueued(jobId))
            .build();

    when(dataStore.get(jobId)).thenReturn(Observable.just(job));

    final Status[] statuses = new Status[] {
            Status.createSending(jobId, 0), Status.createSending(jobId, 10),
            Status.createSending(jobId, 20), Status.createSending(jobId, 30),
    };

    when(uploader.upload(eq(job), any(File.class))).thenReturn(
            Observable.from(statuses).concatWith(Observable.error(new IOException("error"))));

    final TestSubscriber<Status> ts = TestSubscriber.create();
    uploadInteractor.upload(jobId).subscribe(ts);

    testScheduler.triggerActions();

    ts.awaitTerminalEvent(1, TimeUnit.SECONDS);

    ts.assertValues(statuses);
    ts.assertError(IOException.class);
}
 
開發者ID:jsaund,項目名稱:RxUploader,代碼行數:33,代碼來源:UploadInteractorImplTest.java

示例15: validateQuerySuccess

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
public static <T extends Resource> void validateQuerySuccess(Observable<FeedResponsePage<T>> observable,
        FeedResponsePageListValidator<T> validator, long timeout) throws InterruptedException {

    TestSubscriber<FeedResponsePage<T>> testSubscriber = new TestSubscriber<>();

    observable.subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
    testSubscriber.assertNoErrors();
    testSubscriber.assertCompleted();
    validator.validate(testSubscriber.getOnNextEvents());
}
 
開發者ID:Azure,項目名稱:azure-documentdb-rxjava,代碼行數:12,代碼來源:TestSuiteBase.java


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