Closed Segelzwerg closed 4 years ago
Shouldn't it transform to this?
@SneakyThrows
@Test
void testIndex() {
//
}
I think we can use it, but it is not really better than the throws clause 🤔
yes, was a bad copy and paste. I think the advantage is you acknowledge it is bit ugly and you didn't add the throw by mistake
This is a bad use case for @SneakyThrows
.
The intended use cases are listed here.
They boil down to this: You have to do exception handling in a function because something is throwing an unchecked exception but...
...and you don't want to deal with unnecessary syntax (try-catch with rethrow or swallow).
We have full control over the test methods and the exceptions that can arise are all valid and possible. So it is enough to just declare the methods as throws T
. @SneakyThrows
gives no extra value.
I see, thanks for clearing that up @iTitus. Maybe I spent to much time annotating stuff :wink:
I have a idea for code quality. I found this lombok annotation
@SneakyThrows
. From lombok documentation:We could use this on our controller tests EDIT:
instead of
https://github.com/n2o/url-shortener/blob/a90ac854c324b5521b6e927bf0964d66b2d94cd7/src/test/java/de/hhu/propra/link/controllers/LinkControllerTest.java#L29-L34
what do you think @n2o @iTitus