ExtSourceEGISSO extends ExtSourceLdap implements ExtSourceApi { @Override public List<Map<String, String>> getUsersSubjects() { String query = getAttributes().get(UsersManager.USERS_QUERY); return getUsersOrGroupSubjects(query); }  @Override List<Map<String, String>> getGroupSubjects(Map<String, String> attributes); @Override List<Map<String, String>> getSubjectGroups(Map<String, String> attributes); @Override List<Map<String, String>> getUsersSubjects();  }
@Test public void getUsersSubjectsTest() throws Exception { System.out.println("getUsersSubjectsTest"); String usersQuery = "firstName=josef"; Map<String, String> mapOfAttributes = new HashMap<>(); mapOfAttributes.put("usersQuery", usersQuery); doReturn(mapOfAttributes).when(extSourceEGISSO).getAttributes(); DirContext dirContext = mock(DirContext.class); doReturn(dirContext).when(extSourceEGISSO).getContext(); Attributes attributes = new BasicAttributes(); attributes.put(new BasicAttribute("cn", "josef")); NamingEnumeration<SearchResult> namingEnumeration = mock(NamingEnumeration.class); doReturn(namingEnumeration).when(dirContext).search(anyString(), anyString(), any()); doReturn(true,false).when(namingEnumeration).hasMore(); SearchResult searchResult = new SearchResult("name", namingEnumeration, attributes); doReturn(searchResult).when(namingEnumeration).next(); extSourceEGISSO.mapping = new HashMap<>(); extSourceEGISSO.mapping.put("cn", "cn"); List<Map<String, String>> expectedSubjects = new ArrayList<>(); Map<String, String> subject = new HashMap<>(); subject.put("cn", "josef"); expectedSubjects.add(subject); List<Map<String, String>> actualSubjects = extSourceEGISSO.getUsersSubjects(); assertEquals("subjects should be same", expectedSubjects, actualSubjects); }