EMMA Coverage Report (generated Fri Jul 28 01:51:09 CEST 2006)
[all classes][org.jtiger.framework]

COVERAGE SUMMARY FOR SOURCE FILE [TestRunnerFactory.java]

nameclass, %method, %block, %line, %
TestRunnerFactory.java100% (2/2)100% (4/4)76%  (182/240)86%  (34,3/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TestRunnerFactory100% (1/1)100% (2/2)100% (7/7)100% (3/3)
TestRunnerFactory (): void 100% (1/1)100% (3/3)100% (2/2)
newTestRunner (): TestRunner 100% (1/1)100% (4/4)100% (1/1)
     
class TestRunnerFactory$TestRunnerImpl100% (1/1)100% (2/2)75%  (175/233)85%  (31,3/37)
TestRunnerFactory$TestRunnerImpl (): void 100% (1/1)100% (3/3)100% (2/2)
run (Method, Object, SetUpTearDown): TestResult 100% (1/1)75%  (172/230)84%  (29,3/35)

1/*
2 * JTiger Unit Testing Framework for J2SE 1.5
3 * Copyright (C) 2005 Tony Morris
4 *
5 * This software is licenced under the
6 * Common Public Licence version 1.0
7 * http://www.opensource.org/licenses/cpl1.0.php
8 *
9 * You received a copy of this licence with this software.
10 */
11package org.jtiger.framework;
12 
13import java.lang.reflect.InvocationTargetException;
14import java.lang.reflect.Method;
15import static org.jtiger.framework.TestResultFactory.newTestResult;
16import static org.jtiger.framework.TestResultType.SUCCESS;
17import static org.jtiger.framework.TestResultType.FAILURE;
18import static org.jtiger.framework.TestResultType.IGNORED_ANNOTATED;
19import static org.jtiger.framework.TestResultType.IGNORED_CANNOT_INVOKE;
20import static org.jtiger.framework.TestResultType.FAILURE_SETUP;
21import static org.jtiger.framework.TestResultType.FAILURE_TEARDOWN;
22 
23final class TestRunnerFactory
24{
25    private TestRunnerFactory()
26    {
27 
28    }
29 
30    static TestRunner newTestRunner()
31    {
32        return new TestRunnerImpl();
33    }
34 
35    private static final class TestRunnerImpl implements TestRunner
36    {
37        TestRunnerImpl()
38        {
39 
40        }
41 
42        public TestResult run(final Method m, final Object fixture, final SetUpTearDown sutd) throws NullPointerException
43        {
44            if(m == null || fixture == null || sutd == null)
45            {
46                throw new NullPointerException();
47            }
48 
49            if(m.isAnnotationPresent(Ignore.class))
50            {
51                return newTestResult(IGNORED_ANNOTATED,
52                        m.getAnnotation(Ignore.class).value(),  null, null, m);
53            }
54 
55            if(m.getDeclaringClass().isAnnotationPresent(Ignore.class))
56            {
57                return newTestResult(IGNORED_ANNOTATED,
58                        m.getDeclaringClass().getAnnotation(Ignore.class).value(),  null, null, m);
59            }
60 
61            if(m.getParameterTypes().length != 0)
62            {
63                return newTestResult(IGNORED_CANNOT_INVOKE,
64                        Messages.wrongMethodSignature(), null, null, m);
65            }
66 
67            final ExpectException ee = m.getAnnotation(ExpectException.class);
68            
69            try
70            {
71                sutd.setUp(fixture);
72            }
73            catch(SetUpException e)
74            {
75                return newTestResult(FAILURE_SETUP, e.getMessage(), e, null, m);
76            }
77 
78            try
79            {
80                final long t1 = System.currentTimeMillis();
81                final Object ret = m.invoke(fixture);
82                final long t2 = System.currentTimeMillis();
83 
84                m.setAccessible(true);
85 
86                final String message = ret == null ? null : ret.toString();
87 
88                return newTestResult(ee == null ? SUCCESS : FAILURE, message, null, t2 - t1, m);
89            }
90            catch(IllegalAccessException e)
91            {
92                return newTestResult(FAILURE, e.getMessage(), null, null, m);
93            }
94            catch(InvocationTargetException e)
95            {
96                final Throwable cause = e.getCause();
97 
98                if(ee != null)
99                {
100                    final Class<? extends Throwable> expected = ee.value();
101                    final boolean subclass = ee.subclass();
102 
103                    if(subclass ? expected.isAssignableFrom(cause.getClass()) : expected == cause.getClass())
104                    {
105                        return newTestResult(SUCCESS, cause.getMessage(), cause, null, m);
106                    }
107                }
108 
109                return newTestResult(FAILURE, cause.getMessage(), cause, null, m);
110            }
111            finally
112            {
113                try
114                {
115                    sutd.tearDown(fixture);
116                }
117                catch(TearDownException e)
118                {
119                    return newTestResult(FAILURE_TEARDOWN, e.getMessage(), e, null, m);
120                }
121            }
122        }
123    }
124}

[all classes][org.jtiger.framework]
EMMA 2.0.5312 (C) Vladimir Roubtsov