{ // some code }).is-6ren">
sách gpt4 ai đã đi

java - 当抛出 'Exception B'时如何断言 "Exception A: Exception B"?

In lại 作者:行者123 更新时间:2023-12-02 01:31:07 31 4
mua khóa gpt4 Nike

我想断言运行某些代码时会引发特定异常(SSLHandshakeException)。

assertThatThrownBy(() -> {
// some code
}).isInstanceOf(SSLHandshakeException.class);

但是,这失败了,因为失败跟踪显示:

java.lang.AssertionError: 
Expecting:

to be an instance of:

but was:
<"javax.ws.rs.ProcessingException: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

检查ProcessingException 可以,但是太笼统了。我需要确保代码片段由于 SSL 握手而失败。

如何更改它以考虑“第二个”异常?

1 Câu trả lời

您可以简单地使用 hasCauseInstanceOf .

关于java - 当抛出 'Exception B'时如何断言 "Exception A: Exception B"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56043940/

31 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com