Clover Coverage Report - KS Common 1.3.0-SNAPSHOT (Aggregated)
Coverage timestamp: Thu Apr 28 2011 06:00:36 EDT
../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
18   96   10   3.6
6   48   0.56   5
5     2  
1    
 
  RiceUnitTestClassRunner       Line # 30 18 0% 10 29 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in
5    * compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.opensource.org/licenses/ecl2.php
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS
10    * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
11    * language governing permissions and limitations under the License.
12    */
13    package org.kuali.rice.test.runners;
14   
15    import java.lang.reflect.Method;
16   
17    import org.apache.commons.beanutils.MethodUtils;
18    import org.junit.internal.runners.InitializationError;
19    import org.junit.internal.runners.JUnit4ClassRunner;
20    import org.junit.runner.notification.RunNotifier;
21    import org.kuali.rice.test.MethodAware;
22   
23    /**
24    * A Runner which sets up Rice unit tests appropriately.
25    * 1) It invokes setName() on the Test (if the method exists) and sets it to the name of the test method being invoked.
26    *
27    * @author Kuali Rice Team (rice.collab@kuali.org)
28    * @since 0.9
29    */
 
30    public class RiceUnitTestClassRunner extends JUnit4ClassRunner {
31    //private PerTestDataLoaderLifecycle perTestDataLoaderLifecycle;
32    private Method currentMethod;
33   
 
34  0 toggle public RiceUnitTestClassRunner(final Class<?> testClass) throws InitializationError {
35  0 super(testClass);
36   
37    }
38   
 
39  0 toggle @Override
40    protected void invokeTestMethod(Method method, RunNotifier runNotifier) {
41  0 this.currentMethod = method;
42  0 try {
43    //perTestDataLoaderLifecycle = new PerTestDataLoaderLifecycle(method);
44  0 super.invokeTestMethod(method, runNotifier);
45    } finally {
46  0 this.currentMethod = null;
47    }
48    }
49   
 
50  0 toggle @Override
51    protected Object createTest() throws Exception {
52  0 Object test = super.createTest();
53  0 setTestName(test, currentMethod);
54  0 setTestMethod(test, currentMethod);
55    //setTestPerTestDataLoaderLifecycle(test);
56  0 return test;
57    }
58   
59    /**
60    * Sets the {@link java.lang.reflect.Method} on the test case if it is {@link MethodAware}
61    * @param method the current method to be run
62    */
 
63  0 toggle protected void setTestMethod(Object test, Method method) {
64  0 try {
65  0 if (test instanceof MethodAware) {
66  0 ((MethodAware) test).setTestMethod(method);
67    }
68    } catch (Exception e) {
69  0 e.printStackTrace();
70    // something went horribly wrong?
71    }
72    }
73   
74    /*
75    protected void setTestPerTestDataLoaderLifecycle(final Object test) {
76    try {
77    final Method setPerTestDataLoaderLifecycle = MethodUtils.getAccessibleMethod(test.getClass(), "setPerTestDataLoaderLifecycle", new Class[]{PerTestDataLoaderLifecycle.class});
78    setPerTestDataLoaderLifecycle.invoke(test, new Object[]{perTestDataLoaderLifecycle});
79    } catch (final Exception e) {
80    // no setPerTestDataLoaderLifecycle method or we failed to invoke it so we can't set the lifecycle
81    }
82    }*/
83   
 
84  0 toggle protected void setTestName(final Object test, final Method testMethod) {
85  0 try {
86  0 String name = testMethod == null ? "" : testMethod.getName();
87  0 final Method setNameMethod = MethodUtils.getAccessibleMethod(test.getClass(), "setName", new Class[]{String.class});
88  0 if (setNameMethod != null) {
89  0 setNameMethod.invoke(test, new Object[]{name});
90    }
91    } catch (final Exception e) {
92    // no setName method or we failed to invoke it so we can't set the name
93    }
94    }
95   
96    }