JDK 9 RFR of JDK-8023897: Replace/update/rename executeAndCatch in various tests to assertThrows
Amy Lu
amy.lu at oracle.com
Wed May 3 04:18:47 UTC 2017
Thank you Pavel, Paul, Roger and Daniel for your reviewing.
On 5/3/17 5:02 AM, Roger Riggs wrote:
> But ": Must throw ClassCastException for parameter which is not
> Comparable."
> in Empty navigableMap is much more useful.
>
> And wrapping exceptions in exceptions makes debugging much harder,
> because
> it requires unwrapping the context and figuring out what the test was
> trying to
> do and which was the relevant source line.
As the message and exception trace are all kept, it won't make debugging
harder.
For example for EmptyNavigableMap.java:
No exception case:
assertThrowsCCE(
() -> {},
description + ": Must throw ClassCastException for
parameter which is not Comparable.");
The output:
test
EmptyNavigableMap.testSubMap("emptyNavigableMap().descendingMap().descendingMap()",
{}): failure
java.lang.AssertionError:
emptyNavigableMap().descendingMap().descendingMap(): Must throw
ClassCastException for parameter which is not Comparable.
Expected ClassCastException to be thrown, but nothing was thrown
at EmptyNavigableMap.assertThrows(EmptyNavigableMap.java:76)
at EmptyNavigableMap.assertThrowsCCE(EmptyNavigableMap.java:82)
at EmptyNavigableMap.testSubMap(EmptyNavigableMap.java:227)
...
Caused by: java.lang.AssertionError: Expected ClassCastException to be
thrown, but nothing was thrown
at org.testng.Assert.expectThrows(Assert.java:1018)
at org.testng.Assert.assertThrows(Assert.java:989)
at EmptyNavigableMap.assertThrows(EmptyNavigableMap.java:74)
... 17 more
Wrong exception case:
assertThrowsCCE(
() -> {
throw new NullPointerException();
},
description + ": Must throw ClassCastException for
parameter which is not Comparable.");
The output:
test
EmptyNavigableMap.testSubMap("emptyNavigableMap().descendingMap().descendingMap()",
{}): failure
java.lang.AssertionError:
emptyNavigableMap().descendingMap().descendingMap(): Must throw
ClassCastException for parameter which is not Comparable.
Expected ClassCastException to be thrown, but NullPointerException was
thrown
at EmptyNavigableMap.assertThrows(EmptyNavigableMap.java:76)
at EmptyNavigableMap.assertThrowsCCE(EmptyNavigableMap.java:82)
at EmptyNavigableMap.testSubMap(EmptyNavigableMap.java:227)
...
Caused by: java.lang.AssertionError: Expected ClassCastException to be
thrown, but NullPointerException was thrown
at org.testng.Assert.expectThrows(Assert.java:1013)
at org.testng.Assert.assertThrows(Assert.java:989)
at EmptyNavigableMap.assertThrows(EmptyNavigableMap.java:74)
... 17 more
>
> I should probably try to file a bug against TestNG.assertThrows to add
> a variant with
> a message. Many/most of the TestNG asserts have variants with messages.
Good point!
> - java/util/Map/Defaults.java:167 The {}'s around the lambda value
> are not necessary (like 166).
I'll remove it when push.
Thanks,
Amy
More information about the core-libs-dev
mailing list