I wanted to make fun of the following code with 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);
However, when I make fun of QueueingConsumer as expectNew:
@RunWith(PowerMockRunner.class) @PrepareForTest({MyClass.class}) public class MyClassTester { @Test public void test() { QueueingConsumer consumer = createMock(QueueingConsumer.class); MyClass myClass = new MyClass();
I always get the following exception:
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)
I just donβt understand why. Is there something wrong with my code? I rewrote it using different approaches, but I will always come up with this error when using expectNew. Or is this the current issue for PowerMock 1.5.1?
-Thanks -
source share