0

I am trying to run just a simple test using easyMock:

public class Class1 implements Interface1{
    public void method1(Object obj){
       if(isEnable()){
    doSmth();
    }
    }

    public boolean isEnable(){
    return isEnable;
    }
}

My test:

Interface1 test1= Interface1(Class1.class);
test1.method1(anyObject);
expectLastCall();
expect(test1.isEnable).andReturn(true);
replay(test1);

test1.method1(new Object());
verify(test1);

Error:

Expectation failure on verify: isEnable(): expected: 1, actual: 0

Where is the problem? I have read tons of examples where there are similar problems with the parameters sent, but not a method without params example1 or this tutorial, that I found interesting

Thanks in advance

Blanca Hdez
  • 3,513
  • 19
  • 71
  • 93

1 Answers1

0

Change the mocking code little bit. You are wanting to call a method isEnable and return true.

Interface1 test1= Interface1(Class1.class);
test1.method1(anyObject);
expectLastCall();
expect(test1.isEnable()).andReturn(true);
replay(test1);

Change you actual test to

test1.method1(new Object());
test1.isEnable();
verify(test1);
randominstanceOfLivingThing
  • 16,873
  • 13
  • 49
  • 72