OfflineEditsViewer extends Configured implements Tool { @Override public int run(String[] argv) throws Exception { Options options = buildOptions(); if(argv.length == 0) { printHelp(); return 0; } if (argv.length == 1 && isHelpOption(argv[0])) { printHelp(); return 0; } CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, argv); } catch (ParseException e) { System.out.println( "Error parsing command-line options: " + e.getMessage()); printHelp(); return -1; } if (cmd.hasOption("h")) { printHelp(); return -1; } String inputFileName = cmd.getOptionValue("i"); String outputFileName = cmd.getOptionValue("o"); String processor = cmd.getOptionValue("p"); if(processor == null) { processor = defaultProcessor; } Flags flags = new Flags(); if (cmd.hasOption("r")) { flags.setRecoveryMode(); } if (cmd.hasOption("f")) { flags.setFixTxIds(); } if (cmd.hasOption("v")) { flags.setPrintToScreen(); } return go(inputFileName, outputFileName, processor, flags, null); }  static Options buildOptions(); int go(String inputFileName, String outputFileName, String processor,
      Flags flags, OfflineEditsVisitor visitor); @Override int run(String[] argv); static void main(String[] argv);  }
@Test public void testOfflineEditsViewerHelpMessage() throws Throwable { final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final PrintStream out = new PrintStream(bytes); final PrintStream oldOut = System.out; try { System.setOut(out); int status = new OfflineEditsViewer().run(new String[] { "-h" }); assertTrue("" + "Exit code returned for help option is incorrect", status == 0); Assert.assertFalse( "Invalid Command error displayed when help option is passed.", bytes .toString().contains("Error parsing command-line options")); } finally { System.setOut(oldOut); IOUtils.closeStream(out); } }