[jboss-cvs] jboss-seam/src/main/org/jboss/seam/mock ...

Gavin King gavin.king at jboss.com
Sun Jun 10 16:39:48 EDT 2007


  User: gavin   
  Date: 07/06/10 16:39:48

  Modified:    src/main/org/jboss/seam/mock     MockExternalContext.java
                        MockHttpServletRequest.java MockHttpSession.java
                        MockServletContext.java
  Log:
  improve mocks
  
  Revision  Changes    Path
  1.21      +25 -3     jboss-seam/src/main/org/jboss/seam/mock/MockExternalContext.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MockExternalContext.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/MockExternalContext.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -b -r1.20 -r1.21
  --- MockExternalContext.java	27 May 2007 09:24:30 -0000	1.20
  +++ MockExternalContext.java	10 Jun 2007 20:39:48 -0000	1.21
  @@ -33,7 +33,7 @@
   /**
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.20 $
  + * @version $Revision: 1.21 $
    */
   public class MockExternalContext extends ExternalContext
   {
  @@ -125,6 +125,12 @@
            {
               context.setAttribute(key, value);
            }
  +         
  +         @Override
  +         public void removeAttribute(String key)
  +         {
  +            context.removeAttribute(key);
  +         }
         };
      }
   
  @@ -259,6 +265,12 @@
            {
               request.setAttribute(key, value);
            }
  +         
  +         @Override
  +         public void removeAttribute(String key)
  +         {
  +            request.removeAttribute(key);
  +         }
         };
      }
   
  @@ -332,7 +344,7 @@
      @Override
      public Map getSessionMap()
      {
  -      final HttpSession session = request.getSession(true);
  +      final HttpSession session = request.getSession(true); //TODO: create the session lazily, RI should do that to
         return new AttributeMap()
         {
            @Override
  @@ -352,6 +364,12 @@
            {
               session.setAttribute(key, value);
            }
  +
  +         @Override
  +         public void removeAttribute(String key)
  +         {
  +            session.removeAttribute(key);
  +         }
         };
      }
   
  @@ -435,6 +453,8 @@
   
         public abstract void setAttribute(String key, Object value);
   
  +      public abstract void removeAttribute(String key);
  +
         public void putAll(Map t)
         {
            for (Map.Entry me : (Set<Map.Entry>) t.entrySet())
  @@ -445,7 +465,9 @@
   
         public Object remove(Object key)
         {
  -         return put(key, null);
  +         Object result = getAttribute((String) key);
  +         removeAttribute((String) key);
  +         return result;
         }
   
         public int size()
  
  
  
  1.16      +9 -2      jboss-seam/src/main/org/jboss/seam/mock/MockHttpServletRequest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MockHttpServletRequest.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/MockHttpServletRequest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -b -r1.15 -r1.16
  --- MockHttpServletRequest.java	22 Mar 2007 13:32:07 -0000	1.15
  +++ MockHttpServletRequest.java	10 Jun 2007 20:39:48 -0000	1.16
  @@ -27,7 +27,7 @@
   /**
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.15 $
  + * @version $Revision: 1.16 $
    */
   public class MockHttpServletRequest implements HttpServletRequest
   {
  @@ -317,8 +317,15 @@
   
      public void setAttribute(String att, Object value)
      {
  +      if (value==null)
  +      {
  +         attributes.remove(value);
  +      }
  +      else
  +      {
         attributes.put(att, value);
      }
  +   }
   
      public void removeAttribute(String att)
      {
  
  
  
  1.9       +9 -2      jboss-seam/src/main/org/jboss/seam/mock/MockHttpSession.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MockHttpSession.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/MockHttpSession.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- MockHttpSession.java	25 Oct 2006 15:14:36 -0000	1.8
  +++ MockHttpSession.java	10 Jun 2007 20:39:48 -0000	1.9
  @@ -17,7 +17,7 @@
   /**
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    */
   @SuppressWarnings("deprecation")
   public class MockHttpSession implements HttpSession
  @@ -91,8 +91,15 @@
   
      public void setAttribute(String att, Object value)
      {
  +      if (value==null)
  +      {
  +         attributes.remove(value);
  +      }
  +      else
  +      {
         attributes.put(att, value);
      }
  +   }
   
      public void putValue(String att, Object value)
      {
  
  
  
  1.8       +10 -3     jboss-seam/src/main/org/jboss/seam/mock/MockServletContext.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MockServletContext.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/MockServletContext.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- MockServletContext.java	21 May 2007 21:25:00 -0000	1.7
  +++ MockServletContext.java	10 Jun 2007 20:39:48 -0000	1.8
  @@ -1,4 +1,4 @@
  -//$Id: MockServletContext.java,v 1.7 2007/05/21 21:25:00 myoungstrom Exp $
  +//$Id: MockServletContext.java,v 1.8 2007/06/10 20:39:48 gavin Exp $
   package org.jboss.seam.mock;
   
   import java.io.File;
  @@ -176,9 +176,16 @@
         return new IteratorEnumeration(attributes.keySet().iterator());
      }
   
  -   public void setAttribute(String att, Object val)
  +   public void setAttribute(String att, Object value)
      {
  -      attributes.put(att, val);
  +      if (value==null)
  +      {
  +         attributes.remove(value);
  +      }
  +      else
  +      {
  +         attributes.put(att, value);
  +      }
      }
   
      public void removeAttribute(String att)
  
  
  



More information about the jboss-cvs-commits mailing list