vijayjcp / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 2 forks source link

Unexpected method call expected: 1, actual: 0 #473

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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 reported on code.google.com by bsrera...@gmail.com on 23 Dec 2013 at 11:01

GoogleCodeExporter commented 8 years ago
I really am looking for some inputs. Please help!

Original comment by bsrera...@gmail.com on 23 Dec 2013 at 1:57

GoogleCodeExporter commented 8 years ago
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?

Original comment by bsrera...@gmail.com on 24 Dec 2013 at 4:06

GoogleCodeExporter commented 8 years ago
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

Original comment by bsrera...@gmail.com on 24 Dec 2013 at 4:29