EMMA Coverage Report (generated Mon Nov 01 16:48:29 PDT 2010)
[all classes][com.google.caja.service]

COVERAGE SUMMARY FOR SOURCE FILE [TestHttpServletRequest.java]

nameclass, %method, %block, %line, %
TestHttpServletRequest.java67%  (2/3)18%  (12/65)42%  (178/423)39%  (35.6/92)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TestHttpServletRequest100% (1/1)15%  (9/59)41%  (161/392)37%  (31.6/86)
TestHttpServletRequest (String): void 100% (1/1)100% (24/24)100% (9/9)
TestHttpServletRequest (String, byte [], String, String): void 100% (1/1)100% (23/23)100% (9/9)
decode (String): String 100% (1/1)40%  (4/10)33%  (1/3)
decodeParams (): void 100% (1/1)100% (66/66)100% (8/8)
enumeration (Iterator): Enumeration 0%   (0/1)0%   (0/5)0%   (0/1)
getAttribute (String): Object 0%   (0/1)0%   (0/4)0%   (0/1)
getAttributeNames (): Enumeration 0%   (0/1)0%   (0/4)0%   (0/1)
getAuthType (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getCharacterEncoding (): String 100% (1/1)100% (3/3)100% (1/1)
getContentLength (): int 0%   (0/1)0%   (0/4)0%   (0/1)
getContentType (): String 100% (1/1)100% (3/3)100% (1/1)
getContextPath (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getCookies (): Cookie [] 0%   (0/1)0%   (0/4)0%   (0/1)
getDateHeader (String): long 100% (1/1)62%  (10/16)81%  (1.6/2)
getHeader (String): String 0%   (0/1)0%   (0/6)0%   (0/1)
getHeaderNames (): Enumeration 0%   (0/1)0%   (0/6)0%   (0/1)
getHeaders (String): Enumeration 0%   (0/1)0%   (0/4)0%   (0/1)
getInputStream (): ServletInputStream 100% (1/1)100% (12/12)100% (2/2)
getIntHeader (String): int 0%   (0/1)0%   (0/14)0%   (0/2)
getLocalAddr (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getLocalName (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getLocalPort (): int 0%   (0/1)0%   (0/4)0%   (0/1)
getLocale (): Locale 0%   (0/1)0%   (0/2)0%   (0/1)
getLocales (): Enumeration 0%   (0/1)0%   (0/4)0%   (0/1)
getMethod (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getParameter (String): String 100% (1/1)100% (16/16)100% (1/1)
getParameterMap (): Map 0%   (0/1)0%   (0/4)0%   (0/1)
getParameterNames (): Enumeration 0%   (0/1)0%   (0/6)0%   (0/1)
getParameterValues (String): String [] 0%   (0/1)0%   (0/16)0%   (0/2)
getPathInfo (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getPathTranslated (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getProtocol (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getQueryString (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getReader (): BufferedReader 0%   (0/1)0%   (0/4)0%   (0/1)
getRealPath (String): String 0%   (0/1)0%   (0/4)0%   (0/1)
getRemoteAddr (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getRemoteHost (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getRemotePort (): int 0%   (0/1)0%   (0/4)0%   (0/1)
getRemoteUser (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getRequestDispatcher (String): RequestDispatcher 0%   (0/1)0%   (0/4)0%   (0/1)
getRequestURI (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getRequestURL (): StringBuffer 0%   (0/1)0%   (0/4)0%   (0/1)
getRequestedSessionId (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getScheme (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getServerName (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getServerPort (): int 0%   (0/1)0%   (0/2)0%   (0/1)
getServletPath (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getSession (): HttpSession 0%   (0/1)0%   (0/4)0%   (0/1)
getSession (boolean): HttpSession 0%   (0/1)0%   (0/4)0%   (0/1)
getUserPrincipal (): Principal 0%   (0/1)0%   (0/4)0%   (0/1)
isRequestedSessionIdFromCookie (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
isRequestedSessionIdFromURL (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
isRequestedSessionIdFromUrl (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
isRequestedSessionIdValid (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
isSecure (): boolean 0%   (0/1)0%   (0/6)0%   (0/1)
isUserInRole (String): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
removeAttribute (String): void 0%   (0/1)0%   (0/4)0%   (0/1)
setAttribute (String, Object): void 0%   (0/1)0%   (0/4)0%   (0/1)
setCharacterEncoding (String): void 0%   (0/1)0%   (0/4)0%   (0/1)
     
class TestHttpServletRequest$1100% (1/1)100% (3/3)100% (17/17)100% (4/4)
TestHttpServletRequest$1 (TestHttpServletRequest, ByteArrayInputStream): void 100% (1/1)100% (9/9)100% (1/1)
close (): void 100% (1/1)100% (4/4)100% (2/2)
read (): int 100% (1/1)100% (4/4)100% (1/1)
     
class TestHttpServletRequest$20%   (0/1)0%   (0/3)0%   (0/14)0%   (0/2)
TestHttpServletRequest$2 (Iterator): void 0%   (0/1)0%   (0/6)0%   (0/1)
hasMoreElements (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
nextElement (): Object 0%   (0/1)0%   (0/4)0%   (0/1)

1// Copyright (C) 2008 Google Inc.
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.caja.service;
16 
17import com.google.caja.SomethingWidgyHappenedError;
18import com.google.caja.util.Maps;
19import com.google.caja.util.Strings;
20import java.io.BufferedReader;
21import java.io.ByteArrayInputStream;
22import java.io.UnsupportedEncodingException;
23import java.io.IOException;
24import java.net.URLDecoder;
25import java.security.Principal;
26import java.util.ArrayList;
27import java.util.Collections;
28import java.util.Date;
29import java.util.Enumeration;
30import java.util.Iterator;
31import java.util.List;
32import java.util.Locale;
33import java.util.Map;
34 
35import javax.servlet.RequestDispatcher;
36import javax.servlet.ServletInputStream;
37import javax.servlet.http.Cookie;
38import javax.servlet.http.HttpServletRequest;
39import javax.servlet.http.HttpSession;
40 
41/**
42 * @author jasvir@google.com (Jasvir Nagra)
43 */
44public final class TestHttpServletRequest implements HttpServletRequest {
45  private final String queryString;
46  private final Map<String, List<String>> params = Maps.newHashMap();
47  private final byte[] content;
48  private final String contentType;
49  private final String characterEncoding;
50  private final Map<String, String> headers = Maps.newHashMap();
51 
52  public TestHttpServletRequest(String queryString) {
53    this.queryString = queryString;
54    this.content = new byte[0];
55    this.contentType = null;
56    this.characterEncoding = null;
57    decodeParams();
58  }
59 
60  TestHttpServletRequest(String queryString,
61                         byte[] content,
62                         String contentType,
63                         String characterEncoding) {
64    this.queryString = queryString;
65    this.content = content;
66    this.contentType = contentType;
67    this.characterEncoding = characterEncoding;
68    decodeParams();
69  }
70 
71  private void decodeParams() {
72    for (String pair : queryString.split("[?&]")) {
73      int eq = pair.indexOf('=');
74      String k = decode(eq >= 0 ? pair.substring(0, eq) : pair);
75      String v = decode(eq >= 0 ? pair.substring(eq + 1) : "");
76      if (!params.containsKey(k)) {
77        params.put(k, new ArrayList<String>());
78      }
79      params.get(k).add(v);
80    }
81  }
82 
83  public String getAuthType() { throw new UnsupportedOperationException(); }
84  public Cookie[] getCookies() { throw new UnsupportedOperationException(); }
85  @SuppressWarnings("deprecation")
86  public long getDateHeader(String a) {
87    String h = headers.get(a);
88    return h != null ? new Date(h).getTime() : -1;
89  }
90  public String getHeader(String a) {
91    return headers.get(a);
92  }
93  public Enumeration<String> getHeaderNames() {
94    return enumeration(headers.keySet().iterator());
95  }
96  public int getIntHeader(String arg0) {
97    String h = headers.get(arg0);
98    return h != null ? Integer.valueOf(h) : -1;
99  }
100  public String getMethod() { throw new UnsupportedOperationException(); }
101  public String getPathInfo() { throw new UnsupportedOperationException(); }
102  public String getPathTranslated() {
103    throw new UnsupportedOperationException();
104  }
105  public String getQueryString() { return queryString; }
106  public String getRemoteUser() { throw new UnsupportedOperationException(); }
107  public String getRequestURI() { return "/proxy"; }
108  public String getRequestedSessionId() {
109    throw new UnsupportedOperationException();
110  }
111  public String getServletPath() { throw new UnsupportedOperationException(); }
112  public HttpSession getSession() { throw new UnsupportedOperationException(); }
113  public HttpSession getSession(boolean a) {
114    throw new UnsupportedOperationException();
115  }
116  public boolean isRequestedSessionIdFromCookie() {
117    throw new UnsupportedOperationException();
118  }
119  public boolean isRequestedSessionIdFromURL() {
120    throw new UnsupportedOperationException();
121  }
122  @Deprecated
123  public boolean isRequestedSessionIdFromUrl() {
124    throw new UnsupportedOperationException();
125  }
126  public boolean isRequestedSessionIdValid() {
127    throw new UnsupportedOperationException();
128  }
129  public Object getAttribute(String arg0) {
130    throw new UnsupportedOperationException();
131  }
132  public Enumeration<String> getAttributeNames() {
133    throw new UnsupportedOperationException();
134  }
135  public String getCharacterEncoding() { return characterEncoding; }
136  public int getContentLength() { return content.length; }
137  public String getContentType() { return contentType; }
138  public ServletInputStream getInputStream() {
139    final ByteArrayInputStream bais = new ByteArrayInputStream(content);
140    return new ServletInputStream() {
141      @Override
142      public int read() {
143        return bais.read();
144      }
145      @Override
146      public void close() throws IOException {
147        bais.close();
148      }
149    };
150  }
151  public String getParameter(String k) {
152    return params.containsKey(k) ? params.get(k).get(0) : null;
153  }
154  public Enumeration<String> getParameterNames() {
155    return enumeration(params.keySet().iterator());
156  }
157  public String[] getParameterValues(String k) {
158    List<String> vals = params.get(k);
159    return vals != null ? vals.toArray(new String[0]) : null;
160  }
161  public String getProtocol() { return "http"; }
162  public BufferedReader getReader() {
163    throw new UnsupportedOperationException();
164  }
165  @Deprecated
166  public String getRealPath(String arg0) {
167    throw new UnsupportedOperationException();
168  }
169  public String getRemoteAddr() { throw new UnsupportedOperationException(); }
170  public String getRemoteHost() { throw new UnsupportedOperationException(); }
171  public String getScheme() { return getProtocol(); }
172  public String getServerName() { return "test.proxy"; }
173  public int getServerPort() { return -1; }
174  public void setAttribute(String arg0, Object arg1) {
175    throw new UnsupportedOperationException();
176  }
177 
178  private static String decode(String mimeEncoded) {
179    try {
180      return URLDecoder.decode(mimeEncoded, "UTF-8");
181    } catch (UnsupportedEncodingException ex) {
182      throw new SomethingWidgyHappenedError(ex);
183    }
184  }
185 
186  public String getContextPath() {
187    throw new UnsupportedOperationException();
188  }
189 
190  public Enumeration<?> getHeaders(String arg0) {
191    throw new UnsupportedOperationException();
192  }
193 
194  public StringBuffer getRequestURL() {
195    throw new UnsupportedOperationException();
196  }
197 
198  public Principal getUserPrincipal() {
199    throw new UnsupportedOperationException();
200  }
201 
202  public boolean isUserInRole(String arg0) {
203    throw new UnsupportedOperationException();
204  }
205 
206  public Locale getLocale() {
207    return Locale.ENGLISH;
208  }
209 
210  public Enumeration<Locale> getLocales() {
211    throw new UnsupportedOperationException();
212  }
213 
214  public Map<String, List<String>> getParameterMap() {
215    return Collections.unmodifiableMap(this.getParameterMap());
216  }
217 
218  public RequestDispatcher getRequestDispatcher(String arg0) {
219    throw new UnsupportedOperationException();
220  }
221 
222  public boolean isSecure() {
223    return Strings.toLowerCase(this.getRequestURI()).startsWith("https://");
224  }
225 
226  public void removeAttribute(String arg0) {
227    throw new UnsupportedOperationException();
228  }
229 
230  public void setCharacterEncoding(String encodingName) {
231    throw new UnsupportedOperationException();
232  }
233 
234  private static <T> Enumeration<T> enumeration(final Iterator<T> it) {
235    return new Enumeration<T>() {
236      public boolean hasMoreElements() { return it.hasNext(); }
237      public T nextElement() { return it.next(); }
238    };
239  }
240 
241  public String getLocalAddr() { throw new UnsupportedOperationException(); }
242  public String getLocalName() { throw new UnsupportedOperationException(); }
243  public int getLocalPort() { throw new UnsupportedOperationException(); }
244  public int getRemotePort() { throw new UnsupportedOperationException(); }
245}

[all classes][com.google.caja.service]
EMMA 2.0.5312 (C) Vladimir Roubtsov