本文整理汇总了Java中org.assertj.core.api.ThrowableAssert类的典型用法代码示例。如果您正苦于以下问题:Java ThrowableAssert类的具体用法?Java ThrowableAssert怎么用?Java ThrowableAssert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThrowableAssert类属于org.assertj.core.api包,在下文中一共展示了ThrowableAssert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subscribeOnlyOnceFlowableOperatorErrorsWhenMultipleSubscribe
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void subscribeOnlyOnceFlowableOperatorErrorsWhenMultipleSubscribe() {
SubscribeOnlyOnceFlowableOperator<Object> op = new SubscribeOnlyOnceFlowableOperator<Object>();
Subscriber<Object> innerSub = mock(Subscriber.class);
final Subscription subscription = mock(Subscription.class);
final Subscriber<Object> outerSub = op.apply(innerSub);
outerSub.onSubscribe(subscription);
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() {
outerSub.onSubscribe(subscription);
}
})
.isInstanceOf(NullPointerException.class)
.hasMessageContaining("cannot directly subscribe to a gRPC service multiple times");
verify(innerSub, times(1)).onSubscribe(subscription);
}
示例2: subscribeOnlyOnceSingleOperatorErrorsWhenMultipleSubscribe
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void subscribeOnlyOnceSingleOperatorErrorsWhenMultipleSubscribe() {
SubscribeOnlyOnceSingleOperator<Object> op = new SubscribeOnlyOnceSingleOperator<Object>();
SingleObserver<Object> innerSub = mock(SingleObserver.class);
final Disposable disposable = mock(Disposable.class);
final SingleObserver<Object> outerSub = op.apply(innerSub);
outerSub.onSubscribe(disposable);
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() {
outerSub.onSubscribe(disposable);
}
})
.isInstanceOf(NullPointerException.class)
.hasMessageContaining("cannot directly subscribe to a gRPC service multiple times");
verify(innerSub, times(1)).onSubscribe(disposable);
}
示例3: testExecutingTwiceThrowsIllegalStateException
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void testExecutingTwiceThrowsIllegalStateException() throws Exception {
Request request = RequestUtils.getUserInfoRequest(Endpoint.DEFAULT);
mockConnection(createDummyConnection(request.endpoint(), MOCK_EMPTY_ARRAY_RESPONSE));
final RealCall call = getMockRealCall(request, executor);
call.execute();
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
call.execute();
}
}).isInstanceOf(IllegalStateException.class);
}
示例4: testEnqueueWithTimeoutBlocksUntilTimeout
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void testEnqueueWithTimeoutBlocksUntilTimeout() throws Exception {
Request request = RequestUtils.getUserInfoRequest(Endpoint.DEFAULT);
final Connection connection = createDummyConnection(Endpoint.DEFAULT, MOCK_EMPTY_ARRAY_RESPONSE);
mockConnection(connection);
final RealCall call = getMockRealCall(request, realExecutor);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Thread.sleep(MOCK_TIMEOUT_TIME);
return connection.sink();
}
}).when(connection).sink();
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
call.enqueueAndWait(MOCK_TIMEOUT_TIME, TimeUnit.MILLISECONDS);
}
}).isInstanceOf(TimeoutException.class);
}
示例5: testExecutingTwiceThrowsIllegalStateException
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void testExecutingTwiceThrowsIllegalStateException() throws Exception {
Connection connection = createDummyConnection(Endpoint.DEFAULT, getMockByteDataResponse(1));
retrofitConnectionProvider(connection);
final MultiCall multiCall = createMultiCall(connection, executor);
multiCall.execute();
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
multiCall.execute();
}
}).isInstanceOf(IllegalStateException.class);
}
示例6: testExecutingAfterCancelThrowsIOException
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void testExecutingAfterCancelThrowsIOException() throws Exception {
Connection connection = createDummyConnection(Endpoint.DEFAULT, getMockByteDataResponse(1));
retrofitConnectionProvider(connection);
final MultiCall multiCall = createMultiCall(connection, executor);
multiCall.cancel();
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
multiCall.execute();
}
}).isInstanceOf(IOException.class);
}
示例7: testEnqueueWithTimeoutBlocksUntilTimeout
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void testEnqueueWithTimeoutBlocksUntilTimeout() throws Exception {
final Connection connection = createDummyConnection(Endpoint.DEFAULT, getMockByteDataResponse(1));
retrofitConnectionProvider(connection);
final MultiCall multiCall = createMultiCall(connection, realExecutor);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Thread.sleep(MOCK_TIMEOUT_TIME);
return connection.sink();
}
}).when(connection).sink();
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
multiCall.enqueueAndWait(MOCK_TIMEOUT_TIME, TimeUnit.MILLISECONDS);
}
}).isInstanceOf(TimeoutException.class);
}
示例8: fromBytes_withNullIntent_throwsBadParcelableException
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void fromBytes_withNullIntent_throwsBadParcelableException() {
final byte[] intentBytes = toBytesUnchecked(null);
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
IntentUtil.fromBytes(intentBytes);
}
}).isInstanceOf(BadParcelableException.class);
}
示例9: rollbackToPosition
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void rollbackToPosition() throws Exception {
// Populate a session state with dummy data for a single partition
final SessionState sessionState = new SessionState();
PartitionState partitionState = new PartitionState();
partitionState.addToFailoverLog(5, 12345);
partitionState.setStartSeqno(1);
partitionState.setEndSeqno(1000);
partitionState.setSnapshotStartSeqno(2);
partitionState.setSnapshotEndSeqno(3);
sessionState.set(0, partitionState);
Throwable th = catchThrowable(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
sessionState.rollbackToPosition((short) 0, 1L);
}
});
assertThat(th).isNull();
}
示例10: verifyMetadata
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
private void verifyMetadata(final DefaultErrorDTO error, MetadataArgOption metadataArgOption, Map<String, Object> expectedMetadata) {
switch(metadataArgOption) {
case NULL:
case EMPTY: // intentional fall-through
assertThat(error.metadata)
.isNotNull()
.isEmpty();
break;
case NOT_EMPTY:
assertThat(error.metadata)
.isNotSameAs(expectedMetadata)
.isEqualTo(expectedMetadata);
Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
error.metadata.put("can't modify", "me");
}
});
assertThat(ex).isInstanceOf(UnsupportedOperationException.class);
break;
default:
throw new IllegalArgumentException("Unhandled case: " + metadataArgOption);
}
}
示例11: ProjectApiErrorsTestBase
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void findRandomApiErrorWithHttpStatusCode_throws_IllegalStateException_if_it_cannot_find_error_with_specified_status_code() {
// given
final ProjectApiErrorsTestBase base = new ProjectApiErrorsTestBase() {
@Override
protected ProjectApiErrors getProjectApiErrors() {
return ProjectApiErrorsForTesting.withProjectSpecificData(null, null);
}
};
// when
Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
base.findRandomApiErrorWithHttpStatusCode(42424242);
}
});
// then
assertThat(ex).isInstanceOf(IllegalStateException.class);
}
示例12: getOwnerClass_throws_IllegalArgumentException_if_AnnotatedElement_is_not_Member_or_Class
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void getOwnerClass_throws_IllegalArgumentException_if_AnnotatedElement_is_not_Member_or_Class() {
// given
final AnnotatedElement notMemberOrClass = mock(AnnotatedElement.class);
// when
Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
ReflectionBasedJsr303AnnotationTrollerBase.getOwnerClass(notMemberOrClass);
}
});
// then
assertThat(ex).isInstanceOf(IllegalArgumentException.class);
}
示例13: extractMessageFromAnnotation_throws_wrapped_RuntimeException_if_annotation_blows_up
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void extractMessageFromAnnotation_throws_wrapped_RuntimeException_if_annotation_blows_up() {
// given
RuntimeException exToThrow = new RuntimeException("kaboom");
final Annotation annotation = mock(Annotation.class);
doThrow(exToThrow).when(annotation).annotationType();
// when
Throwable actual = catchThrowable(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
ReflectionBasedJsr303AnnotationTrollerBase.extractMessageFromAnnotation(annotation);
}
});
// then
assertThat(actual)
.isNotEqualTo(exToThrow)
.isInstanceOf(RuntimeException.class)
.hasCause(exToThrow);
}
示例14: MetadataPropertyWriter_serializeAsField_still_works_for_non_Error_objects
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void MetadataPropertyWriter_serializeAsField_still_works_for_non_Error_objects() throws Exception {
// given
final MetadataPropertyWriter mpw = new MetadataPropertyWriter(mock(BeanPropertyWriter.class));
// when
Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
mpw.serializeAsField(new Object(), mock(JsonGenerator.class), mock(SerializerProvider.class));
}
});
// then
// We expect a NPE because mocking a base BeanPropertyWriter is incredibly difficult and not worth the effort.
assertThat(ex).isInstanceOf(NullPointerException.class);
}
示例15: SmartErrorCodePropertyWriter_serializeAsField_still_works_for_non_Error_objects
import org.assertj.core.api.ThrowableAssert; //导入依赖的package包/类
@Test
public void SmartErrorCodePropertyWriter_serializeAsField_still_works_for_non_Error_objects() throws Exception {
// given
final SmartErrorCodePropertyWriter secpw = new SmartErrorCodePropertyWriter(mock(BeanPropertyWriter.class));
// when
Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
secpw.serializeAsField(new Object(), mock(JsonGenerator.class), mock(SerializerProvider.class));
}
});
// then
// We expect a NPE because mocking a base BeanPropertyWriter is incredibly difficult and not worth the effort.
assertThat(ex).isInstanceOf(NullPointerException.class);
}