HelpFormatter { protected void help(Writer writer) throws IOException { line(writer, getDivider()); Option option; OptionException exception = getException(); if (exception != null && exception.getOption() != null) { option = exception.getOption(); } else { option = getOption(); } isNotNull(option, "Option is required"); List<Help> helps = option.help(0, getOptionOutputHints(), getComparator()); int usageWidth = 0; for (Help help : helps) { String content = help.help(getHelpOutputHints(), getComparator()); usageWidth = Math.max(usageWidth, content.length()); } for (Help help : helps) { line(writer, pad(help.help(getHelpOutputHints(), getComparator()), usageWidth), getGutter(), help.getOption().getDescription()); } line(writer, getDivider()); }  void format(OutputStream output); void format(Writer writer); Set<HelpHint> getUsageOutputHints(); void setUsageOutputHints(Set<HelpHint> usageOutputHints); Set<HelpHint> getHelpOutputHints(); void setHelpOutputHints(Set<HelpHint> helpOutputHints); Set<HelpHint> getOptionOutputHints(); void setOptionOutputHints(Set<HelpHint> optionOutputHints); String getExecutable(); void setExecutable(String executable); String getHeader(); void setHeader(String header); String getDivider(); void setDivider(String divider); String getGutter(); void setGutter(String gutter); String getFooter(); void setFooter(String footer); Option getOption(); void setOption(Option option); Comparator getComparator(); void setComparator(Comparator comparator); OptionException getException(); void setException(OptionException exception); final static String GUTTER; static Set<HelpHint> USAGE_OUTPUT_HINTS; static Set<HelpHint> HELP_OUTPUT_HINTS; static Set<HelpHint> OPTION_OUTPUT_HINTS; }
@Test public void testHelp() throws IOException { String footer = "------------"; String divider = "\n"; helpFormatter.setFooter(footer); helpFormatter.setDivider(divider); OptionException exception = mock(OptionException.class); when(exception.getOption()).thenReturn(mock(Option.class)); helpFormatter.setException(exception); Writer writer = mock(Writer.class); helpFormatter.help(writer); verify(helpFormatter, times(2)).line(writer, divider); verify(exception, times(2)).getOption(); }