trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.34k stars 2.98k forks source link

Change tests not to use "fail() + catch" pattern #6553

Open findepi opened 3 years ago

findepi commented 3 years ago

Some tests use the following pattern

try {
    ... do something ...
    fail();
}
catch (IllegalStateException e) {
    assertEquals(e.getMessage(), "the expected message");
}

this is not very readable and can be expressed more tersely with assertThatThrownBy also, in case the message not as expected, the actual failure gets lots, so it's harder to diagnose the problem

find all occurrences of such pattern and migrate to assertThatThrownBy see https://github.com/trinodb/trino/pull/6554 for example of such migration

choiwaiyiu commented 3 years ago

Hi @findepi May I work on this?

findepi commented 3 years ago

@choiwaiyiu sure, thank you!

findepi commented 3 years ago

please make sure to have a look at https://github.com/trinodb/trino/pull/6554 to see how some of the code places have been updated recently.

MariyaR commented 3 years ago

Hello @findepi, does @choiwaiyiu still work on that issue or I can try?

findepi commented 3 years ago

@MariyaR hopefully @choiwaiyiu will clarify that. If not, please feel free to go ahead.

choiwaiyiu commented 3 years ago

@MariyaR @findepi Sorry for my slow progress. I have already started working on this issue and will create a pull request soon.

findepi commented 3 years ago

@choiwaiyiu no worries and thanks for info!

Also, thank you for your #6767 PR! @MariyaR do you want to help review this?

ebyhr commented 3 years ago

@findepi Should we prohibit fail() by modernizer?

findepi commented 3 years ago

I think there are legitimate cases where verifying some condition.

We shouldn't need to

assertTrue(some condition);

as

if (! some condition) {
  fail("good message");
}

reads better.

Of course, we could use throw new AssertionError in these cases, but we should make sure we have an agreement on this first.

MariyaR commented 3 years ago

@findepi yes, I would like to help with review

findepi commented 3 years ago

https://github.com/trinodb/trino/pull/6767 is merged. @choiwaiyiu can you please do another check whether there is anything remaining and close the issue? thanks!

choiwaiyiu commented 3 years ago

@findepi Here are the remaining "fail() + catch" pattern.

- trino-spi

- TestUnscaledDecimal128Arithmetic - https://github.com/trinodb/trino/blob/master/core/trino-spi/src/test/java/io/trino/spi/type/TestUnscaledDecimal128Arithmetic.java#L631-L644

rnzucker commented 3 years ago

Since choiwaiyiu moved this back to Open, I assume that there is still work to do here? I wasn't sure if choiwaiyiu's Mar. 22nd update means that there are still cases to fix.

Faizankhan1104 commented 2 years ago

Hello, @findepi I would like to start my contribution to this issue. Can I pick this up??