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.uif.util;
17
18 import java.util.concurrent.Callable;
19
20 import org.junit.Rule;
21 import org.junit.rules.MethodRule;
22 import org.junit.runners.model.FrameworkMethod;
23 import org.junit.runners.model.Statement;
24
25 /**
26 * Base class for wrapping all JUnit tests in call to
27 * {@link ProcessLogger#follow(String, String, Callable)}.
28 *
29 * @author Kuali Rice Team (rice.collab@kuali.org)
30 */
31 public class ProcessLoggingUnitTest {
32
33 @Rule
34 public MethodRule processLogRule = new MethodRule() {
35 @Override
36 public Statement apply(final Statement base,
37 final FrameworkMethod method, Object target) {
38 return new Statement() {
39 @Override
40 public void evaluate() throws Throwable {
41 try {
42 ProcessLogger.follow("test", "Test Run " + method.getName(), new Callable<Void>() {
43
44 @Override
45 public Void call() throws Exception {
46 try {
47 base.evaluate();
48 } catch (Throwable e) {
49 if (e instanceof Error)
50 throw (Error) e;
51 else
52 throw (Exception) e;
53 }
54 return null;
55 }
56
57 @Override
58 public String toString() {
59 return "Test Run " + method.getName();
60 }
61 });
62 } catch (Throwable t) {
63 System.err.println("Error running test "
64 + method.getName());
65 t.printStackTrace();
66 throw t;
67 }
68 }
69 };
70 }
71 };
72
73 }