2

I have a static method in a class. the method is not final. I keep getting a when() requires an argument which has to be 'a method call on a mock' error. Below is my code.

mockStatic(HomefeedExperimentUtils.class);

when(HomefeedExperimentUtils.getGroupAndActivateExperiment(
    "link_stock_signal_filter_exp")).thenReturn(
    "treatment");

I've also tried:

HomefeedExperimentUtils mock = org.mockito.Mockito.mock(HomefeedExperimentUtils.class);

when(mock.getGroupAndActivateExperiment(
    "link_stock_signal_filter_exp")).thenReturn(
    "treatment");

Any help with be appreciated.

Thanks!

Kinnary Jangla
  • 123
  • 1
  • 6

1 Answers1

0

Mockito is not able perform static mocking, use PowerMock to extend their capability and achieve that.

https://github.com/powermock/powermock/wiki