Powermock: Unexpected method call expected: 1, actual: 0

Created on 25 Jul 2015  路  3Comments  路  Source: powermock/powermock

_From [email protected] on December 23, 2013 12:01:15_

I have a external api method getDefinedOnNodesByType, which takes five arguments [int, long, long[], String[], Offset] and returns Map[], where Offset is always null in my case.

I created a mock and set the Expectation as follows: EasyMock .expect(polapi.getDefinedOnNodesByType( EasyMock .eq(1012928), EasyMock .eq(0), EasyMock .aryEq(new long[]{13487148}), EasyMock .aryEq(new String[]{"IpsSensorUpdate"}), EasyMock .eq((Offset)null))).andReturn((Map[])null);

and I call the method to be tested which calls the same method with same arguments. However i get Unexpected method call every time. Am i doing something wrong?

java.lang.AssertionError:
Unexpected method call PolicyApi.getDefinedOnNodesByType(1012928, 0, [13487148], ["IpsSensorUpdate"], null):
PolicyApi.getDefinedOnNodesByType(1012928, 0, [13487148], ["IpsSensorUpdate"], null): expected: 1, actual: 0
at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:44)
at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:85)
at com.sun.proxy.$Proxy11.getDefinedOnNodesByType(Unknown Source)
at com.client.nm.vms.ips.device.update.SensorUpdateUtils.getIpsSettingPolicy(SensorUpdateUtils.java:184)
at com.client.nm.vms.ips.device.update.SensorUpdateUtilsTest.testGetIpsSettingPolicySuccess(SensorUpdateUtilsTest.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:118)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:101)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:53)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

_Original issue: http://code.google.com/p/powermock/issues/detail?id=473_

Medium bug imported

Most helpful comment

_From [email protected] on December 23, 2013 20:29:55_

Found the problem. Were giving EasyMock .eq(0) instead of EasyMock .eq(0L). Note the method takes long as an argument whereas the default 0 is an integer. Not noticing that I did initialize the long[] separately as

long longarr = new long[]{ EasyMock .eq(13487148)}; 

So were getting the second exception.
Hope this helps someone.

Thanks

All 3 comments

_From [email protected] on December 23, 2013 05:57:06_

I really am looking for some inputs. Please help!

_From [email protected] on December 23, 2013 20:06:08_

Further debugging gave me the exception in Powermock saying org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException: Type has not been loaded occurred while retrieving component type of array.

This happens only when the actual function is called. Not while setting the expectation.

Any clues on this?

_From [email protected] on December 23, 2013 20:29:55_

Found the problem. Were giving EasyMock .eq(0) instead of EasyMock .eq(0L). Note the method takes long as an argument whereas the default 0 is an integer. Not noticing that I did initialize the long[] separately as

long longarr = new long[]{ EasyMock .eq(13487148)}; 

So were getting the second exception.
Hope this helps someone.

Thanks

Was this page helpful?
0 / 5 - 0 ratings