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 | */ |
11 | package org.jtiger.framework; |
12 | |
13 | import java.lang.reflect.Method; |
14 | |
15 | final class TestNameFactory |
16 | { |
17 | private TestNameFactory() |
18 | { |
19 | |
20 | } |
21 | |
22 | static TestName newTestName() |
23 | { |
24 | return new TestNameImpl(); |
25 | } |
26 | |
27 | private static final class TestNameImpl implements TestName |
28 | { |
29 | TestNameImpl() |
30 | { |
31 | |
32 | } |
33 | |
34 | public String getTestName(final Method m) throws NullPointerException |
35 | { |
36 | if(m == null) |
37 | { |
38 | throw new NullPointerException(); |
39 | } |
40 | |
41 | final Test t = m.getAnnotation(Test.class); |
42 | |
43 | if(t == null) |
44 | { |
45 | return m.getName(); |
46 | } |
47 | |
48 | final String value = t.value(); |
49 | |
50 | if(value == null || value.length() == 0) |
51 | { |
52 | return m.getName(); |
53 | } |
54 | else |
55 | { |
56 | return t.value(); |
57 | } |
58 | } |
59 | } |
60 | } |