Java Mailing List Archive

Home » user.jmock »

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



Replies: Find Java Web Hosting

Author LoginPost Reply
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:

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