-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Assert.fail usage with AssertJ fluent testing #6029
Conversation
@@ -37,178 +34,110 @@ private CustomCheckedException(String message) { | |||
@Test | |||
public void testRunSafely() { | |||
CustomCheckedException exc = new CustomCheckedException("test"); | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to admit that the original test code was quite difficult to read, so I tried to simplify it to the bare minimum
0ba187a
to
ac040a6
Compare
ac040a6
to
a06939c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love it!
"Validation should complain about missing field", | ||
e.getMessage().contains("Cannot find field 'missing' in struct:")); | ||
} | ||
Assertions.assertThatThrownBy(() -> unbound.bind(struct)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this was so old it predated adding the assertThrows
methods!
"test finally suppression", | ||
finallySuppressed.getMessage()); | ||
} | ||
Exception suppressedOne = new Exception("test catch suppression"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a lot better.
Assertions.assertThatThrownBy( | ||
() -> | ||
glueCatalog.createNamespace( | ||
Namespace.of("denied_" + UUID.randomUUID().toString().replace("-", "")))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, it would be better to put the namespace in a variable to avoid such awkward auto formatting.
|
||
Namespace namespace = Namespace.of("allowed_" + UUID.randomUUID().toString().replace("-", "")); | ||
try { | ||
glueCatalog.createNamespace(namespace); | ||
} catch (GlueException e) { | ||
LOG.error("fail to create or delete Glue database", e); | ||
Assert.fail("create namespace should succeed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the idea here that the whole test will fail so we don't need to assert?
Assert.assertEquals(message + ", http code", httpCode, e.getHttpCode()); | ||
Assert.assertEquals(message + ", error code", errorCode, e.getErrorCode()); | ||
} | ||
Assertions.assertThatThrownBy(task::run) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems more complicated than the original try/catch. Not sure it's worth it.
@@ -94,7 +95,7 @@ public void testWriteOption() throws Exception { | |||
writer.add(record2); | |||
} | |||
|
|||
Class clazzFileDump = Class.forName("org.apache.orc.tools.FileDump"); | |||
Class<?> clazzFileDump = Class.forName("org.apache.orc.tools.FileDump"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding these! Never good to have types without parameters.
Thanks, @nastra! |
This replaces a bunch of code of the form
There are still a few legit places left that use
Assert.fail()
so I didn't create a checkstyle rule to prevent usage