@@ -0,0 +1,2092 @@
+/**%0A * Copyright 2010 OpenEngSB Division, Vienna University of Technology%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * 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 */%0A%0Apackage org.openengsb.core.test.rules;%0A%0Aimport org.junit.rules.MethodRule;%0Aimport org.junit.runners.model.FrameworkMethod;%0Aimport org.junit.runners.model.Statement;%0A%0A/**%0A * Use this rule to run every test in a separate Thread. This is useful when testing code using%0A * %7B@link java.lang.ThreadLocal%7D%0A *%0A * Usage: create a public field in your testclass and annotate it with %3Ccode%3E@Rule%3C/code%3E%0A * %3Ccode%3Epublic DedicatedThread threadRule = new DedicatedThread();%3C/code%3E%0A */%0Apublic final class DedicatedThread implements MethodRule %7B%0A%0A    private class ThreadStatement extends Statement %7B%0A        private Throwable thrown;%0A        private Statement parent;%0A%0A        public ThreadStatement(Statement parent) %7B%0A            this.parent = parent;%0A        %7D%0A%0A        @Override%0A        public void evaluate() throws Throwable %7B%0A            Thread thread = new Thread() %7B%0A                @Override%0A                public void run() %7B%0A                    try %7B%0A                        parent.evaluate();%0A                    %7D catch (Throwable e) %7B%0A                        thrown = e;%0A                    %7D%0A                %7D%0A            %7D;%0A            thread.start();%0A            thread.join();%0A            if (thrown != null) %7B%0A                throw thrown;%0A            %7D%0A        %7D%0A    %7D%0A%0A    @Override%0A    public Statement apply(final Statement statement, final FrameworkMethod frameworkMethod, final Object o) %7B%0A        return new ThreadStatement(statement);%0A    %7D%0A%7D%0A

add DedicatedTdThread-Rule for junit-tests using Threadlocals