本文整理匯總了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);
}
示例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);
}
示例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));
}
示例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)));
}
示例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();
}
示例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);
}
示例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);
}
示例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));
}
示例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.");
}
示例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);
}
示例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();
}
示例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);
}
示例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));
}
示例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);
}
示例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());
}