View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
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.rice.krad.datadictionary.validation;
17  
18  import junit.framework.AssertionFailedError;
19  
20  /**
21   * UTF8ValidationTestUtils has test values and a method used in {@link org.kuali.rice.krad.datadictionary.validation.charlevel.UTF8AnyCharacterValidationPatternTest}
22   *
23   * @author Kuali Rice Team (rice.collab@kuali.org)
24   */
25  public class UTF8ValidationTestUtils {
26  	static final String[] TEST_INPUTS = { "", "!!!", "[a-9]", "^A-Z", "abc", "a bc", "a_bc", "123", "12 3", "12_3", 
27  		"a1b2c3", "a1b2_c3", "a 1b2c3", "a 1b2_c3", "foo.bar", "foo.bar_baz", ".bar_foo baz", 
28  		"!\"#abs$%&'()*+,./:;<=abs>?@\\^_abs`{|}~-", "\u00E6\u00E6", "\t", "\u00E6 \u00E6"};
29  
30      /**
31       * checks that the test values, when matched to the supplied pattern, result in the expected value
32       * @param pattern - a validation pattern
33       * @param expectedValues - an array containing boolean values for each expected result
34       */
35  	public static final void assertPatternMatches(ValidationPattern pattern, boolean[] expectedValues) {
36  
37  		if (expectedValues.length != TEST_INPUTS.length) {
38  			throw new AssertionFailedError("expectedValues length was " + expectedValues.length + ", expected TEST_INPUTS.length of " + TEST_INPUTS.length);
39  		}
40  
41  		for (int i = 0; i < TEST_INPUTS.length; ++i) {
42  			String testInput = TEST_INPUTS[i];
43  			boolean expectedResult = expectedValues[i];
44  
45  			boolean actualResult = pattern.matches(testInput);
46  			if (actualResult != expectedResult) {
47  				throw new AssertionFailedError("for input '" + testInput + "', expected " + expectedResult + " but got " + actualResult);
48  			}
49  		}
50  	}
51  }