click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bck...@apache.org
Subject svn commit: r961504 - in /click/trunk/click/mock: src/org/apache/click/servlet/ test/org/apache/click/servlet/
Date Wed, 07 Jul 2010 20:45:54 GMT
Author: bckfnn
Date: Wed Jul  7 20:45:53 2010
New Revision: 961504

URL: http://svn.apache.org/viewvc?rev=961504&view=rev
Log:
generics. CLK-696

Modified:
    click/trunk/click/mock/src/org/apache/click/servlet/MockRequest.java
    click/trunk/click/mock/src/org/apache/click/servlet/MockResponse.java
    click/trunk/click/mock/src/org/apache/click/servlet/MockServletConfig.java
    click/trunk/click/mock/src/org/apache/click/servlet/MockServletContext.java
    click/trunk/click/mock/src/org/apache/click/servlet/MockSession.java
    click/trunk/click/mock/test/org/apache/click/servlet/MockTests.java

Modified: click/trunk/click/mock/src/org/apache/click/servlet/MockRequest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/src/org/apache/click/servlet/MockRequest.java?rev=961504&r1=961503&r2=961504&view=diff
==============================================================================
--- click/trunk/click/mock/src/org/apache/click/servlet/MockRequest.java (original)
+++ click/trunk/click/mock/src/org/apache/click/servlet/MockRequest.java Wed Jul  7 20:45:53
2010
@@ -79,7 +79,7 @@ public class MockRequest implements Http
     private Locale locale = Locale.getDefault();
 
     /** The request attributes map. */
-    private final Map attributes = new HashMap();
+    private final Map<String, Object> attributes = new HashMap<String, Object>();
 
     /** The request authentication type (BASIC, FORM, DIGEST, CLIENT_CERT). */
     private String authType;
@@ -91,16 +91,16 @@ public class MockRequest implements Http
     private ServletContext servletContext;
 
     /** The request list of cookies. */
-    private final List cookies = new ArrayList();
+    private final List<Cookie> cookies = new ArrayList<Cookie>();
 
     /** The request headers map. */
-    private final Map headers = new HashMap();
+    private final Map<String, List<String>> headers = new HashMap<String,
List<String>>();
 
     /** The name of the HTTP method with which this request was made. */
     private String method = "POST";
 
     /** The request parameter map. */
-    private final Map parameters = new HashMap();
+    private final Map<String, Object> parameters = new HashMap<String, Object>();
 
     /** The request HTTP session. */
     private HttpSession session;
@@ -121,7 +121,7 @@ public class MockRequest implements Http
     private String forward;
 
     /** The list of server side included url's. */
-    private List includes = new ArrayList();
+    private List<String> includes = new ArrayList<String>();
 
     /** The scheme used to make this request, defaults to "http". */
     private String scheme = "http";
@@ -271,7 +271,7 @@ public class MockRequest implements Http
         }
 
         if (uploadedFiles == null) {
-            uploadedFiles = new HashMap/* <String, UploadedFile> */();
+            uploadedFiles = new HashMap<String, UploadedFile>();
         }
 
         UploadedFile uf = new UploadedFile(fieldName, file, contentType);
