RFR: 8251989: Hex formatting and parsing utility [v2]

Marcono1234 github.com+11685886+marcono1234 at openjdk.java.net
Tue Oct 13 21:52:11 UTC 2020


On Tue, 13 Oct 2020 16:15:51 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> test/jdk/java/util/HexFormat/HexFormatTest.java line 406:
>> 
>>> 404:
>>> 405:             int byteVal = hex.fromHexDigits(byteStr);
>>> 406:             assert(byteStr.equals("7f"));
>> 
>> Why use regular `assert` statements in this test method? TestNG's methods likely yield more useful results.
>
> These code fragments are the examples used in the javadoc; making a simple copy/paste from working code to the javadoc.
> In the example code `assert`, a Java language construct is cleaner than showing testng assertions).

Yes using test framework specific code in the example code is probably not a good idea and the `assert` statement there
makes the intention clear.

However, for unit tests I assume it can be a little bit problematic if the tests are compiled with assertions disabled.
Additionally if one of the `assert` statements fail you would only get an `AssertionError` without much additional
feedback, while test framework assertion methods usually provide pretty detailed messages and have good IDE support.
For example `assertEquals("a", "b")` would yield something like
> Expected "a" but was "b"

which makes it obvious what the issue is.

-------------

PR: https://git.openjdk.java.net/jdk/pull/482


More information about the core-libs-dev mailing list