### Question:
LDAPAuthService { public ResponseEntity<String> listLdapGroups(String token) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "List LDAP Groups"). put(LogMessage.MESSAGE, "Trying to list LDAP groups "). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); if(token == null || "".equals(token)){ return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Missing token \"]}"); } Response response = reqProcessor.process("/auth/ldap/groups/list","{}",token); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "List LDAP Groups"). put(LogMessage.MESSAGE, "Listing of LDAP groups completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }  ResponseEntity<String> authenticateLdap(UserLogin userLogin); ResponseEntity<String> configureLdapGroup(String token, LDAPGroup ldapGroup); ResponseEntity<String> listLdapGroups(String token); ResponseEntity<String> fetchLdapGroup(String token, String groupname); ResponseEntity<String> deleteLdapGroup(String token, String groupname); ResponseEntity<String> configureLdapUser(String token, LDAPUser ldapUser); ResponseEntity<String> listLdapUsers(String token); ResponseEntity<String> fetchLdapUser(String token, String username); ResponseEntity<String> deleteLdapUser(String token, String username);  }### Answer:
@Test public void test_listLdapGroups_successfully() { String token = "4EpPYDSfgN2D4Gf7UmNO3nuL"; Response response = getMockResponse(HttpStatus.OK, true, "{\"keys\": [\"admin\"]]"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"keys\": [\"admin\"]]"); when(reqProcessor.process("/auth/ldap/groups/list","{}",token)).thenReturn(response); ResponseEntity<String> responseEntity = ldapAuthService.listLdapGroups(token); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
@Test public void test_listLdapGroups_failure_400() { String token = "4EpPYDSfgN2D4Gf7UmNO3nuL"; Response response = getMockResponse(HttpStatus.BAD_REQUEST, false, "{\"errors\":[\"Missing token \"]}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Missing token \"]}"); when(reqProcessor.process("/auth/ldap/groups/list","{}",token)).thenReturn(response); ResponseEntity<String> responseEntity = ldapAuthService.listLdapGroups(""); assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }