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

COVERAGE SUMMARY FOR SOURCE FILE [DefaultSetUpTearDownFactory.java]

nameclass, %method, %block, %line, %
DefaultSetUpTearDownFactory.java100% (2/2)100% (5/5)90%  (142/158)91%  (39/43)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DefaultSetUpTearDownFactory100% (1/1)100% (2/2)100% (7/7)100% (3/3)
DefaultSetUpTearDownFactory (): void 100% (1/1)100% (3/3)100% (2/2)
newDefaultSetUpTearDown (): SetUpTearDown 100% (1/1)100% (4/4)100% (1/1)
     
class DefaultSetUpTearDownFactory$DefaultSetUpTearDownImpl100% (1/1)100% (3/3)89%  (135/151)90%  (36/40)
DefaultSetUpTearDownFactory$DefaultSetUpTearDownImpl (): void 100% (1/1)100% (3/3)100% (2/2)
setUp (Object): void 100% (1/1)89%  (66/74)89%  (17/19)
tearDown (Object): void 100% (1/1)89%  (66/74)89%  (17/19)

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 java.util.Arrays;
16import java.util.HashSet;
17import java.util.Set;
18 
19/**
20 * The default implementation of setting up and tearing down a unit test case.
21 * This implementation searches for the {@link SetUp} annotation present on a method and calls it to set up a test case.
22 * This implementation searches for the {@link TearDown} annotation present on a method and calls it to tear down a test
23 * case. If more than one method contains either of these annotations, it cannot be guaranteed which order they are
24 * executed in.
25 *
26 * @see SetUpTearDown
27 * @author %javadoc.author.tag%
28 * @version %version%<br/>
29 *          <i>Build Number %build.number%</i><br/>
30 *          <i>Build Time %build.time% CET (GMT + 1)</i>
31 */
32public final class DefaultSetUpTearDownFactory
33{
34    private DefaultSetUpTearDownFactory()
35    {
36 
37    }
38 
39    /**
40     * Returns a new instance of the default implementation to handle setting up and tearing down of unit test cases.
41     *
42     * @return A new instance of the default implementation to handle setting up and tearing down of unit test cases.
43     */
44    public static SetUpTearDown newDefaultSetUpTearDown()
45    {
46        return new DefaultSetUpTearDownImpl();
47    }
48 
49    private static final class DefaultSetUpTearDownImpl implements SetUpTearDown
50    {
51        DefaultSetUpTearDownImpl()
52        {
53 
54        }
55 
56        public void setUp(final Object fixture) throws SetUpException
57        {
58            final Class<?> c = fixture.getClass();
59 
60            final Method[] methods = c.getMethods();
61            final Method[] declaredMethods = c.getDeclaredMethods();
62            final Set<Method> allMethods = new HashSet<Method>(Arrays.asList(methods));
63            allMethods.addAll(Arrays.asList(declaredMethods));
64 
65            for(Method m : allMethods)
66            {
67                if(m.getParameterTypes().length == 0 && m.isAnnotationPresent(SetUp.class))
68                {
69                    final boolean isAccessible = m.isAccessible();
70 
71                    if(!isAccessible)
72                    {
73                        m.setAccessible(true);
74                    }
75 
76                    try
77                    {
78                        m.invoke(fixture);
79                    }
80                    catch(IllegalAccessException e)
81                    {
82                        throw new SetUpException(e.getMessage(), e);
83                    }
84                    catch(InvocationTargetException e)
85                    {
86                        throw new SetUpException(e.getMessage(), e);
87                    }
88 
89                    m.setAccessible(isAccessible);
90                }
91            }
92        }
93 
94        public void tearDown(final Object fixture) throws TearDownException
95        {
96            final Class<?> c = fixture.getClass();
97 
98            final Method[] methods = c.getMethods();
99            final Method[] declaredMethods = c.getDeclaredMethods();
100            final Set<Method> allMethods = new HashSet<Method>(Arrays.asList(methods));
101            allMethods.addAll(Arrays.asList(declaredMethods));
102 
103            for(Method m : allMethods)
104            {
105                if(m.getParameterTypes().length == 0 && m.isAnnotationPresent(TearDown.class))
106                {
107                    final boolean isAccessible = m.isAccessible();
108 
109                    if(!isAccessible)
110                    {
111                        m.setAccessible(true);
112                    }
113 
114                    try
115                    {
116                        m.invoke(fixture);
117                    }
118                    catch(IllegalAccessException e)
119                    {
120                        throw new TearDownException(e.getMessage(), e);
121                    }
122                    catch(InvocationTargetException e)
123                    {
124                        throw new TearDownException(e.getMessage(), e);
125                    }
126 
127                    m.setAccessible(isAccessible);
128                }
129            }
130        }
131    }
132}

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