Download Wiley - Java Tools for Extreme Programming

Transcript
HttpServletResponse response)throws IOException{
Map paramMap = SessionMapper.mapRequestToSession(request);
PrintWriter writer = response.getWriter();
Set mapEntries = paramMap.entrySet();
Map.Entry e = null;
for(Iterator iter = mapEntries.iterator(); iter.hasNext();){
Map.Entry entry = (Map.Entry)iter.next();
String entryStr = entry.getKey() + "=" + entry.getValue();
if(useAllCaps()){
entryStr = entryStr.toUpperCase();
}
writer.println(entryStr);
}
}
public boolean useAllCaps(){
String useAllCapsStr =getServletConfig().getInitParameter("ALL_CAPS");
return useAllCapsStr.equalsIgnoreCase("true");
}
}
Listing 8.3 contains the complete code for MapperServletTest, a subclass of Cactus's ServletTestCase. Don't
worry if you don't fully understand it; the following sections will explore each part in detail.
Listing 8.3: The Test Case for the MapperServlet.
package xptoolkit.cactus;
import org.apache.cactus.*;
import junit.framework.*;
public class MapperServletTest extends ServletTestCase{
private MapperServlet servlet;
213