HelpCommand extends AbstractCommand { @Override public void exec(OptionSet options, GlacierUploaderOptionParser optionParser) { if (!options.has(optionParser.help)) { log.info("Ooops, can't determine what you want to do. Check your options." + System.getProperty("line.separator")); } try { optionParser.printHelpOn(out); } catch (final IOException e) { log.error("Can not print help", e); } } HelpCommand(AmazonGlacier client, AmazonSQS sqs, AmazonSNS sns);  HelpCommand(final AmazonGlacier client, final AmazonSQS sqs, final AmazonSNS sns, final OutputStream out); @Override void exec(OptionSet options, GlacierUploaderOptionParser optionParser); @Override boolean valid(OptionSet options, GlacierUploaderOptionParser optionParser);  }
@Test public void exec() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); final OptionSet options = optionParser.parse("--help"); final HelpCommand command = new HelpCommand(client, sqs, sns, out); assertTrue(command.valid(options, optionParser)); command.exec(options, optionParser); ByteArrayOutputStream another = new ByteArrayOutputStream(); optionParser.printHelpOn(another); assertEquals(another.toString(), out.toString()); }
@Test public void execWithoutOption() { final OptionSet options = optionParser.parse(); final HelpCommand command = new HelpCommand(client, sqs, sns, System.out); command.exec(options, optionParser); }
@Test public void execWithBrokenOutput() throws IOException { final OptionSet options = optionParser.parse("--help"); final OutputStream out = createMock(OutputStream.class); out.write((byte[]) anyObject(), anyInt(), anyInt()); expectLastCall().andThrow(new IOException("dummy exception from junit test")); replay(out); final HelpCommand command = new HelpCommand(client, sqs, sns, out); command.exec(options, optionParser); }