junit - Mockito - You cannot use argument matchers outside of verification or stubbing - have tried many things but still no solution -
i have following piece of code:
powermockito.mockstatic(dateutils.class); //and line exception - notice it's static function powermockito.when(dateutils.isequalbydatetime (any(date.class),any(date.class)).thenreturn(false);
the class begins with:
@runwith(powermockrunner.class) @preparefortest({cm9dateutils.class,dateutils.class})
and org.mockito.exceptions.invaliduseofmatchersexception...... cannot use argument matchers outside of verification or stubbing..... (the error appears twice in failure trace - both point same line)
in other places in code usage of when done , it's working properly. also, when debugging code found any(date.class) returns null.
i have tried following solutions saw other people found useful, me doesn't work:
adding
@after public void checkmockito() { mockito.validatemockitousage(); }
or
@runwith(mockitojunitrunner.class)
or
@runwith(powermockrunner.class)change
powermockito.when(new boolean(dateutils.isequalbydatetime(any(date.class), any(date.class)))).thenreturn(false);using
anyobject()(it doesn't compile)using
notnull(date.class)or(date)notnull()replace
when(........).thenreturn(false);with
boolean falsebool=new boolean(false);
and
when(.......).thenreturn(falsebool);
as detailed on powermockito getting started page, you'll need use both powermock runner @preparefortest annotation.
@runwith(powermockrunner.class) @preparefortest(dateutils.class) ensure you're using @runwith annotation comes junit 4, org.junit.runner.runwith. because it's accepted value attribute, it's pretty odd me you're receiving error if you're using correct runwith type.
any(date.class) correct return null: rather using magic "matches date" instance, mockito uses a hidden stack of matchers track matcher expressions correspond matched arguments, , returns null objects (and 0 integers, , false booleans, , forth).
Comments
Post a Comment