Skip to content

Commit 1fcf87d

Browse files
committed
Simplify exception testing
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@1440541 13f79535-47bb-0310-9956-ffa450edef68
1 parent c6cf0e7 commit 1fcf87d

1 file changed

Lines changed: 13 additions & 50 deletions

File tree

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

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,11 @@ public void test13425() throws Exception
201201

202202
Parser parser = new PosixParser();
203203

204-
try
205-
{
204+
try {
206205
parser.parse( options, args );
206+
fail( "MissingArgumentException not caught." );
207+
} catch( MissingArgumentException expected ) {
207208
}
208-
// catch the exception and leave the method
209-
catch( Exception exp )
210-
{
211-
assertTrue( exp != null );
212-
return;
213-
}
214-
fail( "MissingArgumentException not caught." );
215209
}
216210

217211
public void test13666() throws Exception
@@ -263,62 +257,31 @@ public void test13935() throws Exception
263257
opts.addOption( straight );
264258

265259
CommandLineParser parser = new PosixParser();
266-
boolean exception = false;
267260

268261
String[] args = new String[] { };
269-
try
270-
{
262+
try {
271263
parser.parse(opts, args);
264+
fail("Expected ParseException");
272265
}
273-
catch (ParseException exp)
274-
{
275-
exception = true;
266+
catch (ParseException expected) {
276267
}
277268

278-
if (!exception)
279-
{
280-
fail("Expected exception not caught.");
281-
}
282-
283-
exception = false;
284-
285269
args = new String[] { "-s" };
286-
try
287-
{
270+
try {
288271
parser.parse(opts, args);
272+
fail("Expected ParseException");
289273
}
290-
catch (ParseException exp)
291-
{
292-
exception = true;
293-
}
294-
295-
if (!exception)
296-
{
297-
fail("Expected exception not caught.");
274+
catch (ParseException expected) {
298275
}
299276

300-
exception = false;
301-
302277
args = new String[] { "-s", "-l" };
303-
try
304-
{
305-
parser.parse(opts, args);
306-
}
307-
catch (ParseException exp)
308-
{
309-
fail("Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage());
310-
}
278+
CommandLine line = parser.parse(opts, args);
279+
assertNotNull(line);
311280

312281
opts.addOption( forward );
313282
args = new String[] { "-s", "-l", "-f" };
314-
try
315-
{
316-
parser.parse(opts, args);
317-
}
318-
catch (ParseException exp)
319-
{
320-
fail("Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage());
321-
}
283+
line = parser.parse(opts, args);
284+
assertNotNull(line);
322285
}
323286

324287
public void test14786() throws Exception

0 commit comments

Comments
 (0)