0

I am using a Retrier class to retry failed tasks. My code looks something like this. I have mocked Retrier class in my testcase using Mockito

someMethod() {
 Callable a = new TestingCall()
 Retrier.call(a, arg2, arg3)
 .....
}

my test code looks something like this.

testMymethod()
 // mock(Retrier.class)
 when(Retrier.call(any(Callable.class), anyObject(), anyObject()).thenAnswer(new  Answer<Boolean>() {
@Override
    public Boolean answer(InvocationOnMock invocation) throws Throwable {
      return true;
    }
});

But when I run the test, it throws a null pointer Exception in Retrier.call

Retrier.call uses the passed arguments which is coming as null hence the NPE.

Note: I have tried passing something like this too.

when(Retrier.call(any(Callable.class), any(arg2.Class), any(arg3.Class) where arg2 and arg3 are mocked too.

Any thoughts about this error? Or another way of doing it successfully?

jigsaw
  • 165
  • 1
  • 16
  • if `Retrier.call` is a static call, this doesn't work because Mockito does **not** work with static. Also what is `arg2.Class` (uppercase C on class?) –  Apr 07 '15 at 06:01
  • That was a typo. It is .class(lowercase). It is static. If I change it to non static, will this work?If not ,what is the alternate solution? – jigsaw Apr 07 '15 at 06:10
  • You should post the whole classes (Retrier and the one sporting `someMethod`). –  Apr 07 '15 at 08:58

1 Answers1

-1

You need to use PowerMock with Mockito in order to mock the static methods:

bedrin
  • 4,458
  • 32
  • 53