### Question:
ServiceCombClient { public String registerMicroservice(Microservice microservice) throws ServiceCombException { Response response = null; String content = null; try { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true); content = objectMapper.writeValueAsString(microservice); StringEntity stringEntity = new StringEntity(content, "utf-8"); response = httpTransport .sendPostRequest(buildURI("/registry/microservices"), stringEntity); if (response.getStatusCode() == HttpStatus.SC_OK) { LOGGER.info(response.getContent()); HashMap<String, String> result = objectMapper .readValue(response.getContent(), HashMap.class); if (null != result) { return result.get("serviceId"); } } else { throw new RemoteOperationException( "read response failed. status:" + response.getStatusCode() + "; message:" + response .getStatusMessage() + "; content:" + response.getContent()); } } catch (URISyntaxException e) { throw new RemoteOperationException("build url failed.", e); } catch (IOException e) { throw new RemoteOperationException( response == null ? "read response failed. " : "read response failed. " + response, e); } return null; } ServiceCombClient(String urls, HttpTransport httpTransport); void autoDiscovery(boolean autoDiscovery); MicroserviceInstancesResponse getServiceCenterInstances(); String registerMicroservice(Microservice microservice); String getServiceId(Microservice microservice); SchemaResponse getSchemas(String serviceId); String registerInstance(MicroserviceInstance microserviceInstance); boolean deRegisterInstance(String serviceId, String instanceId); List<ServiceInstance> getInstances(Microservice microservice, String revision); MicroserviceInstanceSingleResponse getInstance(String serviceId, String instanceId); HeardBeatStatus heartbeat(HeartbeatRequest heartbeatRequest); boolean updateInstanceStatus(String serviceId, String instanceId, String status); MicroserviceResponse getServices(); boolean registerSchema(String microserviceId, String schemaId, String schemaContent); static String calcSchemaSummary(String schemaContent); void toggle(); String getUrl(); static String INSTANCE_STATUS; static String ZONE; }### Answer:
@Test public void registerMicroservice(@Injectable HttpTransport httpTransport) throws ServiceCombException, IOException { final int expectedCode = 200; Response response = new Response(); response.setStatusCode(expectedCode); String responseString = "{\"serviceId\": \"22222\"}"; response.setContent(responseString); Microservice microservice = new Microservice(); new Expectations() { { Deencapsulation.newUninitializedInstance(DefaultHttpTransport.class); result = httpTransport; httpTransport.sendPostRequest(anyString, (HttpEntity) any); result = response; } }; ServiceCombClient serviceCombClient = new ServiceCombClient(url, httpTransport); String actual = serviceCombClient.registerMicroservice(microservice); Assert.assertEquals("22222", actual); }