0

I have problems when calling the static method of the class ManagerPageFlowScope.getInstance().getParamPageFlowScope(any(), the one that throws an error is the getInstance(), and it always returns null.

@Mock
ManagerPageFlowScope mpfs;

@Test
public void mostrarSeriesTest() {
    ArrayList<Serie> list = new ArrayList<Serie>();
    Serie s = new Serie("Test01", "N");
    Long l = Long.parseLong("59960000");
    Etiqueta e = new Etiqueta(l);
    list.add(s);
    when(mpfs.getInstance().getParamPageFlowScope("consultaSerie")).thenReturn(e);
Makoto
  • 104,088
  • 27
  • 192
  • 230
  • Mockito is very precise...if you expect specifically the string "consultaSerie" to be passed in when `getParamPageFlowScope` is called, and you're getting back `null` from your mock, this *usually* indicates that this string is not being called. So...you're going to want to trace back in your code where it's being called like this. Or, switch to `anyString()`. – Makoto Jan 30 '23 at 22:03
  • i used anyString() and too return null, the problem getInstance() is a static method and mockito mark as warning – Darkazura Barquero Jan 30 '23 at 22:08
  • Does this answer your question? [Mocking static methods with Mockito](https://stackoverflow.com/questions/21105403/mocking-static-methods-with-mockito) – Tim Moore Jan 30 '23 at 23:06

0 Answers0