I have a private method I need to access from a junit. The method has the following signature:
private String search(Map<String, String[]> params, String userName)
I have tried the following setup:
Method mockSearch;
Class[] cArg = new Class[2];
cArg[0] = Map<String, String[]>.class
cArg[1] = String.class;
mockSearch = aClass.getClass().getDeclaredMethod("search", cArg);
Which obviously won't even compile because "cArg[0] = Map<String, String[]>.class" is nonsensical. So I attempted a concrete class for arg 0 like this:
Map<String, String[]> mockMap = new HashMap<>();
cArg[0] = mockMap.getClass();
which threw exception at runtime because of the strictness of the getDeclaredMethod. Here basically is exception snippet:
java.lang.NoSuchMethodException: blah.blah.blah$MyTestClass.search(java.util.HashMap, java.lang.String)
Is there a way to represent a Map<String, String[]> class type that will work? Thanks for ideas.
Aucun commentaire:
Enregistrer un commentaire