[
https://issues.apache.org/jira/browse/HDDS-9956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17814149#comment-17814149
]
Zhaohui Wang commented on HDDS-9956:
------------------------------------
Hi, [~adoroszlai], I'm not sure if I understand exactly.
{code:java}
try {
<some action>
} catch (Exception e) {
fail()
}
assertTrue()
assertThat()...{code}
try-catch-fail can be replaced by
{code:java}
assertDoesNotThrow(() ->){code}
Then, there are no other assertions like this
{code:java}
public void testXXX() {
try {
<some action>
} catch (Exception e) {
fail()
}
}{code}
try-catch-fail can be removed and replaced with
{code:java}
void testXXX() throws Exception {}
{code}
Sorry, I'm not sure about description of the modification in these issues. Look
forward to your reply.
> 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]