Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MockRenderKitFactory |
|
| 3.5;3.5 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to you under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | package org.apache.shale.test.mock; | |
19 | ||
20 | import java.util.HashMap; | |
21 | import java.util.Iterator; | |
22 | import java.util.Map; | |
23 | ||
24 | import javax.faces.context.FacesContext; | |
25 | import javax.faces.render.RenderKit; | |
26 | import javax.faces.render.RenderKitFactory; | |
27 | ||
28 | /** | |
29 | * <p>Mock implementation of <code>RenderKitFactory</code>.</p> | |
30 | * | |
31 | * $Id$ | |
32 | */ | |
33 | ||
34 | public class MockRenderKitFactory extends RenderKitFactory { | |
35 | ||
36 | ||
37 | // ------------------------------------------------------------ Constructors | |
38 | ||
39 | ||
40 | /** | |
41 | * <p>Return a default instance.</p> | |
42 | */ | |
43 | 18 | public MockRenderKitFactory() { |
44 | ||
45 | 18 | renderKits = new HashMap(); |
46 | ||
47 | 18 | } |
48 | ||
49 | ||
50 | // ----------------------------------------------------- Mock Object Methods | |
51 | ||
52 | ||
53 | // ------------------------------------------------------ Instance Variables | |
54 | ||
55 | ||
56 | /** | |
57 | * <p>The set of render kits that have been registered here.</p> | |
58 | */ | |
59 | 18 | private Map renderKits = new HashMap(); |
60 | ||
61 | ||
62 | // ------------------------------------------------ RenderKitFactory Methods | |
63 | ||
64 | ||
65 | /** {@inheritDoc} */ | |
66 | public void addRenderKit(String renderKitId, RenderKit renderKit) { | |
67 | ||
68 | 18 | if ((renderKitId == null) || (renderKit == null)) { |
69 | throw new NullPointerException(); | |
70 | } | |
71 | 18 | if (renderKits.containsKey(renderKitId)) { |
72 | throw new IllegalArgumentException(renderKitId); | |
73 | } | |
74 | 18 | renderKits.put(renderKitId, renderKit); |
75 | ||
76 | 18 | } |
77 | ||
78 | ||
79 | /** {@inheritDoc} */ | |
80 | public RenderKit getRenderKit(FacesContext context, String renderKitId) { | |
81 | ||
82 | 2 | if (renderKitId == null) { |
83 | throw new NullPointerException(); | |
84 | } | |
85 | 2 | RenderKit renderKit = (RenderKit) renderKits.get(renderKitId); |
86 | 2 | if (renderKit == null) { |
87 | // Issue 38294 -- We removed the automatic creation of the | |
88 | // default renderkit in the constructor, allowing it to be | |
89 | // added by AbstractJsfTestCase in the usual case. To preserve | |
90 | // backwards compatibility, however, create one on the fly | |
91 | // if the user asks for the default HTML renderkit and it has | |
92 | // not been manually added yet | |
93 | if (RenderKitFactory.HTML_BASIC_RENDER_KIT.equals(renderKitId)) { | |
94 | renderKit = new MockRenderKit(); | |
95 | renderKits.put(RenderKitFactory.HTML_BASIC_RENDER_KIT, | |
96 | renderKit); | |
97 | return renderKit; | |
98 | } | |
99 | throw new IllegalArgumentException(renderKitId); | |
100 | } | |
101 | 2 | return renderKit; |
102 | ||
103 | } | |
104 | ||
105 | ||
106 | /** {@inheritDoc} */ | |
107 | public Iterator getRenderKitIds() { | |
108 | ||
109 | return renderKits.keySet().iterator(); | |
110 | ||
111 | } | |
112 | ||
113 | ||
114 | } |