### Question:
DeploymentGroupRemoveCommand extends ControlCommand { @Override int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException, IOException { final String name = options.getString(nameArg.getDest()); final RemoveDeploymentGroupResponse status = client.removeDeploymentGroup(name).get(); if (status == null) { throw new RuntimeException("The Helios master could not remove the given deployment group."); } final boolean failed = status.getStatus() != RemoveDeploymentGroupResponse.Status.REMOVED; if (json) { out.println(status.toJsonString()); } else { if (failed) { out.println(format("Failed to remove deployment-group %s, status: %s", name, status.getStatus())); } else { out.println(format("Deployment-group %s removed", name)); } } return failed ? 1 : 0; } DeploymentGroupRemoveCommand(final Subparser parser);   }### Answer:
@Test public void testRemoveDeploymentGroupRemoved() throws Exception { when(client.removeDeploymentGroup(GROUP_NAME)) .thenReturn(immediateFuture(new RemoveDeploymentGroupResponse(Status.REMOVED))); final int ret = command.run(options, client, out, false, null); final String output = baos.toString(); verify(client).removeDeploymentGroup(GROUP_NAME); assertEquals(0, ret); final String expected = format("Deployment-group %s removed\n", GROUP_NAME); assertEquals(expected, output); }
@Test public void testRemoveDeploymentGroupRemovedJson() throws Exception { when(client.removeDeploymentGroup(GROUP_NAME)) .thenReturn(immediateFuture(new RemoveDeploymentGroupResponse(Status.REMOVED))); final int ret = command.run(options, client, out, true, null); final String output = baos.toString(); verify(client).removeDeploymentGroup(GROUP_NAME); assertEquals(0, ret); final RemoveDeploymentGroupResponse res = Json.read( output, new TypeReference<RemoveDeploymentGroupResponse>() {}); assertEquals(new RemoveDeploymentGroupResponse(Status.REMOVED), res); }
@Test public void testRemoveDeploymentGroupNotFound() throws Exception { when(client.removeDeploymentGroup(GROUP_NAME)) .thenReturn(immediateFuture( new RemoveDeploymentGroupResponse(Status.DEPLOYMENT_GROUP_NOT_FOUND))); final int ret = command.run(options, client, out, false, null); final String output = baos.toString(); verify(client).removeDeploymentGroup(GROUP_NAME); assertEquals(1, ret); final String expected = format("Failed to remove deployment-group %s, status: %s\n", GROUP_NAME, Status.DEPLOYMENT_GROUP_NOT_FOUND); assertEquals(expected, output); }
@Test public void testRemoveDeploymentGroupNotFoundJson() throws Exception { when(client.removeDeploymentGroup(GROUP_NAME)) .thenReturn(immediateFuture( new RemoveDeploymentGroupResponse(Status.DEPLOYMENT_GROUP_NOT_FOUND))); final int ret = command.run(options, client, out, true, null); final String output = baos.toString(); verify(client).removeDeploymentGroup(GROUP_NAME); assertEquals(1, ret); final RemoveDeploymentGroupResponse res = Json.read( output, new TypeReference<RemoveDeploymentGroupResponse>() {}); assertEquals(new RemoveDeploymentGroupResponse(Status.DEPLOYMENT_GROUP_NOT_FOUND), res); }