When I trying to run this one - all works as expected and test successfully passes:
@Test
public void shouldThrowNPE() {
@SuppressWarnings("OptionalAssignedToNull") Optional<String> nullOptional = null;
Assertions.assertThrows(NullPointerException.class, () -> nullOptional.isEmpty());
}
But for this one when I change lambda to method reference I receive NPE and test fails:
@Test
public void shouldThrowNPE() {
@SuppressWarnings("OptionalAssignedToNull") Optional<String> nullOptional = null;
Assertions.assertThrows(NullPointerException.class, nullOptional::isEmpty);
}
Could someone give a hint what's wrong here.