EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hiveutils.test]

COVERAGE SUMMARY FOR SOURCE FILE [TestSuiteHelper.java]

nameclass, %method, %block, %line, %
TestSuiteHelper.java50%  (1/2)50%  (4/8)68%  (95/140)72%  (23/32)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TestSuiteHelper$10%   (0/1)0%   (0/2)0%   (0/11)0%   (0/3)
TestSuiteHelper$1 (String, String): void 0%   (0/1)0%   (0/7)0%   (0/1)
runTest (): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class TestSuiteHelper100% (1/1)67%  (4/6)74%  (95/129)79%  (23/29)
TestSuiteHelper (): void 0%   (0/1)0%   (0/3)0%   (0/2)
warning (String): Test 0%   (0/1)0%   (0/6)0%   (0/1)
addTestMethod (TestSuite, Method, List, TestFactory): void 100% (1/1)65%  (24/37)80%  (8/10)
addAllTests (TestSuite, Class, TestFactory): void 100% (1/1)75%  (36/48)91%  (10/11)
isPublicTestMethod (Method): boolean 100% (1/1)100% (11/11)100% (1/1)
isTestMethod (Method): boolean 100% (1/1)100% (24/24)100% (4/4)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hiveutils.test;
16 
17import java.lang.reflect.Method;
18import java.lang.reflect.Modifier;
19import java.util.ArrayList;
20import java.util.List;
21 
22import junit.framework.Test;
23import junit.framework.TestCase;
24import junit.framework.TestSuite;
25 
26/**
27 * @author Jean-Francois Poilpret
28 */
29final public class TestSuiteHelper
30{
31        private TestSuiteHelper()
32        {
33        }
34        
35        static public void        addAllTests(TestSuite suite, Class clazz, TestFactory factory)
36        {
37                Class superClass = clazz;
38                List<String> names = new ArrayList<String>();
39                while (Test.class.isAssignableFrom(superClass))
40                {
41                        Method[] methods = superClass.getDeclaredMethods();
42                        for (int i = 0; i < methods.length; i++)
43                        {
44                                addTestMethod(suite, methods[i], names, factory);
45                        }
46                        superClass = superClass.getSuperclass();
47                }
48                if (suite.testCount() == 0)
49                {
50                        suite.addTest(warning("No tests found in " + clazz.getName()));
51                }
52        }
53        
54        static private void addTestMethod(        TestSuite                suite,
55                                                                                Method                        m,
56                                                                                List<String>        names, 
57                                                                                TestFactory                factory)
58        {
59                String name = m.getName();
60                if (names.contains(name))
61                {
62                        return;
63                }
64                if (!isPublicTestMethod(m))
65                {
66                        if (isTestMethod(m))
67                        {
68                                suite.addTest(warning("Test method isn't public: " + m.getName()));
69                        }
70                        return;
71                }
72                names.add(name);
73                suite.addTest(factory.createTest(name));
74        }
75 
76        static private boolean isPublicTestMethod(Method m)
77        {
78                return isTestMethod(m) && Modifier.isPublic(m.getModifiers());
79        }
80         
81        static private boolean isTestMethod(Method m)
82        {
83                String name = m.getName();
84                Class[] parameters = m.getParameterTypes();
85                Class returnType = m.getReturnType();
86                return                (parameters.length == 0)
87                                &&        (name.startsWith("test") && returnType.equals(Void.TYPE));
88         }
89         
90        static private Test warning(final String message)
91        {
92                return new TestCase("warning")
93                {
94                        protected void runTest()
95                        {
96                                fail(message);
97                        }
98                };
99        }
100}

[all classes][net.sourceforge.hiveutils.test]
EMMA 2.0.5312 (C) Vladimir Roubtsov