shale-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig McClanahan" <>
Subject Re: SHALE-409 Bug
Date Wed, 02 May 2007 16:46:10 GMT
On 5/2/07, hughes.matt <> wrote:
> I started to write a patch for this and was writing a test case when I came
> across MockRequestMap.
> 1) Why do you need to mock a java.util.Map?

At the servlet API level, request attributes are accessed via a set of
methods (getAttribute, setAttribute, getAttributeNames etc.) -- not
too surprising, since servlets preceded the Java collections API.  To
make life simpler for developers, JSF requires an ExternalContext to
model the request attributes as a Map so you can use familiar
semantics.  If you look inside a JSF implementation (the RI or
MyFaces), you'll see similar sorts of code.

So why do we need to mock one?  It is to support unit tests that call
ExternalContext.getRequestMap() and try to operate on it at test time.
 The MockExternalContext being used will use MockRequestMap to
synthesize the return value.

The same principle applies to MockSessionMap and MockApplicationMap.

> 2) Isn't this implementation of entrySet() incorrect:
>     public Set entrySet() {
>         Set set = new HashSet();
>         Enumeration keys = request.getAttributeNames();
>         while (keys.hasMoreElements()) {
>             set.add(request.getAttribute((String) keys.nextElement()));
>         }
>         return set;
>     }
> This is really returning a valueSet.  I came across this during my testing
> as I kept getting a ClassCastException.  I was expecting a Map.EntrySet as
> specified in the Map docs, but was getting the value object.

Ugh, you're right (and that is probably true on the other mock maps as
well).  Can you file a bug against those?


> hughes.matt wrote:
> >
> > As best as I can tell there is a bug in the ViewPhaseListener in
> > shale-view that is breaking other libraries, namely ajax4jsf by removing
> > ALL entries from the request map.  I'd gladly fix this, but I can't tell
> > what the code should be doing.
> >
> > I have detailed the bug here:
> >
> >
> >
> --
> View this message in context:
> Sent from the Shale - Dev mailing list archive at

View raw message