-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Issue #9142: finalize #11151
Issue #9142: finalize #11151
Conversation
@@ -75,7 +73,9 @@ public void testLoadFromUrl() throws Exception { | |||
} | |||
} | |||
|
|||
assumeTrue(actualFilterSet != null, "No Internet connection."); |
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.
assumeXXX should not be replaced with an assert.
This test requires an internet connection, which may not be available.
This can be replaced with if
, but an assume
method is better, since it will output the reason to the tests log.
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 am not understanding why it can't be replaced. Can you provide clarification on why we can't use assert here?
Why aren't the 2 equal?
assumeTrue(variable, "Text");
assertWithMessage("Text").that(variable).isTrue();
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.
false conditions in assume
methods will not break the build. It simply reports that the test is ignored due to "Text".
false condition in assert
methods will break the build.
@@ -223,7 +222,9 @@ public void testFinishLocalSetup() { | |||
@Test | |||
public void testLanguageIsValid() { | |||
final String language = DEFAULT_LOCALE.getLanguage(); | |||
assumeFalse(language.isEmpty(), "Locale not set"); | |||
assertWithMessage("Locale not set") |
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.
same
@@ -235,7 +236,9 @@ public void testLanguageIsValid() { | |||
@Test | |||
public void testCountryIsValid() { | |||
final String country = DEFAULT_LOCALE.getCountry(); | |||
assumeFalse(country.isEmpty(), "Locale not set"); | |||
assertWithMessage("Locale not set") |
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.
same
@@ -248,8 +251,9 @@ public void testCountryIsValid() { | |||
@Test | |||
public void testLocaleIsSupported() throws Exception { | |||
final String language = DEFAULT_LOCALE.getLanguage(); | |||
assumeFalse(language.isEmpty() || Locale.ENGLISH.getLanguage().equals(language), | |||
"Custom locale not set"); | |||
assertWithMessage("Custom locale not set") |
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.
same
@@ -251,22 +250,28 @@ protected final void verify(Checker checker, | |||
for (int i = 0; i < expected.length; i++) { | |||
final String expectedResult = messageFileName + ":" + expected[i]; | |||
final String actual = lnr.readLine(); | |||
assertEquals(expectedResult, actual, "error message " + i); | |||
assertWithMessage("error message " + i) |
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.
It is better to use formatted message here:
assertWithMessage("error message %s", i)
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.
What is better about it? The readability or is there some performance?
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.
Both assertWithMessage("error message %s", i)
and `assertWithMessage("error message " + i) have the same readability and performance.
The difference is that "error message " + i
is actually String.concat("error message "), i.toString())
. And this .toString()
method can (in theory) have side effects. For example, it may throw an NPE, which will cause the test to fail for no clear reason.
This is absolutely inapplicable to any primitive type such as int
, but this is a style issue. If we all agree to use this style, it will avoid possible problems in the future.
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.
What about #11151 (comment) ?
|| theWarnings.remove((Integer) lineNumber), | ||
"input file is expected to have a warning comment on line number " | ||
+ lineNumber); | ||
assertWithMessage("input file is expected to have a warning comment on line number " |
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.
same
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.
One minor change please
assertEquals(expected.length, | ||
errs, "unexpected output: " + lnr.readLine()); | ||
assertEquals(0, theWarnings.size(), "unexpected warnings " + theWarnings); | ||
assertWithMessage("unexpected output: " + lnr.readLine()) |
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.
same
assertWithMessage("unexpected output: " + lnr.readLine()) | ||
.that(errs) | ||
.isEqualTo(expected.length); | ||
assertWithMessage("unexpected warnings " + theWarnings) |
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.
same
@@ -154,7 +153,8 @@ public void testGetAccessModifierFromModifiersTokenWrongTokenType() { | |||
|
|||
try { | |||
CheckUtil.getAccessModifierFromModifiersToken(modifiers); | |||
fail(IllegalArgumentException.class.getSimpleName() + " was expected."); | |||
assertWithMessage(IllegalArgumentException.class.getSimpleName() + " was expected.") |
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.
same
if (!node.isPresent()) { | ||
fail("Cannot find node of specified type: " + type); | ||
} | ||
assertWithMessage("Cannot find node of specified type: " + type) |
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.
same
@pbludov all done |
Closes #9142
Doing a search on
org.junit.jupiter.api.Assertions
only provides the following results: