Skip to content

Commit b6cfdf9

Browse files
committed
Improved test coverage for HelpFormatter.printHelp() with a null or empty cmdLineSyntax parameter
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/branches/cli-1.x@661652 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8214cec commit b6cfdf9

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,31 @@ public void testPrintOptions() throws Exception
155155
assertEquals("multiple wrapped options", expected, sb.toString());
156156
}
157157

158+
public void testPrintHelpWithEmptySyntax()
159+
{
160+
HelpFormatter formatter = new HelpFormatter();
161+
try
162+
{
163+
formatter.printHelp(null, new Options());
164+
fail("null command line syntax should be rejected");
165+
}
166+
catch (IllegalArgumentException e)
167+
{
168+
// expected
169+
}
170+
171+
try
172+
{
173+
formatter.printHelp("", new Options());
174+
fail("empty command line syntax should be rejected");
175+
}
176+
catch (IllegalArgumentException e)
177+
{
178+
// expected
179+
}
180+
}
181+
182+
158183
public void testAutomaticUsage() throws Exception
159184
{
160185
HelpFormatter hf = new HelpFormatter();
@@ -295,13 +320,7 @@ public void testPrintOptionWithEmptyArgNameUsage()
295320

296321
public void testRtrim()
297322
{
298-
HelpFormatter formatter = new HelpFormatter()
299-
{
300-
public String rtrim(String s)
301-
{
302-
return super.rtrim(s);
303-
}
304-
};
323+
HelpFormatter formatter = new HelpFormatter();
305324

306325
assertEquals(null, formatter.rtrim(null));
307326
assertEquals("", formatter.rtrim(""));

0 commit comments

Comments
 (0)