@Test(timeout=500)
public void testHelp() throws Exception {

  PrintStream oldOutPrintStream = System.out;
  PrintStream oldErrPrintStream = System.err;
  ByteArrayOutputStream dataOut = new ByteArrayOutputStream();
  ByteArrayOutputStream dataErr = new ByteArrayOutputStream();
  System.setOut(new PrintStream(dataOut));
  System.setErr(new PrintStream(dataErr));
  try {
    String[] args = { "-help" };
    assertEquals(0, rmAdminCLI.run(args));
    oldOutPrintStream.println(dataOut);
    assertTrue(dataOut
        .toString()
        .contains(
            "rmadmin is the command to execute YARN administrative commands."));
    assertTrue(dataOut
        .toString()
        .contains(
            "yarn rmadmin [-refreshQueues] [-refreshNodes] [-refreshSuper" +
            "UserGroupsConfiguration] [-refreshUserToGroupsMappings] " +
            "[-refreshAdminAcls] [-refreshServiceAcl] [-getGroup" +
            " [username]] [-help [cmd]]"));
    assertTrue(dataOut
        .toString()
        .contains(
            "-refreshQueues: Reload the queues' acls, states and scheduler " +
            "specific properties."));
    assertTrue(dataOut
        .toString()
        .contains(
            "-refreshNodes: Refresh the hosts information at the " +
            "ResourceManager."));
    assertTrue(dataOut.toString().contains(
        "-refreshUserToGroupsMappings: Refresh user-to-groups mappings"));
    assertTrue(dataOut
        .toString()
        .contains(
            "-refreshSuperUserGroupsConfiguration: Refresh superuser proxy" +
            " groups mappings"));
    assertTrue(dataOut
        .toString()
        .contains(
            "-refreshAdminAcls: Refresh acls for administration of " +
            "ResourceManager"));
    assertTrue(dataOut
        .toString()
        .contains(
            "-refreshServiceAcl: Reload the service-level authorization" +
            " policy file"));
    assertTrue(dataOut
        .toString()
        .contains(
            "-help [cmd]: Displays help for the given command or all " +
            "commands if none"));
    testError(new String[] { "-help", "-refreshQueues" },
        "Usage: yarn rmadmin [-refreshQueues]", dataErr, 0);
    testError(new String[] { "-help", "-refreshNodes" },
        "Usage: yarn rmadmin [-refreshNodes]", dataErr, 0);
    testError(new String[] { "-help", "-refreshUserToGroupsMappings" },
        "Usage: yarn rmadmin [-refreshUserToGroupsMappings]", dataErr, 0);
    testError(
        new String[] { "-help", "-refreshSuperUserGroupsConfiguration" },
        "Usage: yarn rmadmin [-refreshSuperUserGroupsConfiguration]",
        dataErr, 0);
    testError(new String[] { "-help", "-refreshAdminAcls" },
        "Usage: yarn rmadmin [-refreshAdminAcls]", dataErr, 0);
    testError(new String[] { "-help", "-refreshServiceAcl" },
        "Usage: yarn rmadmin [-refreshServiceAcl]", dataErr, 0);
    testError(new String[] { "-help", "-getGroups" },
        "Usage: yarn rmadmin [-getGroups [username]]", dataErr, 0);
    testError(new String[] { "-help", "-transitionToActive" },
        "Usage: yarn rmadmin [-transitionToActive <serviceId>" +
        " [--forceactive]]", dataErr, 0);
    testError(new String[] { "-help", "-transitionToStandby" },
        "Usage: yarn rmadmin [-transitionToStandby <serviceId>]", dataErr, 0);
    testError(new String[] { "-help", "-getServiceState" },
        "Usage: yarn rmadmin [-getServiceState <serviceId>]", dataErr, 0);
    testError(new String[] { "-help", "-checkHealth" },
        "Usage: yarn rmadmin [-checkHealth <serviceId>]", dataErr, 0);
    testError(new String[] { "-help", "-failover" },
        "Usage: yarn rmadmin " +
            "[-failover [--forcefence] [--forceactive] " +
            "<serviceId> <serviceId>]",
        dataErr, 0);
    testError(new String[] { "-help", "-badParameter" },
        "Usage: yarn rmadmin", dataErr, 0);
    testError(new String[] { "-badParameter" },
        "badParameter: Unknown command", dataErr, -1);
    // Test -help when RM HA is enabled
    assertEquals(0, rmAdminCLIWithHAEnabled.run(args));
    oldOutPrintStream.println(dataOut);
    assertTrue(dataOut
        .toString()
        .contains(
            "yarn rmadmin [-refreshQueues] [-refreshNodes] [-refreshSuper" +
            "UserGroupsConfiguration] [-refreshUserToGroupsMappings] " +
            "[-refreshAdminAcls] [-refreshServiceAcl] [-getGroup" +
            " [username]] [-help [cmd]] [-transitionToActive <serviceId>" + 
            " [--forceactive]] [-transitionToStandby <serviceId>] [-failover" +
            " [--forcefence] [--forceactive] <serviceId> <serviceId>] " +
            "[-getServiceState <serviceId>] [-checkHealth <serviceId>]"));
  } finally {
    System.setOut(oldOutPrintStream);
    System.setErr(oldErrPrintStream);
  }
}