Closed
Description
the second assertion will fail
@Test
public void test_trycatch_contract() {
JavaClasses classes = new ClassFileImporter().importClasses(ClassWithTryCatchInLambda.class);
List<JavaMethodCall> calls = classes.stream()
.flatMap(cls -> cls.getMethodCallsFromSelf().stream())
.filter(call -> "parseDouble".equals(call.getName()))
.collect(Collectors.toList());
Assertions.assertFalse(calls.isEmpty());
List<TryCatchBlock> tryBlocks =
calls.stream().flatMap(call -> call.getContainingTryBlocks().stream()).collect(Collectors.toList());
Assertions.assertFalse(tryBlocks.isEmpty());
}
private class ClassWithTryCatchInLambda {
public void testCall() {
testFunctionInterface(text -> {
try {
Double.parseDouble(text);
} catch (NumberFormatException e) {
e.printStackTrace();
}
});
}
private void testFunctionInterface(Consumer<String> func) {
func.accept("123456");
}
}