0

I am trying to mock a private void method with parameters using Mockito as below:

MyClass clsSpy = spy(new MyClass());
doNothing().when(clsSpy, method("privateMethod", String.class, boolean.class))
    .withArguments(any(String.class), any(boolean.class));

but it is not able to find the symbol method.

I know this can be done with the help of PowerMock. But is there a way to do this using Mockito only?

Thanks in advance.

Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
Newbie
  • 2,979
  • 9
  • 34
  • 41
  • 2
    This question already has an answer here: http://stackoverflow.com/questions/8799439/testing-private-method-using-mockito – Mahesh Oct 14 '16 at 11:43
  • 1
    As properly explained [here](http://stackoverflow.com/a/8799482/1997376) no you can't mock a `private` method with `Mockito` because it should never happen unless you have a design issue in your code, it is only doable with `PowerMock`. – Nicolas Filotto Oct 14 '16 at 12:00

0 Answers0