下面的测试似乎表明@Capturing
不适用于lambdas。也就是说,当lambda
测试通过时,下面的anonymousClass
测试失败:
@RunWith(JMockit.class)
public class CapturingTest {
public interface Foo {
int get();
}
@Test
public void lambda(@Capturing final Foo unused) {
// this test fails.
// an UnsupportedOperationException is thrown
final Foo foo = () -> {
throw new UnsupportedOperationException();
};
assertThat(foo.get(), equalTo(0));
}
@Test
public void anonymousClass(@Capturing final Foo unused) {
final Foo foo = new Foo() {
@Override
public int get() {
throw new UnsupportedOperationException();
}
};
assertThat(foo.get(), equalTo(0));
}
}
JMockit v1.17