trino: Change tests not to use "fail() + catch" pattern

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

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@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~~

@findepi yes, I would like to help with review

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.