本文整理匯總了Java中rx.observers.TestSubscriber.assertError方法的典型用法代碼示例。如果您正苦於以下問題:Java TestSubscriber.assertError方法的具體用法?Java TestSubscriber.assertError怎麽用?Java TestSubscriber.assertError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rx.observers.TestSubscriber
的用法示例。
在下文中一共展示了TestSubscriber.assertError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: searchUsers_OtherHttpError_SearchTerminatedWithError
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void searchUsers_OtherHttpError_SearchTerminatedWithError() {
//Given
when(githubUserRestService.searchGithubUsers(anyString())).thenReturn(get403ForbiddenError());
//When
TestSubscriber<List<User>> subscriber = new TestSubscriber<>();
userRepository.searchUsers(USER_LOGIN_MOYHEEN).subscribe(subscriber);
//Then
subscriber.awaitTerminalEvent();
subscriber.assertError(HttpException.class);
verify(githubUserRestService).searchGithubUsers(USER_LOGIN_MOYHEEN);
verify(githubUserRestService, never()).getUser(USER_LOGIN_MOYHEEN);
verify(githubUserRestService, never()).getUser(USER_LOGIN_2_MOYHEEN);
}
示例2: callOnErrorIfApiReturnsAnError
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void callOnErrorIfApiReturnsAnError() {
OffsetDateTime lastUpdated = OffsetDateTime.of(2016, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
when(libraryService.lastUpdated()).thenReturn(Observable.just(lastUpdated));
Throwable apiError = new Throwable();
when(disclosureApi.allLibraries(any(), anyInt(), anyInt())).thenReturn(
Observable.error(apiError));
TestSubscriber<List<Library>> testSubscriber = new TestSubscriber<>();
syncLibraries.run()
.toBlocking()
.subscribe(testSubscriber);
testSubscriber.assertError(apiError);
}
示例3: rxCompletableFailWithoutFallback
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void rxCompletableFailWithoutFallback() {
server.enqueue(new MockResponse().setResponseCode(500));
TestInterface api = HystrixFeign.builder()
.target(TestInterface.class, "http://localhost:" + server.getPort());
Completable completable = api.completable();
assertThat(completable).isNotNull();
assertThat(server.getRequestCount()).isEqualTo(0);
TestSubscriber<String> testSubscriber = new TestSubscriber<String>();
completable.subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertError(HystrixRuntimeException.class);
}
示例4: searchMakeUp_OtherHttpError_searchTerminatedWithError
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void searchMakeUp_OtherHttpError_searchTerminatedWithError() {
// Given
when(makeUpProductRestService.searchMakeUpProducts(anyString(), anyString())).thenReturn
(get403ForbiddenError().toList());
// When
TestSubscriber<List<MakeUp>> subscriber = new TestSubscriber<>();
makeUpRepository.searchMakeUp(BRAND_COVERGIRL, PRODUCT_TYPE_LIPSTICK).subscribe(subscriber);
// Then
subscriber.awaitTerminalEvent();
subscriber.assertError(HttpException.class);
verify(makeUpProductRestService).searchMakeUpProducts(BRAND_COVERGIRL,
PRODUCT_TYPE_LIPSTICK);
}
示例5: groupApishouldReturnBadRequest
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void groupApishouldReturnBadRequest() {
// Given
login = "wrongLogin";
password = "wrongPassword";
TestSubscriber<SigfoxData<Group>> testObserver = new TestSubscriber<>();
// When
sigfoxClient.getGroupList(null, null, null).subscribe(testObserver);
// Then
testObserver.assertError(HttpException.class);
List<Throwable> errorEvents = testObserver.getOnErrorEvents();
assertThat(errorEvents).isNotNull().isNotEmpty();
assertThat(errorEvents.get(0)).hasMessage("HTTP 400 Bad Request");
}
示例6: 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();
}
示例7: testUploadFileNotFoundException
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUploadFileNotFoundException() throws Exception {
final File file = new File("invalid");
final String jobId = "job-id";
final Job job = Job.builder()
.setId(jobId)
.setStatus(Status.createQueued(jobId))
.setMetadata(Collections.emptyMap())
.setFilepath("invalid")
.setMimeType("text/plain")
.build();
final UploadService service = mock(UploadService.class);
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(FileNotFoundException.class);
ts.assertNoValues();
}
示例8: testUploadFileNotFound
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUploadFileNotFound() throws Exception {
final String jobId = "job-id";
final Job job = Job.builder()
.setId(jobId)
.setFilepath("invalid")
.setMetadata(Collections.emptyMap())
.setMimeType("text/plain")
.setStatus(Status.createQueued(jobId))
.build();
when(dataStore.get(jobId)).thenReturn(Observable.just(job));
final TestSubscriber<Status> ts = TestSubscriber.create();
uploadInteractor.upload(jobId).subscribe(ts);
testScheduler.triggerActions();
ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
ts.assertError(FileNotFoundException.class);
ts.assertNoValues();
verify(uploader, times(0)).upload(any(Job.class), any(File.class));
}
示例9: 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);
}
示例10: thatMissingClosingIfThrowsException
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test public void thatMissingClosingIfThrowsException() {
TestSubscriber<String> testSubscriber = new TestSubscriber<String>();
MigrationManager.migrate(OLD_INDENTATION_MARKS, new FileUtils()
.getFileLines("bonus1.txt"))
.subscribe(testSubscriber);
testSubscriber.assertError(SyntaxBlockVerifier.MissingBlockException.class);
}
示例11: thatMissingSeveralClosingPartsThrowsException
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test public void thatMissingSeveralClosingPartsThrowsException() {
TestSubscriber<String> testSubscriber = new TestSubscriber<String>();
MigrationManager.migrate(OLD_INDENTATION_MARKS, new FileUtils()
.getFileLines("bonus2.txt"))
.subscribe(testSubscriber);
testSubscriber.assertError(SyntaxBlockVerifier.MissingBlockException.class);
}
示例12: thatMissingClosingForThrowsException
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test public void thatMissingClosingForThrowsException() {
TestSubscriber<String> testSubscriber = new TestSubscriber<String>();
MigrationManager.migrate(OLD_INDENTATION_MARKS, new FileUtils()
.getFileLines("bonus3.txt"))
.subscribe(testSubscriber);
testSubscriber.assertError(SyntaxBlockVerifier.MissingBlockException.class);
}
示例13: thatUselessMissingBlocksThrowsException
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test public void thatUselessMissingBlocksThrowsException() {
TestSubscriber<String> testSubscriber = new TestSubscriber<String>();
MigrationManager.migrate(OLD_INDENTATION_MARKS, new FileUtils()
.getFileLines("bonus4.txt"))
.subscribe(testSubscriber);
testSubscriber.assertError(EmptyStackException.class);
}
示例14: failZipMapIfStreamFails
import rx.observers.TestSubscriber; //導入方法依賴的package包/類
@Test public void failZipMapIfStreamFails() {
String mockItemOne = "mockItemOne";
Observable<String> streamOne = Observable.just(mockItemOne);
Observable<String> streamTwo = Observable.error(new IllegalStateException());
TestSubscriber<List<String>> testSubscriber = new TestSubscriber<>();
RxUtils.zipMap(streamOne, streamTwo, (s1, s2) -> Observable.just(Arrays.asList(s1, s2)))
.toBlocking()
.subscribe(testSubscriber);
testSubscriber.assertError(IllegalStateException.class);
}
示例15: 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);
}