01: /*
02: Copyright 2004-2007 Paul R. Holser, Jr. All rights reserved.
03: Licensed under the Academic Free License version 3.0
04: */
05:
06: package joptsimple;
07:
08: import junit.framework.Test;
09: import junit.framework.TestCase;
10: import junit.framework.TestSuite;
11: import junitx.framework.StringAssert;
12:
13: /**
14: * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
15: * @version $Id: ToStringTest.java,v 1.13 2007/04/10 20:06:27 pholser Exp $
16: */
17: public class ToStringTest extends TestCase {
18: private Object subject;
19: private String[] substrings;
20:
21: private ToStringTest(String name, Object subject,
22: String[] substrings) {
23: super (name);
24:
25: this .subject = subject;
26: this .substrings = (String[]) substrings.clone();
27: }
28:
29: protected void runTest() throws Throwable {
30: String stringRepresentation = subject.toString();
31:
32: for (int i = 0; i < substrings.length; ++i)
33: StringAssert.assertContains(substrings[i],
34: stringRepresentation);
35: }
36:
37: public static Test suite() {
38: TestSuite suite = new TestSuite("toString() tests");
39:
40: suite.addTest(new ToStringTest("no-arg option spec",
41: new NoArgumentOptionSpec("abc"), new String[] { "abc",
42: "accepts no arg" }));
43:
44: suite.addTest(new ToStringTest("required-arg option spec",
45: new RequiredArgumentOptionSpec("def"), new String[] {
46: "def", "arg required" }));
47:
48: suite.addTest(new ToStringTest("optional-arg option spec",
49: new OptionalArgumentOptionSpec("ghi"), new String[] {
50: "ghi", "arg optional" }));
51:
52: suite.addTest(new ToStringTest("key-value pair", KeyValuePair
53: .parse("key=value"),
54: new String[] { "key", "=", "value" }));
55:
56: suite.addTest(new ToStringTest("option exception",
57: new OptionException("a") {
58: }, new String[] { "'a'" }));
59:
60: return suite;
61: }
62: }
|