01: // Copyright © 2002-2005 Canoo Engineering AG, Switzerland.
02: package com.canoo.webtest.engine;
03:
04: import java.util.regex.Pattern;
05:
06: /**
07: * Compares string evaluating the expected value as a regular expression
08: * @see java.util.regex.Pattern
09: * @author Carsten Seibert, Dierk Koenig
10: * @author Marc Guillemot
11: */
12: public class RegExStringVerifier implements IStringVerifier {
13: public static final IStringVerifier INSTANCE = new RegExStringVerifier();
14:
15: /**
16: * @param pattern the pattern to search for
17: * @see com.canoo.webtest.engine.IStringVerifier#verifyStrings(java.lang.String, java.lang.String)
18: * @return <code>true</code> if the pattern can be found in the actual value
19: */
20: public boolean verifyStrings(final String pattern,
21: final String actualValue) {
22: if (pattern == null) {
23: return false;
24: }
25: // "." should match new lines as well, therefore the dotall flag
26: return Pattern.compile(pattern, Pattern.DOTALL).matcher(
27: actualValue).find();
28: }
29: }
|