01: package org.uispec4j;
02:
03: import junit.framework.AssertionFailedError;
04: import org.uispec4j.utils.AssertionFailureNotDetectedError;
05:
06: public abstract class TextBoxComponentTestCase extends
07: UIComponentTestCase {
08: TextBox textBox;
09:
10: protected abstract void createTextBox(String text);
11:
12: public void testAssertTextContainsWithArray() throws Exception {
13: String text = "Universal <b>rules</b>:" + "<ul>"
14: + "<li>item1</li>" + "<li>item2</li>"
15: + "<li>item3</li>" + "</ul>";
16: createTextBox(text);
17:
18: assertTrue(textBox.textContains(new String[0]));
19: assertTrue(textBox.textContains(new String[] { "item1" }));
20: assertTrue(textBox.textContains(new String[] { "item1",
21: "item2", "item3", "ul" }));
22: assertTrue(textBox.textContains(new String[] { "item1", "item",
23: "item" }));
24:
25: String renderedText = textBox.getText();
26: checkAssertTextContainsFails(new String[] { "item2", "item1" },
27: "The component text does not contain 'item1' at the expected position"
28: + " - actual content is:" + renderedText);
29: checkAssertTextContainsFails(new String[] { "item3", "item" },
30: "The component text does not contain 'item' at the expected position"
31: + " - actual content is:" + renderedText);
32: checkAssertTextContainsFails(new String[] { "item2", "toto" },
33: "The component text does not contain 'toto'"
34: + " - actual content is:" + renderedText);
35: }
36:
37: private void checkAssertTextContainsFails(String[] texts,
38: String error) {
39: try {
40: assertTrue(textBox.textContains(texts));
41: throw new AssertionFailureNotDetectedError();
42: } catch (AssertionFailedError e) {
43: assertEquals(error, e.getMessage());
44: }
45: }
46:
47: protected UIComponent createComponent() {
48: return textBox;
49: }
50: }
|