001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.plugins.matcher;
019:
020: import junit.framework.TestCase;
021:
022: /**
023: * Base test classes for PatternMatcher testcase implementation
024: */
025: public abstract class AbstractPatternMatcherTest extends TestCase {
026: protected PatternMatcher patternMatcher;
027:
028: protected boolean exact;
029:
030: protected abstract void setUp() throws Exception;
031:
032: protected void setUp(PatternMatcher matcher, boolean exact) {
033: this .patternMatcher = matcher;
034: this .exact = exact;
035: }
036:
037: public void testAnyExpression() {
038: Matcher matcher = patternMatcher.getMatcher("*");
039: assertTrue(matcher.matches(""));
040: assertTrue(matcher
041: .matches("We shall transcend borders. The new is old."));
042: assertTrue(matcher.matches(" "));
043: }
044:
045: public void testIsExact() {
046: Matcher matcher = patternMatcher.getMatcher("*");
047: assertEquals(false, matcher.isExact());
048: matcher.matches("The words aren't what they were.");
049: assertEquals(false, matcher.isExact());
050:
051: matcher = patternMatcher.getMatcher("some expression");
052: assertEquals(exact, matcher.isExact());
053: matcher.matches("The words aren't what they were.");
054: assertEquals(exact, matcher.isExact());
055: }
056:
057: public void testNullInput() {
058: Matcher matcher = patternMatcher.getMatcher("some expression");
059: try {
060: matcher.matches(null);
061: fail("Should fail for null input");
062: } catch (NullPointerException expected) {
063:
064: }
065: }
066:
067: public void testNullExpression() {
068: try {
069: patternMatcher.getMatcher(null);
070: fail("Should fail for null expression");
071: } catch (NullPointerException expected) {
072:
073: }
074: }
075:
076: public abstract void testImplementation();
077:
078: public void testLoadTestMatches() {
079: Matcher matcher = patternMatcher
080: .getMatcher("this.is.an.expression");
081: String[] inputs = { "this.is.an.expression",
082: "this:is:an:expression", "this is an expression",
083: "whatever this is", "maybe, maybe not" };
084: for (int i = 0; i < 100000; i++) {
085: String input = inputs[i % inputs.length];
086: matcher.matches(input);
087: }
088: }
089:
090: public void testLoadTestGetMatcher() {
091: String[] inputs = { "this.is.an.expression",
092: "this:is:an:expression", "this is an expression",
093: "whatever this is", "maybe, maybe not" };
094:
095: for (int i = 0; i < 100000; i++) {
096: String expression = inputs[i % inputs.length];
097: patternMatcher.getMatcher(expression);
098: }
099: }
100: }
|