java - Can Mockito stub a method without regard to the argument? -


i'm trying test legacy code, using mockito.

i want stub foodao used in production follows:

foo = foodao.getbar(new bazoo()); 

i can write:

when(foodao.getbar(new bazoo())).thenreturn(myfoo); 

but obvious problem getbar() never called same bazoo object stubbed method for. (curse new operator!)

i love if stub method in way returns myfoo regardless of argument. failing that, i'll listen other workaround suggestions, i'd avoid changing production code until there reasonable test coverage.

when(   foodao.getbar(     any(bazoo.class)   ) ).thenreturn(myfoo); 

or (to avoid nulls):

when(   foodao.getbar(     (bazoo)notnull()   ) ).thenreturn(myfoo); 

don't forget import matchers (many others available):

import static org.mockito.matchers.*; 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -