java - Using Mockito: Matching multiple arguments in a private static method? -


i've been trying use mockito , powermockito test code. have akin following class:

public class asdfclass{      public static string methodtomock(string item, string otheritem){       return "asdf";     }      public static string methodtomock(string item){       return "asdf";         } } 

for whatever reason, though, running following:

powermockito.spy(asdfclass.class);  powermockito.when(asdfclass.methodtomock(mockito.any())).thenreturn("asdfghj"); 

appears compile correctly running

powermockito.spy(asdfclass.class);  powermockito.when(asdfclass.methodtomock(mockito.any(), mockito.any())).thenreturn("asdfghj"); 

does not , spits out "'void' type not allowed here" error on mockito.any()s.

does know this? other result saw on stackoverflow suggested reader take @ documentation, though don't think said multiple arguments in private static method.

(in end i'm hoping mock void result donothing though i've boiled issue i'm having down fact of void methods take multiple arguments)

edit: never mind, got it: is possible use partial mocking private static methods in powermock? (comment 4 on chosen answer). curiously didn't work before might've been typo on part know)

you mock void methods, can't return anything, thenreturn() statement should omitted (for example instead of when(), use donothing()).


Comments