01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.core.datadictionary.validation;
17:
18: import junit.framework.AssertionFailedError;
19:
20: public class ValidationTestUtils {
21: private static final String[] TEST_INPUTS = { "", "!!!", "[a-9]",
22: "^A-Z", "abc", "a bc", "a_bc", "123", "12 3", "12_3",
23: "a1b2c3", "a1b2_c3", "a 1b2c3", "a 1b2_c3" };
24:
25: public static final void assertPatternMatches(
26: ValidationPattern pattern, boolean[] expectedValues) {
27: if (expectedValues.length != TEST_INPUTS.length) {
28: throw new AssertionFailedError("expectedValues length was "
29: + expectedValues.length
30: + ", expected TEST_INPUTS.length of "
31: + TEST_INPUTS.length);
32: }
33:
34: for (int i = 0; i < TEST_INPUTS.length; ++i) {
35: String testInput = TEST_INPUTS[i];
36: boolean expectedResult = expectedValues[i];
37:
38: boolean actualResult = pattern.matches(testInput);
39: if (actualResult != expectedResult) {
40: throw new AssertionFailedError("for input '"
41: + testInput + "', expected " + expectedResult
42: + " but got " + actualResult);
43: }
44: }
45: }
46: }
|