@@ -0,0 +1,3908 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one%0A * or more contributor license agreements.  See the NOTICE file%0A * distributed with this work for additional information%0A * regarding copyright ownership.  The ASF licenses this file%0A * to you under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance%0A * with the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.apache.pig.test.junit;%0A%0Aimport static java.lang.annotation.ElementType.TYPE;%0A%0Aimport java.lang.annotation.Retention;%0Aimport java.lang.annotation.Target;%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0Aimport org.junit.runners.BlockJUnit4ClassRunner;%0Aimport org.junit.runners.model.FrameworkMethod;%0Aimport org.junit.runners.model.InitializationError;%0A%0Apublic class OrderedJUnit4Runner extends BlockJUnit4ClassRunner %7B%0A%0A    @Retention(java.lang.annotation.RetentionPolicy.RUNTIME)%0A    @Target(TYPE)%0A    public @interface TestOrder %7B%0A        String%5B%5D value();%0A    %7D%0A%0A    private String testClassName;%0A    private String%5B%5D orderedTestMethods;%0A    private List%3CFrameworkMethod%3E methodsCustomOrder;%0A%0A    public OrderedJUnit4Runner(Class%3C?%3E klass) throws InitializationError %7B%0A        super(klass);%0A        TestOrder testOrder = klass.getAnnotation(TestOrder.class);%0A        if (testOrder != null) %7B%0A            orderedTestMethods = testOrder.value();%0A        %7D%0A        this.testClassName = klass.getName();%0A    %7D%0A%0A    @Override%0A    protected List%3CFrameworkMethod%3E computeTestMethods() %7B%0A        List%3CFrameworkMethod%3E methodsReflectionOrder = super%0A                .computeTestMethods();%0A        if (orderedTestMethods == null %7C%7C orderedTestMethods.length == 0) %7B%0A            return methodsReflectionOrder;%0A        %7D else %7B%0A%0A            if (methodsCustomOrder == null) %7B%0A                // Check for duplicate test methods%0A                Set%3CString%3E uniqueMethods = new HashSet%3CString%3E();%0A                Collections.addAll(uniqueMethods, orderedTestMethods);%0A                if (uniqueMethods.size() != orderedTestMethods.length) %7B%0A                    throw new IllegalArgumentException(%0A                            %22The TestOrder annotation in %22 + testClassName%0A                                    + %22 has duplicate test method names%22);%0A                %7D%0A%0A                methodsCustomOrder = new ArrayList%3CFrameworkMethod%3E();%0A                for (String method : orderedTestMethods) %7B%0A                    for (FrameworkMethod fMethod : methodsReflectionOrder) %7B%0A                        if (fMethod.getName().equals(method)) %7B%0A                            methodsCustomOrder.add(fMethod);%0A                            break;%0A                        %7D%0A                    %7D%0A                %7D%0A%0A                // Check for missing test methods%0A                methodsReflectionOrder.removeAll(methodsCustomOrder);%0A                if (methodsReflectionOrder.size() %3E 0) %7B%0A                    String tests = %22%22;%0A                    for (FrameworkMethod fMethod : methodsReflectionOrder) %7B%0A                        tests = tests + fMethod.getName();%0A                    %7D%0A                    throw new IllegalArgumentException(%0A                            %22The TestOrder annotation in %22 + testClassName%0A                            + %22 does not include the following tests which have @Test: %22%0A                            + tests);%0A                %7D%0A            %7D%0A            return methodsCustomOrder;%0A        %7D%0A    %7D%0A%0A%7D%0A

Add test/org/apache/pig/test/junit for PIG-2908