01: package org.uispec4j.utils;
02:
03: import junit.framework.AssertionFailedError;
04: import junit.framework.TestCase;
05: import org.uispec4j.UISpec4J;
06: import org.uispec4j.assertion.Assertion;
07: import org.uispec4j.assertion.UISpecAssert;
08: import org.uispec4j.interception.InterceptionError;
09:
10: import java.util.Locale;
11:
12: public abstract class UnitTestCase extends TestCase {
13: static {
14: UISpec4J.init();
15: Locale.setDefault(Locale.ENGLISH);
16: }
17:
18: protected void setUp() throws Exception {
19: UISpec4J.setWindowInterceptionTimeLimit(30);
20: UISpec4J.setAssertionTimeLimit(30);
21: }
22:
23: public void assertTrue(Assertion assertion) {
24: UISpecAssert.assertTrue(assertion);
25: }
26:
27: public void waitUntil(Assertion assertion, int timeLimit) {
28: UISpecAssert.waitUntil(assertion, timeLimit);
29: }
30:
31: public void assertFalse(Assertion assertion) {
32: UISpecAssert.assertFalse(assertion);
33: }
34:
35: public Assertion not(Assertion assertion) {
36: return UISpecAssert.not(assertion);
37: }
38:
39: public void assertEquals(boolean expected, Assertion assertion) {
40: UISpecAssert.assertEquals(expected, assertion);
41: }
42:
43: protected void checkAssertionFails(Assertion assertion,
44: String expectedMessage) throws Exception {
45: try {
46: assertTrue(assertion);
47: throw new AssertionFailureNotDetectedError();
48: } catch (AssertionFailedError e) {
49: assertEquals(expectedMessage, e.getMessage());
50: }
51: }
52:
53: protected void checkException(Functor functor,
54: String expectedMessage) throws Exception {
55: try {
56: functor.run();
57: throw new AssertionFailureNotDetectedError();
58: } catch (Exception e) {
59: assertEquals(expectedMessage, e.getMessage());
60: }
61: }
62:
63: protected void checkInterceptionError(Functor functor,
64: String expectedMessage) throws Exception {
65: try {
66: functor.run();
67: throw new AssertionFailureNotDetectedError();
68: } catch (InterceptionError e) {
69: assertEquals(expectedMessage, e.getMessage());
70: }
71: }
72:
73: protected void checkAssertionFailedError(Functor functor,
74: String expectedMessage) throws Exception {
75: try {
76: functor.run();
77: throw new AssertionFailureNotDetectedError();
78: } catch (Throwable e) {
79: assertEquals(expectedMessage, e.getMessage());
80: }
81: }
82:
83: protected void checkAssertionFailedError(Functor functor)
84: throws Exception {
85: try {
86: functor.run();
87: throw new AssertionFailureNotDetectedError();
88: } catch (AssertionFailedError e) {
89: } catch (InterceptionError e) {
90: }
91: }
92: }
|