Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] How to mock different returns between the first and the second invocations?

Ashish

2011-06-17

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi,
I have a method that I want to mock that has recursive call to itself. If the
method is called first (From my test) it should return say null but as the
method internally calls itself internally (the second call) it should return a
specific value.
public class A {
private Service service;
public Object lookup() {
  if (service == null) {
    service = new Service();
  }
*1:   Object o = service.getValue();
 
  while (o == null) {
    Thread.sleep (100);
*2:     o = service.getValue();
  }
  return o;
 }
}

Testing this class I used reflection to replace the service with a Mocked value.
Have set the expection that *1 returns null. But I want *2 to return some
other value. Is it possible?

Appreciate your help.




 
 




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.