From f445e5c1e744ece68f04830aedc0931aecb210a2 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 7 Sep 2018 17:38:49 +0200 Subject: [PATCH] Test status quo for void method references passed to assertDoesNotThrow() Issue: #1576 --- .../AssertDoesNotThrowAssertionsTests.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/api/AssertDoesNotThrowAssertionsTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/api/AssertDoesNotThrowAssertionsTests.java index ba64bf9920fa..43a9aa7904cf 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/api/AssertDoesNotThrowAssertionsTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/api/AssertDoesNotThrowAssertionsTests.java @@ -55,6 +55,24 @@ void assertDoesNotThrowWithFutureMethodReference() { assertEquals("foo", result); } + @Test + void assertDoesNotThrowWithMethodReferenceForVoidReturnType() { + var foo = new Foo(); + + // Note: the following does not compile since the compiler cannot properly + // perform type inference for a method reference for an overloaded method + // that has a void return type such as Foo.overloaded(...) + // + // assertDoesNotThrow(foo::overloaded); + + // Current compiler's type inference + assertDoesNotThrow(foo::normalMethod); + + // Explicitly as an Executable + assertDoesNotThrow((Executable) foo::normalMethod); + assertDoesNotThrow((Executable) foo::overloaded); + } + // --- executable ---------------------------------------------------------- @Test @@ -221,4 +239,19 @@ void assertDoesNotThrowWithSupplierThatThrowsAnExceptionWithMessageSupplier() { } } + // ------------------------------------------------------------------------- + + private static class Foo { + + void normalMethod() { + } + + void overloaded() { + } + + void overloaded(int i) { + } + + } + }