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.testutil;
04:
05: import java.util.regex.Matcher;
06: import java.util.regex.Pattern;
07:
08: import junit.framework.TestCase;
09:
10: public class RegexTest extends TestCase {
11: public void testKeepJunitFromWarning() throws Exception {
12: // FIXME: Dropped a test in to keep the warning from occurring
13: assertEquals(0, 0);
14: }
15:
16: public static void assertMatches(String regexp, String string) {
17: assertHasRegexp(regexp, string);
18: }
19:
20: public static void assertNotMatches(String regexp, String string) {
21: assertDoesntHaveRegexp(regexp, string);
22: }
23:
24: public static void assertHasRegexp(String regexp, String output) {
25: Matcher match = Pattern.compile(regexp,
26: Pattern.MULTILINE | Pattern.DOTALL).matcher(output);
27: boolean found = match.find();
28: if (!found)
29: fail("The regexp <" + regexp + "> was not found.");
30: }
31:
32: public static void assertDoesntHaveRegexp(String regexp,
33: String output) {
34: Matcher match = Pattern.compile(regexp, Pattern.MULTILINE)
35: .matcher(output);
36: boolean found = match.find();
37: if (found)
38: fail("The regexp <" + regexp + "> was found.");
39: }
40:
41: public static void assertSubString(String substring, String string) {
42: if (string.indexOf(substring) == -1)
43: fail("substring '" + substring + "' not found.");
44: }
45:
46: public static void assertNotSubString(String subString,
47: String string) {
48: if (string.indexOf(subString) > -1)
49: fail("unexpected substring found");
50: }
51:
52: public static String divWithIdAndContent(String id,
53: String expectedDivContent) {
54: return "<div.*?id=\"" + id + "\".*?>" + expectedDivContent
55: + "</div>";
56: }
57: }
|