You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "Zhaohui Wang (Jira)" <ji...@apache.org> on 2024/01/25 03:04:00 UTC

[jira] [Commented] (HDDS-9956) Simplify tests using assertThrows

    [ https://issues.apache.org/jira/browse/HDDS-9956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17810635#comment-17810635 ] 

Zhaohui Wang commented on HDDS-9956:
------------------------------------

Hi [~adoroszlai] , If you don't mind, I'll continue working on this issue. If you want to do it first, feel free to reassign it to you. Thanks.

> Simplify tests using assertThrows
> ---------------------------------
>
>                 Key: HDDS-9956
>                 URL: https://issues.apache.org/jira/browse/HDDS-9956
>             Project: Apache Ozone
>          Issue Type: Improvement
>          Components: test
>            Reporter: Attila Doroszlai
>            Assignee: Attila Doroszlai
>            Priority: Major
>
> Tests of the following form can be simplified:
> {code}
> try {
>   <some action>
>   fail()
> } catch (Exception e) {
>   assertTrue(e instanceof <SpecificException>)
>   <further assertions>
> }
> {code}
> to:
> {code}
> Exception e = assertThrows(<SpecificException>.class,
>     () -> <some action>);
> <further assertions>
> {code}
> {{e}} can be declared as {{<SpecificException>}} if its specific properties need to be verified (e.g. {{OMException#getResult()}}).  Otherwise I suggest using {{Exception}} for shorter and more uniform code.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org