简体   繁体   English

ByteBuffer 模拟允许所有调用,但我没有将 JMOCK 设置为允许它

[英]ByteBuffer mock allows all calls but I didn't set JMOCK to alow it

I have an issue with JMOCK 2.6 and JUINT4 when mocking ByteBuffer我在模拟 ByteBuffer 时遇到了 JMOCK 2.6 和 JUINT4 的问题

@RunWith(JUnit4.class)
public class Test {

    @Rule
    public JUnitRuleMockery context = new JUnitRuleMockery() {
        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };

    @Before
    public void setUp() throws Exception {
    }

    @org.junit.Test
    public void testMockByteBuffer() {
        final java.nio.ByteBuffer byteBufferMock = context.mock(java.nio.ByteBuffer.class);
        byteBufferMock.remaining();
    }

}

I expected the test to fail, but it passes.我预计测试会失败,但它通过了。

Just realized I can't mock final methods.刚刚意识到我不能模拟最终方法。 java.nio.ByteBuffer.remaining() declared as final. java.nio.ByteBuffer.remaining() 声明为 final。

from: http://jmock.org/mocking-classes.html来自: http : //jmock.org/mocking-classes.html

If you want to mock final classes or final methods, the JDave library includes an unfinalizer >Instrumentation agent that can unfinalise classes before they are loaded by the JVM.如果您想模拟 final 类或 final 方法,JDave 库包含一个 unfinalizer >Instrumentation 代理,它可以在类被 JVM 加载之前取消终结类。 They can then be >mocked by the ClassImposteriser.然后它们可以被 ClassImposteriser > 模拟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM