### Question:
EjectCommand implements Command { @Override @SuppressWarnings("unchecked") public void run(Line line) throws Exception { if (line.args().size() == 1) { Map<String, String> input = new LinkedHashMap<>(); String id = line.args().get(0); input.put("id", id); String json = new ObjectMapper().writeValueAsString(input); log.info("Ejecting fault id [" + id + "]"); log.debug(json); String profile = (String) configuration.get("default"); HttpPost post = new HttpPost(((Map<String, Object>) configuration.get(profile)).get("endpoint") + "/eject"); post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); try (CloseableHttpResponse response = httpClient.execute(post)) { StatusLine status = response.getStatusLine(); String content = EntityUtils.toString(response.getEntity(), ContentType.APPLICATION_JSON.getCharset()); log.debug(content); if (status.getStatusCode() == HttpStatus.SC_OK) { shell.console().println("Fault has been successfully ejected"); } else { log.warn("Ejecting fault failed in [" + status + "] for a reason of [" + content + "]"); } } return; } shell.console().println("Unsupported usage"); shell.console().println(usage().toString()); } EjectCommand(Shell shell, Map<String, Object> configuration); @Override String name(); @Override Usage usage(); @Override @SuppressWarnings("unchecked") void run(Line line); void httpClient(CloseableHttpClient httpClient);  }### Answer:
@Test public void testRun() throws Exception { Map<String, Object> configuration = new HashMap<>(); configuration.put("default", "profile-1"); Map<String, String> profile1 = new HashMap<>(); profile1.put("endpoint", "https: configuration.put("profile-1", profile1); Map<String, String> profile2 = new HashMap<>(); profile2.put("endpoint", "https: configuration.put("profile-2", profile2); EjectCommand command = new EjectCommand(new Shell(), configuration); CloseableHttpResponse response = mock(CloseableHttpResponse.class); StatusLine line = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""); doReturn(line).when(response).getStatusLine(); HttpEntity entity = new StringEntity("{}", ContentType.APPLICATION_JSON); doReturn(entity).when(response).getEntity(); CloseableHttpClient httpClient = mock(CloseableHttpClient.class); doAnswer((i) -> { HttpPost post = i.getArgument(0); assertThat(post.getURI().toString(), is("https: assertThat(post.getEntity().getContentType().getValue(), is(ContentType.APPLICATION_JSON.toString())); assertThat(IOUtils.toString(post.getEntity().getContent(), ContentType.APPLICATION_JSON.getCharset()), is("{\"id\":\"fault-id-1\"}")); return response; }).when(httpClient).execute(ArgumentMatchers.any(HttpUriRequest.class)); command.httpClient(httpClient); Map<String, String> options = new HashMap<>(); List<String> args = new ArrayList<>(); args.add("fault-id-1"); command.run(new Line("eject", options, args)); line = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_INTERNAL_SERVER_ERROR, ""); doReturn(line).when(response).getStatusLine(); command.run(new Line("eject", options, args)); command = new EjectCommand(new Shell(), configuration); args = new ArrayList<>(); command.run(new Line("eject", options, args)); command = new EjectCommand(new Shell(), configuration); args = new ArrayList<>(); args.add("fault-id-1"); args.add("fault-id-2"); command.run(new Line("eject", options, args)); }