Easymock指定EasyMock.expect()时出现意外的方法调用错误

时间:2017-09-11 20:58:28

标签: unit-testing mocking easymock

我一直遇到以下错误:

org.apache.kafka.connect.runtime.distributed.DistributedHerderTest > testCreateConnector FAILED
java.lang.AssertionError:
  Unexpected method call Worker.getConnectorType("sourceB"):
    Worker.getPlugins(): expected: 3, actual: 0
    at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:44)
    at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:94)
    at org.easymock.internal.ClassProxyFactory$MockMethodInterceptor.intercept(ClassProxyFactory.java:97)
    at org.apache.kafka.connect.runtime.Worker$$EnhancerByCGLIB$$124447d.getConnectorType(<generated>)
    at org.apache.kafka.connect.runtime.distributed.DistributedHerderTest.testCreateConnector(DistributedHerderTest.java:344)

即使我输入了:

    EasyMock.expect(worker.getConnectorType(CONN2)).andReturn(ConnectorType.SOURCE);

可以在此处找到代码:https://github.com/apache/kafka/pull/3812

欢迎提出建议。

1 个答案:

答案 0 :(得分:0)

您可能需要将Worker.class添加到@PrepareForTest({DistributedHerder.class, Plugins.class})