Skip to content

Commit d44f308

Browse files
committed
[CLI-287] Add tests
1 parent d5b5e26 commit d44f308

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

src/test/java/org/apache/commons/cli/HelpFormatterTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,62 @@ public void testOptionWithoutShortFormat2() {
293293
//@formatter:on
294294
}
295295

296+
@Test
297+
public void testPrintHelpNewlineFooter()
298+
{
299+
final HelpFormatter formatter = new HelpFormatter();
300+
final ByteArrayOutputStream out = new ByteArrayOutputStream();
301+
final PrintWriter pw = new PrintWriter(out);
302+
303+
final Options options = new Options();
304+
options.addOption("a", "b");
305+
306+
formatter.printHelp(
307+
pw,
308+
80,
309+
"test" + EOL,
310+
"header" + EOL,
311+
options,
312+
0,
313+
0,
314+
EOL
315+
);
316+
final String expected = "usage: test" + EOL +
317+
"header" + EOL +
318+
"-ab" + EOL +
319+
EOL;
320+
pw.flush();
321+
assertEquals("footer newline", expected, out.toString());
322+
}
323+
324+
@Test
325+
public void testPrintHelpNewlineHeader()
326+
{
327+
final HelpFormatter formatter = new HelpFormatter();
328+
final ByteArrayOutputStream out = new ByteArrayOutputStream();
329+
final PrintWriter pw = new PrintWriter(out);
330+
331+
final Options options = new Options();
332+
options.addOption("a", "b");
333+
334+
formatter.printHelp(
335+
pw,
336+
80,
337+
"test" + EOL,
338+
EOL,
339+
options,
340+
0,
341+
0,
342+
"footer" + EOL
343+
);
344+
String expected = "usage: test" + EOL +
345+
EOL +
346+
"-ab" + EOL +
347+
"footer" + EOL;
348+
pw.flush();
349+
assertEquals("header newline", expected, out.toString());
350+
}
351+
296352
@Test
297353
public void testPrintHelpWithEmptySyntax() {
298354
final HelpFormatter formatter = new HelpFormatter();

0 commit comments

Comments
 (0)