RegexTest.java :  » Testing » StoryTestIQ » fitnesse » testutil » Java Open Source

Java Open Source » Testing » StoryTestIQ 
StoryTestIQ » fitnesse » testutil » RegexTest.java
// Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the GNU General Public License version 2 or later.
package fitnesse.testutil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import junit.framework.TestCase;

public class RegexTest extends TestCase {
  public void testKeepJunitFromWarning() throws Exception {
    // FIXME: Dropped a test in to keep the warning from occurring
    assertEquals(0, 0);
  }

  public static void assertMatches(String regexp, String string) {
    assertHasRegexp(regexp, string);
  }

  public static void assertNotMatches(String regexp, String string) {
    assertDoesntHaveRegexp(regexp, string);
  }

  public static void assertHasRegexp(String regexp, String output) {
    Matcher match = Pattern.compile(regexp, Pattern.MULTILINE | Pattern.DOTALL).matcher(output);
    boolean found = match.find();
    if (!found)
      fail("The regexp <" + regexp + "> was not found.");
  }

  public static void assertDoesntHaveRegexp(String regexp, String output) {
    Matcher match = Pattern.compile(regexp, Pattern.MULTILINE).matcher(output);
    boolean found = match.find();
    if (found)
      fail("The regexp <" + regexp + "> was found.");
  }

  public static void assertSubString(String substring, String string) {
    if (string.indexOf(substring) == -1)
      fail("substring '" + substring + "' not found.");
  }

  public static void assertNotSubString(String subString, String string) {
    if (string.indexOf(subString) > -1)
      fail("unexpected substring found");
  }

  public static String divWithIdAndContent(String id, String expectedDivContent) {
    return "<div.*?id=\"" + id + "\".*?>" + expectedDivContent + "</div>";
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.