final MockFactory mf = MockFactory.getDefaultInstance();
// use a vector as we need to return an enumeration for calls to
// getHeaderNames()
final Map params = new HashMap();
request.fuzzy.getParameter(mf.expectsAny()).does(new MethodAction(){
public Object perform(MethodActionEvent event) throws Throwable {
return params.get(event.getArguments()[0]);
}
}).any();
StringBuffer url = new StringBuffer(pathInfo);
char c = '?';
if (parameters != null) {
url.append('/');
for (int i = 0; i < parameters.length; i++) {
if (parameters[i].length != 2) {
throw new IllegalArgumentException(
"Supplied parameter " +
i +
" has incorrect " +
"length: expected 2 got " +
parameters[i].length);
}
url.append(c).append(parameters[i][0]).append("=").append(parameters[i][1]);
c = '&';
params.put(parameters[i][0], parameters[i][1]);
}
}
// Hack to enable gif support without having a config file.
if (enableGif) {
params.put("v.gifEnabled", "true");
url.append(c).append("v.gifEnabled=true");
}
request.expects.getParameterNames().does(new MethodAction() {
public Object perform(MethodActionEvent event) throws Throwable {
return Collections.enumeration(params.keySet());
}
}).any();