001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.datadictionary.validation;
017
018 import static org.junit.Assert.fail;
019
020
021 public final class ValidationTestUtils {
022 private static final String[] TEST_INPUTS = { "", "!!!", "[a-9]", "^A-Z", "abc", "a bc", "a_bc", "123", "12 3", "12_3", "a1b2c3", "a1b2_c3", "a 1b2c3", "a 1b2_c3", "foo.bar", "foo.bar_baz", ".bar_foo baz" };
023
024 private ValidationTestUtils() {
025 throw new UnsupportedOperationException("do not call");
026 }
027
028 public static final void assertPatternMatches(ValidationPattern pattern, boolean[] expectedValues) {
029 if (expectedValues.length != TEST_INPUTS.length) {
030 fail("expectedValues length was " + expectedValues.length + ", expected TEST_INPUTS.length of " + TEST_INPUTS.length);
031 }
032
033 for (int i = 0; i < TEST_INPUTS.length; ++i) {
034 String testInput = TEST_INPUTS[i];
035 boolean expectedResult = expectedValues[i];
036
037 boolean actualResult = pattern.matches(testInput);
038 if (actualResult != expectedResult) {
039 fail("for input '" + testInput + "', expected " + expectedResult + " but got " + actualResult);
040 }
041 }
042 }
043 }