PowerMock を使用して次のコードをモックしたかったのです。
ConnectionFactory rabbitMqFactory = createFactory();
com.rabbitmq.client.Connection connection = rabbitMqFactory.newConnection();
com.rabbitmq.client.Channel channel = con.createChannel();
com.rabbitmq.client.QueueingConsumer consumer = new com.rabbitmq.client.QueueingConsumer(channel);
ただし、QueueingConsumer を expectNew としてモックすると、次のようになります。
@RunWith(PowerMockRunner.class)
@PrepareForTest({MyClass.class})
public class MyClassTester {
@Test
public void test() {
QueueingConsumer consumer = createMock(QueueingConsumer.class);
MyClass myClass = new MyClass();
// other code mock here ...
PowerMock.expectNew(QueueingConsumer.class, Channel.class).andReturn(consumer);
replayAll();
myClass.callRabbitMq();
verifyAll();
}
}
私は常に次の例外を受け取ります。
org.powermock.reflect.exceptions.FieldNotFoundException: No instance field of type "org.easymock.internal.MocksControl$MockType" could be found in the class hierarchy of org.easymock.internal.MocksControl.
at org.powermock.reflect.internal.matcherstrategies.FieldTypeMatcherStrategy.notFound(FieldTypeMatcherStrategy.java:40)
at org.powermock.reflect.internal.WhiteboxImpl.findSingleFieldUsingStrategy(WhiteboxImpl.java:509)
at org.powermock.reflect.internal.WhiteboxImpl.findFieldInHierarchy(WhiteboxImpl.java:455)
at org.powermock.reflect.internal.WhiteboxImpl.getInternalState(WhiteboxImpl.java:578)
at org.powermock.api.easymock.internal.invocationcontrol.EasyMockMethodInvocationControl.getMockType(EasyMockMethodInvocationControl.java:99)
at org.powermock.api.easymock.internal.invocationcontrol.NewInvocationControlImpl.invoke(NewInvocationControlImpl.java:53)
at org.powermock.core.MockGateway.newInstanceCall(MockGateway.java:191)
理由がわかりません。私のコードに何か問題がありますか? さまざまなアプローチを使用して書き直しましたが、expectNew を使用すると常にこのエラーが発生します。それとも、これは PowerMock リリース 1.5.1 の現在の問題ですか?
-ありがとう-