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


Java TestSubscriber.assertValues方法代碼示例

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


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

示例1: startSchedule

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void startSchedule() {
    TestScheduler scheduler = new TestScheduler();
    RxState<Integer> state = new RxState<>(0, scheduler);
    TestSubscriber<Integer> subscriber = new TestSubscriber<>();
    state.values(StartWith.SCHEDULE).subscribe(subscriber);
    subscriber.assertValues();
    state.apply(it -> it + 1);
    scheduler.triggerActions();
    subscriber.assertValues(0, 1);
}
 
開發者ID:konmik,項目名稱:rxstate,代碼行數:12,代碼來源:RxStateTest.java

示例2: startImmediate

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void startImmediate() {
    RxState<Integer> state = new RxState<>(0, Schedulers.immediate());
    TestSubscriber<Integer> subscriber = new TestSubscriber<>();
    state.values(StartWith.IMMEDIATE).subscribe(subscriber);
    subscriber.assertValues(0);
    state.apply(it -> it + 1);
    subscriber.assertValues(0, 1);
}
 
開發者ID:konmik,項目名稱:rxstate,代碼行數:10,代碼來源:RxStateTest.java

示例3: startNo

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void startNo() {
    RxState<Integer> state = new RxState<>(0, Schedulers.immediate());
    TestSubscriber<Integer> subscriber = new TestSubscriber<>();
    state.values(StartWith.NO).subscribe(subscriber);
    subscriber.assertValues();
    state.apply(it -> it + 1);
    subscriber.assertValues(1);
}
 
開發者ID:konmik,項目名稱:rxstate,代碼行數:10,代碼來源:RxStateTest.java

示例4: postedObjectsAreReceived

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void postedObjectsAreReceived() {
    TestSubscriber<Object> testSubscriber = new TestSubscriber<>();
    mEventBus.observable().subscribe(testSubscriber);

    Object event1 = new Object();
    Object event2 = new Object();
    mEventBus.post(event1);
    mEventBus.post(event2);

    testSubscriber.assertValues(event1, event2);
}
 
開發者ID:ebridfighter,項目名稱:GongXianSheng,代碼行數:13,代碼來源:RxEventBusTest.java

示例5: states_should_observeStateChanges

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void states_should_observeStateChanges() {
  //GIVEN
  Store<Integer> store = new Store<>(0);
  TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
  states(store).subscribe(testSubscriber);

  //WHEN
  store.dispatch(integer -> integer + 1);

  //THEN
  testSubscriber.assertNoTerminalEvent();
  testSubscriber.assertValues(0, 1);
}
 
開發者ID:groupon,項目名稱:grox,代碼行數:15,代碼來源:RxStoresTest.java

示例6: testUpload

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUpload() 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),
            Status.createSending(jobId, 40), Status.createSending(jobId, 50),
            Status.createSending(jobId, 60), Status.createSending(jobId, 70),
            Status.createSending(jobId, 80), Status.createSending(jobId, 90),
            Status.createSending(jobId, 100), Status.createCompleted(jobId, "Finished"),
    };

    when(uploader.upload(job, file)).thenReturn(Observable.from(statuses));

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

    testScheduler.triggerActions();

    ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
    ts.assertNoErrors();
    ts.assertValues(statuses);
}
 
開發者ID:jsaund,項目名稱:RxUploader,代碼行數:35,代碼來源:UploadInteractorImplTest.java

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

示例8: assertValues

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
private void assertValues(List<Integer> values, TestSubscriber<Integer> subscriber) {
    subscriber.assertValues(values.toArray(new Integer[values.size()]));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:4,代碼來源:RxPresenterTest.java

示例9: testUpload

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUpload() 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 BufferedSink sink = mock(BufferedSink.class);

    final List<Status> values = new ArrayList<>();
    values.add(Status.createSending(jobId, 0));

    final long total = file.length();
    long consumed = 0;
    while (consumed < total) {
        consumed = Math.min(total, consumed + RxRequestBody.BUFFER_SIZE);
        values.add(Status.createSending(jobId, (int) ((float) consumed * 100 / total)));
    }
    values.add(Status.createCompleted(jobId, "complete"));

    final Status[] expectedStatus = new Status[values.size()];
    values.toArray(expectedStatus);

    final UploadService service = (__, data) -> {
        try {
            data.body().writeTo(sink);
        } catch (@NonNull IOException e) {
            Single.error(e);
        }
        return Single.just("complete");
    };

    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.assertNoErrors();
    ts.assertValues(expectedStatus);
}
 
開發者ID:jsaund,項目名稱:RxUploader,代碼行數:46,代碼來源:UploaderTest.java

示例10: testUploadFailed

import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUploadFailed() 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 List<Status> values = new ArrayList<>();

    final long total = file.length();
    long consumed = 0;
    while (consumed <= (0.5f * total)) {
        values.add(Status.createSending(jobId, (int) ((float) consumed * 100 / total)));
        consumed = Math.min(total, consumed + RxRequestBody.BUFFER_SIZE);
    }

    final Status[] expectedStatus = new Status[values.size()];
    values.toArray(expectedStatus);

    final BufferedSink sink = mock(BufferedSink.class);
    when(sink.write(any(Source.class), anyLong())).thenAnswer(new Answer<BufferedSink>() {
        long bytesRead = 0;

        @Override
        public BufferedSink answer(InvocationOnMock invocation) throws Throwable {
            bytesRead += (long) invocation.getArguments()[1];
            if (bytesRead > 0.5f * total) {
                throw new IOException("exception");
            }
            return sink;
        }
    });

    final UploadService service = (__, data) -> {
        try {
            data.body().writeTo(sink);
        } catch (@NonNull IOException e) {
            return Single.error(e);
        }
        return Single.just("complete");
    };

    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(IOException.class);
    ts.assertValues(expectedStatus);
}
 
開發者ID:jsaund,項目名稱:RxUploader,代碼行數:56,代碼來源:UploaderTest.java


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