代码覆盖似乎不适用于使用@FunctionalInterface的断言

时间:2019-03-21 14:21:35

标签: java lambda code-coverage functional-interface

在此功能中:

private void assertAssurancesMissing(Vote vote) {
    assertThrows(
            () -> voteManager.showVote(vote.id, "user")
        ).assertMessageIs("missing assurances");
}

带有lambda函数的第三行在Eclipse的代码覆盖率输出中显示为黄色。同样,showVote()方法也没有覆盖。

包含assertThrows的类的相关部分:

public class ThrowableTester {
  private Throwable thrown;

  public ThrowableTester assertThrows(Thrower thrower) {
    thrown = null;
    try {
        thrower.throwException();
    } catch (Throwable exception) {
        thrown = exception;
    }
    if (thrown == null) {
        fail("no exception thrown");            
    }
    return this;
  }

}

Thower如下所示:

@FunctionalInterface
public interface Thrower {
    void throwException() throws Throwable;
}

我非常确定代码确实在测试中运行,因此必须与lambda函数或@FunctionalInterface一起执行。

如何修改覆盖率报告?

0 个答案:

没有答案