RFR: 8273507: Using TestNG for unit testing ChannelInputStream::transferTo

Lance Andersen lancea at openjdk.java.net
Wed Sep 8 18:56:08 UTC 2021


On Wed, 8 Sep 2021 17:17:32 GMT, Markus KARG <github.com+1701815+mkarg at openjdk.org> wrote:

> Using TestNG makes it easier to maintain and extend the unit test of ChannelInputStream::transferTo.
> 
> This change was proposed by Brian Burkhalter @blbp and requested Alan Bateman @AlanBateman.
> 
> *Note: A further test addition (testing 2GB+ transfers) will be added by me in a subsequent PR using TestNG once *this* PR is merged. This will need a while due to personal scheduling, also the topics are not necessarily related, hence there are separate PRs.*

Look better overall.

I would add a comment for for each DataProvider/Test to give future maintainers an overview of the intent of the methods

A couple of additional comments below

Best
Lance

test/jdk/java/nio/channels/Channels/TransferTo.java line 75:

> 73:     }
> 74: 
> 75:     @Test(dataProvider = "streamCombinations", expectedExceptions = NullPointerException.class)

We have been moving away from using the  expectedExceptions annotation element and using the assertThrows method instead, example:

assertThrows(NullPointerException.class, () -> inputStreamProvider.input().transferTo(null));

test/jdk/java/nio/channels/Channels/TransferTo.java line 135:

> 133: 
> 134:             if (reported != count)
> 135:                 fail(format("reported %d bytes but should report %d", reported, count));

I would consider using

 assertTrue( reported == count, format("reported %d bytes but should report %d", reported, count));

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

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


More information about the nio-dev mailing list