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.report.html; |
12 | |
13 | import java.util.Map; |
14 | import java.util.ResourceBundle; |
15 | import java.util.TreeMap; |
16 | import org.jtiger.framework.TestResultType; |
17 | import static org.jtiger.framework.TestResultType.SUCCESS; |
18 | import static org.jtiger.framework.TestResultType.FAILURE; |
19 | import static org.jtiger.framework.TestResultType.FAILURE_SETUP; |
20 | import static org.jtiger.framework.TestResultType.FAILURE_TEARDOWN; |
21 | import static org.jtiger.framework.TestResultType.IGNORED_ANNOTATED; |
22 | import static org.jtiger.framework.TestResultType.IGNORED_CANNOT_INVOKE; |
23 | |
24 | final class ResultMappingFactory |
25 | { |
26 | public static final String BUNDLE = "org/jtiger/report/html/ResultMapping"; |
27 | |
28 | private ResultMappingFactory() |
29 | { |
30 | |
31 | } |
32 | |
33 | static ResultMapping newResultMapping() |
34 | { |
35 | return new ResultMappingImpl(); |
36 | } |
37 | |
38 | private static final class ResultMappingImpl implements ResultMapping |
39 | { |
40 | private final Map<TestResultType, String> mapping; |
41 | private final Map<String, TestResultType> reverseMapping; |
42 | |
43 | ResultMappingImpl() |
44 | { |
45 | mapping = new TreeMap<TestResultType, String>(); |
46 | reverseMapping = new TreeMap<String, TestResultType>(); |
47 | |
48 | final String failure = ResourceBundle.getBundle(BUNDLE).getString("failure"); |
49 | final String failureSetup = ResourceBundle.getBundle(BUNDLE).getString("failure.setup"); |
50 | final String failureTeardown = ResourceBundle.getBundle(BUNDLE).getString("failure.teardown"); |
51 | final String ignoredAnnotated = ResourceBundle.getBundle(BUNDLE).getString("ignored.annotated"); |
52 | final String ignoredCannotInvoke = ResourceBundle.getBundle(BUNDLE).getString("ignored.cannot.invoke"); |
53 | final String success = ResourceBundle.getBundle(BUNDLE).getString("success"); |
54 | |
55 | mapping.put(FAILURE, failure); |
56 | mapping.put(FAILURE_SETUP, failureSetup); |
57 | mapping.put(FAILURE_TEARDOWN, failureTeardown); |
58 | mapping.put(IGNORED_ANNOTATED, ignoredAnnotated); |
59 | mapping.put(IGNORED_CANNOT_INVOKE, ignoredCannotInvoke); |
60 | mapping.put(SUCCESS, success); |
61 | |
62 | reverseMapping.put(failure, FAILURE); |
63 | reverseMapping.put(failureSetup, FAILURE_SETUP); |
64 | reverseMapping.put(failureTeardown, FAILURE_TEARDOWN); |
65 | reverseMapping.put(ignoredAnnotated, IGNORED_ANNOTATED); |
66 | reverseMapping.put(ignoredCannotInvoke, IGNORED_CANNOT_INVOKE); |
67 | reverseMapping.put(success, SUCCESS); |
68 | } |
69 | |
70 | public String getResultMapping(final TestResultType result) |
71 | { |
72 | if(result == null) |
73 | { |
74 | return null; |
75 | } |
76 | |
77 | return mapping.get(result); |
78 | } |
79 | |
80 | public TestResultType getResultMapping(final String s) |
81 | { |
82 | if(s == null) |
83 | { |
84 | return null; |
85 | } |
86 | |
87 | return reverseMapping.get(s); |
88 | } |
89 | } |
90 | } |