How to mock the following stub in mockito
I am not sure how to mock the when and then for "nameValuePairs" which is a
List nameValuePairs
Authorization filteredAuthorization= baseClient.getAuthorizationsForFilteredDepartmets(up.getAuthorization().getAuthorizationToken(), nameValuePairs);
The following method I am trying to Unit Test
public static void applyFilteredDeptCagsToUserProfile(UserProfile up,List<NameValuePair> nameValuePairs) throws Exception {
log.info("Applying FilteredDeptCagsToUserProfile ");
BaseRestClient baseClient = getBaseRestClient();
Authorization filteredAuthorization= baseClient.getAuthorizationsForFilteredDepartmets(up.getAuthorization().getAuthorizationToken(), nameValuePairs);
if(null!=filteredAuthorization) {
up.setAuthorization(filteredAuthorization);
}
Map<String, String> origDeptMap= up.getDeptsIdNameMap(); //
Map<String, String> origCAGMap= up.getCagsIdNameMap();
Map<String, String> revisedDeptMap= new HashMap<String, String>();
Map<String, String> revisedCAGMap= new HashMap<String, String>();
for (NameValuePair nameValuePair : nameValuePairs) {
if("department".equalsIgnoreCase(nameValuePair.getName())) {
createRestrictedList(origDeptMap, revisedDeptMap, nameValuePair);
}
else if ("group".equalsIgnoreCase(nameValuePair.getName())) {
createRestrictedList(origCAGMap, revisedCAGMap, nameValuePair);
}
}
if(revisedDeptMap.size()>0) {
up.setDeptsIdNameMap(revisedDeptMap);
}
if(revisedCAGMap.size()> 0) {
up.setCagsIdNameMap(revisedCAGMap);
}
}
private static void createRestrictedList(Map<String, String> origDeptList, Map<String, String> revisedDeptList,
NameValuePair nameValuePair) {
String key =nameValuePair.getValue();
if (null !=key) {
String value = origDeptList.get(key);
if (null != value) {
revisedDeptList.put(key, value);
}
}
}
I have created the class and the snap shot of the test method
@Test
public void testFilteredDeptCagRestrictions() {
when(upMock.getAuthorization().getAuthorizationToken()).thenReturn(new AuthorizationToken());
when(baseRestClientMock.getAuthorizationsForFilteredDepartmets(any(AuthorizationToken.class),any(List.class)).thenReturn(""));
}
The problem is how to pass the
> List<NameValuePair> nameValuePairs
in the getAuthorizationsForFilteredDepartmets method.
Aucun commentaire:
Enregistrer un commentaire