View Javadoc
1   /**
2    * 
3    */
4   package org.melati.servlet.test;
5   
6   import java.io.ByteArrayOutputStream;
7   import java.io.IOException;
8   import java.io.PrintWriter;
9   import java.util.Locale;
10  
11  import javax.servlet.ServletOutputStream;
12  import javax.servlet.http.Cookie;
13  import javax.servlet.http.HttpServletResponse;
14  
15  /**
16   * @author timp
17   * @since 2006/12/05
18   */
19  public class MockHttpServletResponse implements HttpServletResponse {
20  
21      public void addCookie(Cookie arg0) {
22      }
23  
24      public boolean containsHeader(String arg0) {
25          return false;
26      }
27  
28      public String encodeURL(String arg0) {
29          return null;
30      }
31  
32      public String encodeRedirectURL(String arg0) {
33          return null;
34      }
35  
36      public String encodeUrl(String arg0) {
37          return null;
38      }
39  
40      public String encodeRedirectUrl(String arg0) {
41          return null;
42      }
43  
44      public void sendError(int arg0, String arg1) throws IOException {
45      }
46  
47      public void sendError(int arg0) throws IOException {
48      }
49  
50      public void sendRedirect(String arg0) throws IOException {
51      }
52  
53      public void setDateHeader(String arg0, long arg1) {
54      }
55  
56      public void addDateHeader(String arg0, long arg1) {
57      }
58  
59      public void setHeader(String arg0, String arg1) {
60      }
61  
62      public void addHeader(String arg0, String arg1) {
63      }
64  
65      public void setIntHeader(String arg0, int arg1) {
66      }
67  
68      public void addIntHeader(String arg0, int arg1) {
69      }
70  
71      public void setStatus(int arg0) {
72      }
73  
74      public void setStatus(int arg0, String arg1) {
75      }
76  
77      public String getCharacterEncoding() {
78        return "ISO-8859-1";
79      }
80      ByteArrayOutputStream bout = new ByteArrayOutputStream(); 
81      public ServletOutputStream getOutputStream() throws IOException {
82          return new ServletOutputStream() {
83          
84              public void println(String arg0) throws IOException {
85                  super.println(arg0);
86              }
87  
88              public void write(int b) throws IOException {
89                bout.write(b);
90              }
91          };
92      }
93      /**
94       * @return what was written
95       */
96      public String getWritten() {
97        return bout.toString();
98      }
99      public PrintWriter getWriter() throws IOException {
100         return new PrintWriter(getOutputStream());
101     }
102 
103     public void setContentLength(int arg0) {
104     }
105 
106     String contentType;
107     public void setContentType(String type) {
108       contentType = type;
109     }
110 
111     public void setBufferSize(int arg0) {
112     }
113 
114     public int getBufferSize() {
115         return 0;
116     }
117 
118     public void flushBuffer() throws IOException {
119     }
120 
121     public void resetBuffer() {
122     }
123 
124     public boolean isCommitted() {
125         return false;
126     }
127 
128     public void reset() {
129     }
130 
131     public void setLocale(Locale arg0) {
132     }
133 
134     public Locale getLocale() {
135         return null;
136     }
137 
138     public String getContentType() {
139       throw new RuntimeException("TODO No one else has ever called this method." +
140                                  " Do you really want to start now?");
141       
142     }
143 
144     public void setCharacterEncoding(String charset) {
145       throw new RuntimeException("TODO No one else has ever called this method." +
146                                  " Do you really want to start now? " + charset);
147       
148     }
149     
150 }