@Capturing为lambdas工作吗?

时间:2016-02-12 14:39:56

标签: java java-8 jmockit

下面的测试似乎表明@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

0 个答案:

没有答案