blob: 87a00997811c1636a6d4ec9c829db7bce8260bc1 [file] [log] [blame]
Dave Borowitz9de65952012-08-13 16:09:45 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.gitiles;
16
17import static com.google.common.base.Charsets.UTF_8;
18
19import java.io.PrintWriter;
20import java.util.Locale;
21
22import javax.servlet.ServletOutputStream;
23import javax.servlet.http.Cookie;
24import javax.servlet.http.HttpServletResponse;
25
26/** Simple fake implementation of {@link HttpServletResponse}. */
27public class FakeHttpServletResponse implements HttpServletResponse {
28
29 private volatile int status;
30
31 public FakeHttpServletResponse() {
32 status = 200;
33 }
34
35 @Override
36 public void flushBuffer() {
37 throw new UnsupportedOperationException();
38 }
39
40 @Override
41 public int getBufferSize() {
42 throw new UnsupportedOperationException();
43 }
44
45 @Override
46 public String getCharacterEncoding() {
47 return UTF_8.name();
48 }
49
50 @Override
51 public String getContentType() {
52 return null;
53 }
54
55 @Override
56 public Locale getLocale() {
57 return Locale.US;
58 }
59
60 @Override
61 public ServletOutputStream getOutputStream() {
62 throw new UnsupportedOperationException();
63 }
64
65 @Override
66 public PrintWriter getWriter() {
67 throw new UnsupportedOperationException();
68 }
69
70 @Override
71 public boolean isCommitted() {
72 return false;
73 }
74
75 @Override
76 public void reset() {
77 throw new UnsupportedOperationException();
78 }
79
80 @Override
81 public void resetBuffer() {
82 throw new UnsupportedOperationException();
83 }
84
85 @Override
86 public void setBufferSize(int sz) {
87 throw new UnsupportedOperationException();
88 }
89
90 @Override
91 public void setCharacterEncoding(String name) {
92 throw new UnsupportedOperationException();
93 }
94
95 @Override
96 public void setContentLength(int length) {
97 throw new UnsupportedOperationException();
98 }
99
100 @Override
101 public void setContentType(String type) {
102 throw new UnsupportedOperationException();
103 }
104
105 @Override
106 public void setLocale(Locale locale) {
107 throw new UnsupportedOperationException();
108 }
109
110 @Override
111 public void addCookie(Cookie cookie) {
112 throw new UnsupportedOperationException();
113 }
114
115 @Override
116 public void addDateHeader(String name, long value) {
117 throw new UnsupportedOperationException();
118 }
119
120 @Override
121 public void addHeader(String name, String value) {
122 throw new UnsupportedOperationException();
123 }
124
125 @Override
126 public void addIntHeader(String name, int value) {
127 throw new UnsupportedOperationException();
128 }
129
130 @Override
131 public boolean containsHeader(String name) {
132 return false;
133 }
134
135 @Override
136 public String encodeRedirectURL(String url) {
137 throw new UnsupportedOperationException();
138 }
139
140 @Override
141 @Deprecated
142 public String encodeRedirectUrl(String url) {
143 throw new UnsupportedOperationException();
144 }
145
146 @Override
147 public String encodeURL(String url) {
148 throw new UnsupportedOperationException();
149 }
150
151 @Override
152 @Deprecated
153 public String encodeUrl(String url) {
154 throw new UnsupportedOperationException();
155 }
156
157 @Override
158 public void sendError(int sc) {
159 status = sc;
160 }
161
162 @Override
163 public void sendError(int sc, String msg) {
164 status = sc;
165 }
166
167 @Override
168 public void sendRedirect(String msg) {
169 status = SC_FOUND;
170 }
171
172 @Override
173 public void setDateHeader(String name, long value) {
174 throw new UnsupportedOperationException();
175 }
176
177 @Override
178 public void setHeader(String name, String value) {
179 throw new UnsupportedOperationException();
180 }
181
182 @Override
183 public void setIntHeader(String name, int value) {
184 throw new UnsupportedOperationException();
185 }
186
187 @Override
188 public void setStatus(int sc) {
189 status = sc;
190 }
191
192 @Override
193 @Deprecated
194 public void setStatus(int sc, String msg) {
195 status = sc;
196 }
197
198 public int getStatus() {
199 return status;
200 }
201}