001    /**
002     * Copyright 2005-2014 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 junit.framework.AssertionFailedError;
019    
020    /**
021     * UTF8ValidationTestUtils has test values and a method used in {@link org.kuali.rice.krad.datadictionary.validation.charlevel.UTF8AnyCharacterValidationPatternTest}
022     *
023     * @author Kuali Rice Team (rice.collab@kuali.org)
024     */
025    public class UTF8ValidationTestUtils {
026            static final String[] TEST_INPUTS = { "", "!!!", "[a-9]", "^A-Z", "abc", "a bc", "a_bc", "123", "12 3", "12_3", 
027                    "a1b2c3", "a1b2_c3", "a 1b2c3", "a 1b2_c3", "foo.bar", "foo.bar_baz", ".bar_foo baz", 
028                    "!\"#abs$%&'()*+,./:;<=abs>?@\\^_abs`{|}~-", "\u00E6\u00E6", "\t", "\u00E6 \u00E6"};
029    
030        /**
031         * checks that the test values, when matched to the supplied pattern, result in the expected value
032         * @param pattern - a validation pattern
033         * @param expectedValues - an array containing boolean values for each expected result
034         */
035            public static final void assertPatternMatches(ValidationPattern pattern, boolean[] expectedValues) {
036    
037                    if (expectedValues.length != TEST_INPUTS.length) {
038                            throw new AssertionFailedError("expectedValues length was " + expectedValues.length + ", expected TEST_INPUTS.length of " + TEST_INPUTS.length);
039                    }
040    
041                    for (int i = 0; i < TEST_INPUTS.length; ++i) {
042                            String testInput = TEST_INPUTS[i];
043                            boolean expectedResult = expectedValues[i];
044    
045                            boolean actualResult = pattern.matches(testInput);
046                            if (actualResult != expectedResult) {
047                                    throw new AssertionFailedError("for input '" + testInput + "', expected " + expectedResult + " but got " + actualResult);
048                            }
049                    }
050            }
051    }