java - Mockito Matcher parameters showing as undefined -
i trying mock method contained in main class of application. i'd test when parameters submitted successfully, application calls right method, uploadfiles. when - thenreturn pair shown below:
nrclient nrclient = (nrclient)mockito.mock(nrclient.class); mockito.when(nrclient.uploadfiles("df49acbc8", anylist(), "dl")).thenreturn("");
this shows runtime exception: "the method anystring() undefined type maintest." have imports:
import org.mockito.mockito; import org.mockito.matchers;
so why method undefined? there issue in implementation?
i have tried anystring() , anyint() same result.
you should getting compile-time error, not exception (unless actual exception you've got unresolved compile-time error).
just importing org.mockito.matchers
means can utilize name matchers
mean org.mockito.matchers
anywhere in class. if want import methods, need static wildcard import:
import static org.mockito.matchers.*;
or specific methods:
import static org.mockito.matchers.anystring; import static org.mockito.matchers.anylist;
or qualify method name in calling code instead:
mockito.when(nrclient.uploadfiles("df49acbc8", matchers.anylist(), "dl")) .thenreturn("");
java junit mocking mockito
No comments:
Post a Comment