001: package abbot.script;
002:
003: import java.awt.*;
004:
005: import javax.swing.JLabel;
006: import javax.swing.JTree;
007:
008: import abbot.AssertionFailedError;
009: import junit.extensions.abbot.*;
010:
011: public class AssertTest extends ResolverFixture {
012:
013: public void testAssertTreePath() throws Throwable {
014: JTree tree = new JTree();
015: tree.setSelectionInterval(1, 1);
016: showFrame(tree);
017: ComponentReference ref = getResolver().addComponent(tree);
018: Assert step = new Assert(getResolver(), null,
019: "getSelectionPath", ref.getID(), "[JTree, colors]",
020: false);
021: step.runStep();
022: }
023:
024: public void testAssertNullValue() throws Throwable {
025: JLabel label = new JLabel(getName());
026: Frame frame = showFrame(label);
027: ComponentReference ref1 = getResolver().addComponent(label);
028: ComponentReference ref2 = getResolver().addComponent(frame);
029: Assert step1 = new Assert(getResolver(),
030: "label.getName() == null", "getName", ref1.getID(),
031: ArgumentParser.NULL, false);
032: step1.runStep();
033: label.setName("my label");
034: try {
035: step1.runStep();
036: fail("test getName() == null should fail if name is not null");
037: } catch (AssertionFailedError e) {
038: }
039:
040: Assert step2 = new Assert(getResolver(),
041: "frame.getName() != null", "getName", ref2.getID(),
042: ArgumentParser.NULL, true);
043: step2.runStep();
044: frame.setName(null);
045: try {
046: step2.runStep();
047: fail("test getName() != null should fail if name is null");
048: } catch (AssertionFailedError e) {
049: }
050:
051: }
052:
053: /** Verify expressions are always reduced to a canonical boolean form. */
054: public void testCanonicalBooleans() {
055: String[] args = {};
056: Assert step = new Assert(getResolver(), null, "isSomething",
057: args, Component.class, "true", false);
058: assertEquals("Should expect 'true'", "true", step
059: .getExpectedResult());
060: assertTrue("Should not be inverted", !step.isInverted());
061:
062: step = new Assert(getResolver(), null, "isSomething", args,
063: Component.class, "true", true);
064: assertEquals("Should expect 'true'", "true", step
065: .getExpectedResult());
066: assertTrue("Should be inverted", step.isInverted());
067:
068: step = new Assert(getResolver(), null, "isSomething", args,
069: Component.class, "false", false);
070: assertEquals("Should expect 'true'", "true", step
071: .getExpectedResult());
072: assertTrue("Should be inverted", step.isInverted());
073:
074: step = new Assert(getResolver(), null, "isSomething", args,
075: Component.class, "false", true);
076: assertEquals("Should expect 'true'", "true", step
077: .getExpectedResult());
078: assertTrue("Should not be inverted", !step.isInverted());
079: }
080:
081: public void testAssertFrameShowing() throws Throwable {
082: Frame f = showFrame(new JLabel(getName()));
083: f.setTitle(getName());
084: String a1 = "<assert method=\"assertFrameShowing\" args=\""
085: + getName() + "\"/>";
086: Step s1 = Step.createStep(getResolver(), a1);
087: s1.runStep();
088: }
089:
090: public void testExpectedResult() throws Throwable {
091: Frame f = showFrame(new JLabel(getName()));
092: f.setName(getName());
093: ComponentReference ref = getResolver().addComponent(f);
094: Color c = f.getBackground();
095: String expected = c.toString();
096: Assert s = new Assert(getResolver(), null, "getBackground", ref
097: .getID(), expected, false);
098: assertEquals("Wrong expected result", expected, s
099: .getExpectedResult());
100: s.runStep();
101: }
102:
103: /** Create the assert step without having its class loading context. */
104: public void testCreateWithNoContext() throws Throwable {
105: new Assert(getResolver(), getName(), "unresolvedMethod",
106: "someComponent", "true", false) {
107: protected void setScriptError(Throwable thrown) {
108: fail("Assert should load without error");
109: }
110: };
111: }
112:
113: public AssertTest(String name) {
114: super (name);
115: }
116:
117: public static void main(String[] args) {
118: TestHelper.runTests(args, AssertTest.class);
119: }
120: }
|