Skip to content

Commit

Permalink
Test status quo for void method references passed to assertThrows()
Browse files Browse the repository at this point in the history
Issue: #1576
  • Loading branch information
sbrannen committed Sep 9, 2018
1 parent a6c15fc commit 8fe944b
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ void assertThrowsWithFutureMethodReference() {
assertEquals("boom", exception.getCause().getMessage());
}

@Test
void assertThrowsWithMethodReferenceForVoidReturnType() {
var object = new Object();
IllegalMonitorStateException exception;

// 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 java.lang.Object.wait(...)
//
// exception = assertThrows(IllegalMonitorStateException.class, object::wait);

// Current compiler's type inference
exception = assertThrows(IllegalMonitorStateException.class, object::notify);
assertNotNull(exception);

// Explicitly as an Executable
exception = assertThrows(IllegalMonitorStateException.class, (Executable) object::notify);
assertNotNull(exception);
}

// --- executable ----------------------------------------------------------

@Test
Expand Down

0 comments on commit 8fe944b

Please sign in to comment.