今天在使用Junit5中的assertDoesNotThrow()方法时,idea报出了个警告,
Statement lambda can be replaced with expression lambda less… (Ctrl+F1)
Inspection Info: Reports lambda expressions with code block bodies when expression-style bodies can be used.
代码如下:
int re = assertDoesNotThrow(() -> {
return AssertTestModel.testThrowArithmeticException(2,1);
});
解决方案:
int re = assertDoesNotThrow(()->AssertTestModel.testThrowArithmeticException(2,1));
由
param -> { return expression; }
变成
param -> expression