DirectoryService { public ResponseEntity<DirectoryObjects> searchByGroupName(String groupName) { AndFilter andFilter = new AndFilter(); andFilter.and(new EqualsFilter("objectClass", "group")); andFilter.and(new LikeFilter("CN", groupName+"*")); List<DirectoryGroup> allGroups = getAllGroups(andFilter); DirectoryObjects groups = new DirectoryObjects(); DirectoryObjectsList groupsList = new DirectoryObjectsList(); groupsList.setValues(allGroups.toArray(new DirectoryGroup[allGroups.size()])); groups.setData(groupsList); return ResponseEntity.status(HttpStatus.OK).body(groups); }  ResponseEntity<DirectoryObjects> searchByUPN(String UserPrincipalName); ResponseEntity<DirectoryObjects> searchByCorpId(String corpId); ResponseEntity<DirectoryObjects> searchByGroupName(String groupName);  }
@Test public void test_searchByGroupName_successfully() { DirectoryGroup dirGrp = new DirectoryGroup(); dirGrp.setDisplayName("test_group"); dirGrp.setEmail("testgroup@t-mobile.com"); dirGrp.setGroupName("test_group"); List<DirectoryGroup> allGroups = new ArrayList<>(); allGroups.add(dirGrp); DirectoryObjects groups = new DirectoryObjects(); DirectoryObjectsList groupsList = new DirectoryObjectsList(); groupsList.setValues(allGroups.toArray(new DirectoryGroup[allGroups.size()])); groups.setData(groupsList); ResponseEntity<DirectoryObjects> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body(groups); when(ldapTemplate.search(Mockito.anyString(), Mockito.anyString(), Mockito.any(AttributesMapper.class))).thenReturn(allGroups); ResponseEntity<DirectoryObjects> responseEntity = directoryService.searchByGroupName("test_group"); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected.getBody().getData().getValues()[0], responseEntity.getBody().getData().getValues()[0]); }