01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.wikitext.widgets;
04:
05: import java.util.regex.Matcher;
06: import java.util.regex.Pattern;
07:
08: import fitnesse.testutil.AbstractRegex;
09:
10: public abstract class AbstractWidget extends AbstractRegex {
11: protected void assertMatchEquals(String value, String expected) {
12: Matcher match = Pattern.compile(getRegexp(),
13: Pattern.DOTALL | Pattern.MULTILINE).matcher(value);
14: if (expected != null) {
15: assertTrue("pattern not found in: " + value, match.find());
16: assertEquals(expected, match.group());
17: } else {
18: boolean found = match.find();
19: assertTrue((found ? match.group() : "nothing")
20: + " was found in: " + value, !found);
21: }
22: }
23:
24: protected void assertMatches(String s) {
25: assertMatchEquals(s, s);
26: }
27:
28: protected void assertNoMatch(String s) {
29: assertMatchEquals(s, null);
30: }
31:
32: protected abstract String getRegexp();
33: }
|