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 static org.jtiger.framework.SequenceFactory.newSequence; |
14 | import java.lang.reflect.Method; |
15 | import java.util.Arrays; |
16 | import java.util.LinkedHashSet; |
17 | import java.util.Set; |
18 | |
19 | final class TestMethodCategoriesFactory |
20 | { |
21 | private TestMethodCategoriesFactory() |
22 | { |
23 | |
24 | } |
25 | |
26 | static TestMethodCategories newTestMethodCategories() |
27 | { |
28 | return new TestMethodCategoriesImpl(); |
29 | } |
30 | |
31 | private static final class TestMethodCategoriesImpl implements TestMethodCategories |
32 | { |
33 | TestMethodCategoriesImpl() |
34 | { |
35 | |
36 | } |
37 | |
38 | public ReadOnlyArray<String> getTestMethodCategories(final Method m) throws NullPointerException |
39 | { |
40 | if(m == null) |
41 | { |
42 | throw new NullPointerException(); |
43 | } |
44 | |
45 | final Category mc = m.getAnnotation(Category.class); |
46 | final Category cc = m.getDeclaringClass().getAnnotation(Category.class); |
47 | |
48 | final Set<String> categories = new LinkedHashSet<String>(); |
49 | |
50 | if(mc != null) |
51 | { |
52 | categories.addAll(Arrays.asList(mc.value())); |
53 | } |
54 | |
55 | if(cc != null) |
56 | { |
57 | categories.addAll(Arrays.asList(cc.value())); |
58 | } |
59 | |
60 | return newSequence(categories.toArray(new String[categories.size()])); |
61 | } |
62 | } |
63 | } |