[
https://issues.apache.org/jira/browse/HDDS-9956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17813479#comment-17813479
]
Attila Doroszlai commented on HDDS-9956:
----------------------------------------
[~wangzhaohui], good question. We can simplify it in one of two ways:
{code:title=1}
assertDoesNotThrow(() -> <some action>)
{code}
{code:title=2}
... throws Exception {
...
<some action>
}
{code}
Some code checker tools (I don't recall exactly which ones) flag test cases
without any assertions. We can use the second form if there are other
assertions. Otherwise the first form adds the assertion required by these
tools.
> 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: Zhaohui Wang
> 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: [email protected]
For additional commands, e-mail: [email protected]