@@ -287,9 +287,9 @@ public class MockRequest implements Http
      * @param value the value
      */
     public void addHeader(String name, String value) {
-        List list = (List) headers.get(name);
+        List<String> list = headers.get(name);
         if (list == null) {
-            list = new ArrayList(1);
+            list = new ArrayList<String>(1);
             headers.put(name, list);
         }
         list.add(value);
@@ -312,7 +312,7 @@ public class MockRequest implements Http
      * @param values the header values
      */
     public void setHeader(String name, String... values) {
-        List list = new ArrayList(values.length);
+        List<String> list = new ArrayList<String>(values.length);
         headers.put(name, list);
         for (String value : values) {
             list.add(value);
@@ -334,7 +334,7 @@ public class MockRequest implements Http
      *
      * @return The names
      */
-    public Enumeration getAttributeNames() {
+    public Enumeration<String> getAttributeNames() {
         return Collections.enumeration(attributes.keySet());
     }
 
@@ -409,7 +409,7 @@ public class MockRequest implements Http
             return null;
         }
         Cookie[] result = new Cookie[cookies.size()];
-        return (Cookie[]) cookies.toArray(result);
+        return cookies.toArray(result);
     }
 
     /**
@@ -441,11 +441,11 @@ public class MockRequest implements Http
      * @return The header value or null
      */
     public String getHeader(final String name) {
-        final List l = (List) headers.get(name);
+        final List<String> l = headers.get(name);
         if (l == null || l.size() < 1) {
             return null;
         } else {
-            return (String) l.get(0);
+            return l.get(0);
         }
     }
 
@@ -454,7 +454,7 @@ public class MockRequest implements Http
      *
      * @return The header names
      */
-    public Enumeration getHeaderNames() {
+    public Enumeration<String> getHeaderNames() {
         return Collections.enumeration(headers.keySet());
     }
 
@@ -464,10 +464,10 @@ public class MockRequest implements Http
      * @param name The name
      * @return The header values
      */
-    public Enumeration getHeaders(final String name) {
-        List list = (List) headers.get(name);
+    public Enumeration<String> getHeaders(final String name) {
+        List<String> list = headers.get(name);
         if (list == null) {
-            list = new ArrayList();
+            list = new ArrayList<String>();
         }
         return Collections.enumeration(list);
     }
@@ -477,7 +477,7 @@ public class MockRequest implements Http
      *
      * @return the map of headers for this request
      */
-    public Map getHeaders() {
+    public Map<String, List<String>> getHeaders() {
         return headers;
     }
 
@@ -565,8 +565,8 @@ public class MockRequest implements Http
      *
      * @return The locales
      */
-    public Enumeration getLocales() {
-        List list = new ArrayList(1);
+    public Enumeration<Locale> getLocales() {
+        List<Locale> list = new ArrayList<Locale>(1);
         list.add(getLocale());
         return Collections.enumeration(list);
     }
@@ -593,7 +593,7 @@ public class MockRequest implements Http
         if (value instanceof String[]) {
             return ((String[])value)[0];
         } else {
-            return (String) parameters.get(name);
+            return (String) value;
         }
     }
 
@@ -602,7 +602,7 @@ public class MockRequest implements Http
      *
      * @return The parameters
      */
-    public Map getParameterMap() {
+    public Map<String, Object> getParameterMap() {
         return parameters;
     }
 
@@ -611,7 +611,7 @@ public class MockRequest implements Http
      *
      * @return The parameter names
      */
-    public Enumeration getParameterNames() {
+    public Enumeration<String> getParameterNames() {
         return Collections.enumeration(parameters.keySet());
     }
 
@@ -674,8 +674,8 @@ public class MockRequest implements Http
         } else {
             final StringBuffer buf = new StringBuffer();
             try {
-                for (Iterator iterator = parameters.keySet().iterator(); iterator.hasNext();)
{
-                    final String name = (String) iterator.next();
+                for (Iterator<String> iterator = parameters.keySet().iterator(); iterator.hasNext();)
{
+                    final String name = iterator.next();
                     final Object value = parameters.get(name);
                     if (value instanceof String[]) {
                         String[] aValue = (String[]) value; 
@@ -1238,7 +1238,7 @@ public class MockRequest implements Http
      *
      * @param parameters the parameters to set
      */
-    public void setParameters(final Map parameters) {
+    public void setParameters(final Map<String, Object> parameters) {
         this.parameters.putAll(parameters);
     }
 
@@ -1272,7 +1272,7 @@ public class MockRequest implements Http
      *
      * @return list of urls that were included
      */
-    public List getIncludes() {
+    public List<String> getIncludes() {
         return this.includes;
     }
 
@@ -1344,8 +1344,7 @@ public class MockRequest implements Http
             ByteArrayOutputStream out = new ByteArrayOutputStream();
 
             // Add parameters
-            for (Iterator iterator = parameters.keySet().iterator(); iterator.hasNext();)
{
-                final String name = (String) iterator.next();
+            for (String name : parameters.keySet()) {
                 newAttachment(out);
                 out.write("; name=\"".getBytes());
                 out.write(name.getBytes());
@@ -1358,9 +1357,7 @@ public class MockRequest implements Http
 
             // Add files
             if (uploadedFiles != null) {
-                for (Iterator iterator = uploadedFiles.keySet().iterator(); iterator.hasNext();)
{
-                    String fieldName = (String) iterator.next();
-
+                for (String fieldName : uploadedFiles.keySet()) {
                     UploadedFile uf = uploadedFiles.get(fieldName);
 
                     newAttachment(out);
@@ -1453,6 +1450,7 @@ public class MockRequest implements Http
          *
          * @param contentType The content type.
          */
+        @SuppressWarnings("unused")
         public void setContentType(String contentType) {
             this.contentType = contentType;
         }
@@ -1462,6 +1460,7 @@ public class MockRequest implements Http
          *
          * @return The field name.
          */
+        @SuppressWarnings("unused")
         public String getFieldName() {
             return fieldName;
         }
@@ -1471,6 +1470,7 @@ public class MockRequest implements Http
          *
          * @param fieldName the name of the file field
          */
+        @SuppressWarnings("unused")
         public void setFieldName(String fieldName) {
             this.fieldName = fieldName;
         }
@@ -1489,6 +1489,7 @@ public class MockRequest implements Http
          *
          * @param file the uploaded file
          */
+        @SuppressWarnings("unused")
         public void setFile(File file) {
             this.file = file;
         }

Modified: click/trunk/click/mock/src/org/apache/click/servlet/MockResponse.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/src/org/apache/click/servlet/MockResponse.java?rev=961504&r1=961503&r2=961504&view=diff
==============================================================================
--- click/trunk/click/mock/src/org/apache/click/servlet/MockResponse.java (original)
+++ click/trunk/click/mock/src/org/apache/click/servlet/MockResponse.java Wed Jul  7 20:45:53
2010
@@ -87,13 +87,13 @@ public class MockResponse implements Htt
     private int code = HttpServletResponse.SC_OK;
 
     /** The response list of cookies. */
-    private final List cookies = new ArrayList();
+    private final List<Cookie> cookies = new ArrayList<Cookie>();
 
     /** The response error message. */
     private String errorMessage = null;
 
     /** The response headers map. */
-    private final Map headers = new HashMap();
+    private final Map<String, List<String>> headers = new HashMap<String,
List<String>>();
 
     /** The response locale. */
     private Locale locale = null;
@@ -154,9 +154,9 @@ public class MockResponse implements Htt
      * @param value The value for the header
      */
     public void addHeader(final String name, final String value) {
-        List list = (List) headers.get(name);
+        List<String> list = headers.get(name);
         if (list == null) {
-            list = new ArrayList(1);
+            list = new ArrayList<String>(1);
             headers.put(name, list);
         }
         list.add(value);
@@ -281,7 +281,7 @@ public class MockResponse implements Htt
      *
      * @return The collection of cookies
      */
-    public Collection getCookies() {
+    public Collection<Cookie> getCookies() {
         return cookies;
     }
 
@@ -314,11 +314,11 @@ public class MockResponse implements Htt
      * @return The value, or null
      */
     public String getHeader(final String name) {
-        List l = (List) headers.get(name);
+        List<String> l = headers.get(name);
         if (l == null || l.size() < 1) {
             return null;
         } else {
-            return (String) l.get(0);
+            return l.get(0);
         }
     }
 
@@ -327,7 +327,7 @@ public class MockResponse implements Htt
      *
      * @return The header names
      */
-    public Set getHeaderNames() {
+    public Set<String> getHeaderNames() {
         return headers.keySet();
     }
 
@@ -405,6 +405,7 @@ public class MockResponse implements Htt
         byteStream = new ByteArrayOutputStream();
         servletStream = new ServletOutputStream() {
 
+            @Override
             public void write(int b) {
                 byteStream.write(b);
             }
@@ -412,10 +413,12 @@ public class MockResponse implements Htt
         stringWriter = new StringWriter();
         printWriter = new PrintWriter(stringWriter) {
 
+            @Override
             public void close() {
             // Do nothing
             }
 
+            @Override
             public void flush() {
             // Do nothing
             }
@@ -648,7 +651,7 @@ public class MockResponse implements Htt
      * @param value The value for the header
      */
     public void setHeader(final String name, final String value) {
-        List l = new ArrayList(1);
+        List<String> l = new ArrayList<String>(1);
         l.add(value);
         headers.put(name, l);
     }

Modified: click/trunk/click/mock/src/org/apache/click/servlet/MockServletConfig.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/src/org/apache/click/servlet/MockServletConfig.java?rev=961504&r1=961503&r2=961504&view=diff
==============================================================================
--- click/trunk/click/mock/src/org/apache/click/servlet/MockServletConfig.java (original)
+++ click/trunk/click/mock/src/org/apache/click/servlet/MockServletConfig.java Wed Jul  7
20:45:53 2010
@@ -42,7 +42,7 @@ public class MockServletConfig implement
     private String servletName = "mock click servlet";
 
     /** The servlet initialization parameters. */
-    private final Map initParameters = new HashMap();
+    private final Map<String, String> initParameters = new HashMap<String, String>();
 
     // -------------------------------------------------------- Constructors
 
@@ -90,7 +90,7 @@ public class MockServletConfig implement
      * @param servletContext the servlet context
      * @param initParameters the initialization parameters
      */
-    public MockServletConfig(String servletName, ServletContext servletContext, Map initParameters)
{
+    public MockServletConfig(String servletName, ServletContext servletContext, Map<String,
String> initParameters) {
         this.servletContext = servletContext;
         this.servletName = servletName;
         addInitParameters(initParameters);
@@ -113,7 +113,7 @@ public class MockServletConfig implement
      *
      * @param initParameters A map of init parameters
      */
-    public void addInitParameters(final Map initParameters) {
+    public void addInitParameters(final Map<String, String> initParameters) {
         if (initParameters == null) {
             return;
         }
@@ -165,7 +165,7 @@ public class MockServletConfig implement
      *
      * @return enumeration of initialization parameters
      */
-    public Enumeration getInitParameterNames() {
+    public Enumeration<String> getInitParameterNames() {
         return Collections.enumeration(initParameters.keySet());
     }
 
@@ -177,6 +177,6 @@ public class MockServletConfig implement
      * @return a String containing the value of the initialization parameter
      */
     public String getInitParameter(String name) {
-        return (String) initParameters.get(name);
+        return initParameters.get(name);
     }
 }

Modified: click/trunk/click/mock/src/org/apache/click/servlet/MockServletContext.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/src/org/apache/click/servlet/MockServletContext.java?rev=961504&r1=961503&r2=961504&view=diff
==============================================================================
--- click/trunk/click/mock/src/org/apache/click/servlet/MockServletContext.java (original)
+++ click/trunk/click/mock/src/org/apache/click/servlet/MockServletContext.java Wed Jul  7
20:45:53 2010
@@ -72,13 +72,13 @@ public class MockServletContext implemen
     // -------------------------------------------------------- Private variables
 
     /** Map of attributes. */
-    private final Map attributes = new HashMap();
+    private final Map<String, Object> attributes = new HashMap<String, Object>();
 
     /** Map of initialization parameters. */
-    private final Map initParameters = new HashMap();
+    private final Map<String, String> initParameters = new HashMap<String, String>();
 
     /** Map of mime types. */
-    private final Map mimeTypes = new HashMap();
+    private final Map<String, String> mimeTypes = new HashMap<String, String>();
 
     /** The context temporary path. */
     private String tempPath;
@@ -365,7 +365,7 @@ public class MockServletContext implemen
      *
      * @param initParameters A map of init parameters
      */
-    public void addInitParameters(final Map initParameters) {
+    public void addInitParameters(final Map<String, String> initParameters) {
         if (initParameters == null) {
             return;
         }
@@ -398,7 +398,7 @@ public class MockServletContext implemen
      *
      * @return The attribute names
      */
-    public Enumeration getAttributeNames() {
+    public Enumeration<String> getAttributeNames() {
         return Collections.enumeration(attributes.keySet());
     }
 
@@ -439,7 +439,7 @@ public class MockServletContext implemen
      * @return The parameter, or null if no such parameter
      */
     public String getInitParameter(final String name) {
-        return (String) initParameters.get(name);
+        return initParameters.get(name);
     }
 
     /**
@@ -447,7 +447,7 @@ public class MockServletContext implemen
      *
      * @return The init parameter names
      */
-    public Enumeration getInitParameterNames() {
+    public Enumeration<String> getInitParameterNames() {
         return Collections.enumeration(initParameters.keySet());
     }
 
@@ -479,7 +479,7 @@ public class MockServletContext implemen
         }
         String type = name.substring(index + 1);
         if (mimeTypes.containsKey(type)) {
-            return (String) mimeTypes.get(type);
+            return mimeTypes.get(type);
         } else {
             return ClickUtils.getMimeType(type);
         }
@@ -604,13 +604,13 @@ public class MockServletContext implemen
      * @throws IllegalArgumentException if the specified name does not start
      * with a "/" character
      */
-    public Set getResourcePaths(String name) {
+    public Set<String> getResourcePaths(String name) {
         if (!name.startsWith("/")) {
             throw new IllegalArgumentException("Path " + name
                 + " does not start with a \"/\" character");
         }
         if (webappRoot == null) {
-            return new HashSet();
+            return new HashSet<String>();
         }
 
         name = name.substring(1);
@@ -644,7 +644,7 @@ public class MockServletContext implemen
 
         //List of resources in the matching path
         File[] files = current.listFiles();
-        Set result = new HashSet();
+        Set<String> result = new HashSet<String>();
         int stripLength = webappRoot.getPath().length();
         for (int f = 0; f < files.length; f++) {
             String s = files[f].getPath().substring(stripLength).replace('\\', '/');
@@ -692,7 +692,7 @@ public class MockServletContext implemen
      *
      * @return null
      */
-    public Enumeration getServletNames() {
+    public Enumeration<String> getServletNames() {
         return null;
     }
 
@@ -701,7 +701,7 @@ public class MockServletContext implemen
      *
      * @return null
      */
-    public Enumeration getServlets() {
+    public Enumeration<?> getServlets() {
         return null;
     }
 
@@ -810,6 +810,7 @@ public class MockServletContext implemen
         }
         Runtime.getRuntime().addShutdownHook(new Thread() {
 
+            @Override
             public void run() {
                 //delete the temporary directory and all subdirectories
                 deleteDirectory(directory);

Modified: click/trunk/click/mock/src/org/apache/click/servlet/MockSession.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/src/org/apache/click/servlet/MockSession.java?rev=961504&r1=961503&r2=961504&view=diff
==============================================================================
--- click/trunk/click/mock/src/org/apache/click/servlet/MockSession.java (original)
+++ click/trunk/click/mock/src/org/apache/click/servlet/MockSession.java Wed Jul  7 20:45:53
2010
@@ -23,9 +23,10 @@ import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Random;
+
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionContext;
+
 import org.apache.click.util.HtmlStringBuffer;
 import org.apache.commons.lang.StringUtils;
 
@@ -43,7 +44,7 @@ public class MockSession implements Http
     private ServletContext servletContext = null;
 
     /** The session attributes. */
-    private Map attributes = new HashMap();
+    private Map<String, Object> attributes = new HashMap<String, Object>();
 
     /** The session unique id. */
     private String id = Long.toString(new Random().nextLong());
@@ -124,7 +125,7 @@ public class MockSession implements Http
      * @return an Enumeration of String objects specifying the names of all the
      * objects bound to this session
      */
-    public Enumeration getAttributeNames() {
+    public Enumeration<String> getAttributeNames() {
         return Collections.enumeration(attributes.keySet());
     }
 
@@ -184,7 +185,8 @@ public class MockSession implements Http
      *
      * @return the session sessionContext
      */
-    public HttpSessionContext getSessionContext() {
+    @SuppressWarnings("deprecation")
+    public javax.servlet.http.HttpSessionContext getSessionContext() {
         return null;
     }
 
@@ -195,7 +197,7 @@ public class MockSession implements Http
      * objects bound to this session
      */
     public String[] getValueNames() {
-        return (String[]) attributes.keySet().toArray(new String[attributes.size()]);
+        return attributes.keySet().toArray(new String[attributes.size()]);
     }
 
     /**
@@ -289,11 +291,12 @@ public class MockSession implements Http
      *
      * @return string representation of the session
      */
+    @Override
     public String toString() {
         HtmlStringBuffer buffer = new HtmlStringBuffer();
         buffer.append("Session attributes {");
-        for (Enumeration en = getAttributeNames(); en.hasMoreElements();) {
-            String name = (String) en.nextElement();
+        for (Enumeration<String> en = getAttributeNames(); en.hasMoreElements();) {
+            String name = en.nextElement();
             Object value = getAttribute(name);
             buffer.append(name);
             buffer.append("=");

Modified: click/trunk/click/mock/test/org/apache/click/servlet/MockTests.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/test/org/apache/click/servlet/MockTests.java?rev=961504&r1=961503&r2=961504&view=diff
==============================================================================
--- click/trunk/click/mock/test/org/apache/click/servlet/MockTests.java (original)
+++ click/trunk/click/mock/test/org/apache/click/servlet/MockTests.java Wed Jul  7 20:45:53
2010
@@ -57,7 +57,7 @@ public class MockTests extends TestCase 
         final String value = "initValue";
         ServletContext servletContext = new MockServletContext();
         MockServletConfig servletConfig = new MockServletConfig(servletName,
-          servletContext, new HashMap());
+          servletContext, new HashMap<String, String>());
 
         //test that the method is null safe
         servletConfig.addInitParameters(null);



Mime
View raw message