• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PowerMock: StackOverFlow

 
sam backet
Greenhorn
Posts: 22
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have the following problem:

I wanted to mock a private method in a class.

(1) ORIGINAL


(2) TEST

(3) Error, when the Test calls "green.processStep()"


java.lang.StackOverflowError

at java.lang.reflect.Method.<init>(Method.java:116)
at java.lang.reflect.Method.copy(Method.java:143)
at java.lang.reflect.ReflectAccess.copyMethod(ReflectAccess.java:118)
at sun.reflect.ReflectionFactory.copyMethod(ReflectionFactory.java:
282)
at java.lang.Class.copyMethods(Class.java:2748)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at org.powermock.reflect.internal.WhiteboxImpl
$3.run(WhiteboxImpl.java:1608)
at org.powermock.reflect.internal.WhiteboxImpl
$3.run(WhiteboxImpl.java:1605)
at java.security.AccessController.doPrivileged(Native Method)
at
org.powermock.reflect.internal.WhiteboxImpl.getAllMethods(WhiteboxImpl.java:
1605)
at
org.powermock.reflect.internal.WhiteboxImpl.getMethods(WhiteboxImpl.java:
1888)
at
org.powermock.reflect.internal.WhiteboxImpl.getMethods(WhiteboxImpl.java:
1931)
at
org.powermock.reflect.internal.WhiteboxImpl.getBestMethodCandidate(WhiteboxImpl.java:
1025)
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:89)

and a Part that has repeated itself...

at org.powermock.core.MockGateway.methodCall(MockGateway.java:168)
at
de.affinitas.billing.service.api.processor.AbstractPaymentOptionProcessor.equals(AbstractPaymentOptionProcessor.java)
at
org.mockito.internal.invocation.InvocationMatcher.matches(InvocationMatcher.java:
57)
at
org.mockito.internal.stubbing.InvocationContainerImpl.findAnswerFor(InvocationContainerImpl.java:
72)
at org.mockito.internal.MockHandler.handle(MockHandler.java:93)
at
org.powermock.api.mockito.internal.invocationcontrol.MockitoMethodInvocationControl.performIntercept(MockitoMethodInvocationControl.java:
291)
at
org.powermock.api.mockito.internal.invocationcontrol.MockitoMethodInvocationControl.invoke(MockitoMethodInvocationControl.java:
193)
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:105)
at org.powermock.core.MockGateway.methodCall(MockGateway.java:168)
at
de.affinitas.billing.service.api.processor.AbstractPaymentOptionProcessor.equals(AbstractPaymentOptionProcessor.java)
at
org.mockito.internal.invocation.InvocationMatcher.matches(InvocationMatcher.java:
57)
at
org.mockito.internal.stubbing.InvocationContainerImpl.findAnswerFor(InvocationContainerImpl.java:
72)
at org.mockito.internal.MockHandler.handle(MockHandler.java:93)
at
org.powermock.api.mockito.internal.invocationcontrol.MockitoMethodInvocationControl.performIntercept(MockitoMethodInvocationControl.java:
291)
at
org.powermock.api.mockito.internal.invocationcontrol.MockitoMethodInvocationControl.invoke(MockitoMethodInvocationControl.java:
193)
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:105)



What's the problem?

Thanks

michael

 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Neither of your classes will compile as they are. How can you expect help if your examples are littered with compilation errors...

Sean
 
sam backet
Greenhorn
Posts: 22
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's difficult to reproduce the problem, because I'm working with many, complex classes.

Can you give me an idea, what can be wrong?

michael
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34218
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sam backet wrote:it's difficult to reproduce the problem, because I'm working with many, complex classes.

Can you give me an idea, what can be wrong?

michael

The first step to solving a problem like this is often to try to find the simplest case that can reproduce it. Try removing code until the error goes away; then re-add the last thing. That gives a clue as to the space the problem is in and is something more concrete to ask about.
 
sam backet
Greenhorn
Posts: 22
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok I have developed an example. The problem is the method "equal". If I delete it, it works and if I add it , the response is an error "StackOverFlow". But I need the method.












You can get it via mail.

Thanks

Sam
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I don't understand your example, your GreenPayment class doesn't call the private authorise() method...?

Also don't do this:
Silently getting rid of exceptions is almost always bad, you should at least be printing out the exception, although in your case I'm not even sure why you have the try/catch there.

Finally I recommend you test that the private method is being called once at the end (as in your example it's not being called):
Sean
 
sam backet
Greenhorn
Posts: 22
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the "autorise"call is not the problem. it throw the exception, when the program tries to call the "processStep"

and in that case.. I got the error, which I have written above. -> StackOverflow
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Looks like your error is related to this: http://code.google.com/p/powermock/issues/detail?id=88.

As a note, if you remove the final keyword from your equals() method then your code runs fine.
Sean
 
sam backet
Greenhorn
Posts: 22
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, it works, but why....?

thanks ..

sam
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34218
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why, but I suspect the mock object framework is subclassing your object and "changing things."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic