1
2
3
4 package org.melati.servlet.test;
5
6 import java.io.InputStream;
7 import java.net.MalformedURLException;
8 import java.net.URL;
9 import java.util.Enumeration;
10 import java.util.Hashtable;
11 import java.util.Set;
12
13 import javax.servlet.RequestDispatcher;
14 import javax.servlet.Servlet;
15 import javax.servlet.ServletContext;
16 import javax.servlet.ServletException;
17
18
19
20
21
22
23 public class MockServletContext implements ServletContext {
24
25
26
27
28
29 public String getContextPath() {
30 throw new RuntimeException("TODO No one else has ever called this method." +
31 " Do you really want to start now?");
32
33 }
34
35
36
37
38 public MockServletContext() {
39 }
40
41
42
43
44
45 public Object getAttribute(String name) {
46 return null;
47 }
48
49
50
51
52
53 public Enumeration<String> getAttributeNames() {
54 return null;
55 }
56
57
58
59
60
61 public ServletContext getContext(String uripath) {
62 return null;
63 }
64
65
66
67
68
69 public String getInitParameter(String name) {
70 return null;
71 }
72
73
74
75
76
77 public Enumeration<String> getInitParameterNames() {
78 return null;
79 }
80
81
82
83
84
85 public int getMajorVersion() {
86 return 0;
87 }
88
89
90
91
92
93 public String getMimeType(String file) {
94 return null;
95 }
96
97
98
99
100
101 public int getMinorVersion() {
102 return 0;
103 }
104
105
106
107
108
109 public RequestDispatcher getNamedDispatcher(String name) {
110 return null;
111 }
112
113
114
115
116
117 public String getRealPath(String path) {
118 return "/dist/melati/melati/src/test/webapp";
119 }
120
121
122
123
124
125 public RequestDispatcher getRequestDispatcher(String path) {
126 return null;
127 }
128
129
130
131
132
133 public URL getResource(String path) throws MalformedURLException {
134 return null;
135 }
136
137
138
139
140
141 public InputStream getResourceAsStream(String path) {
142 return null;
143 }
144
145
146
147
148
149 public Set<String> getResourcePaths(String arg0) {
150 return null;
151 }
152
153
154
155
156
157 public String getServerInfo() {
158 return null;
159 }
160
161
162
163
164
165 public Servlet getServlet(String name) throws ServletException {
166 return null;
167 }
168
169
170
171
172
173 public String getServletContextName() {
174 return null;
175 }
176
177
178
179
180
181 public Enumeration<String> getServletNames() {
182 return null;
183 }
184
185
186
187
188
189 public Enumeration<?> getServlets() {
190 return null;
191 }
192
193
194
195
196
197 public void log(String msg) {
198 }
199
200
201
202
203
204 public void log(Exception exception, String msg) {
205 }
206
207
208
209
210
211 public void log(String message, Throwable throwable) {
212 }
213
214
215
216
217
218 public void removeAttribute(String name) {
219 }
220
221
222
223
224
225 public void setAttribute(String name, Object object) {
226 }
227
228 Hashtable<String,String> expectations = new Hashtable<String,String>();
229
230
231
232
233
234 public void expectAndReturn(String key, String value) {
235 expectations.put(key, value);
236 }
237
238 }