NIHVIVO-1460 implement more stub methods to enable testing.

This commit is contained in:
jeb228 2010-12-09 17:18:00 +00:00
parent 48b4f16ed2
commit 192b722de3

View file

@ -4,6 +4,7 @@ package stubs.javax.servlet.http;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Locale; import java.util.Locale;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
@ -19,11 +20,22 @@ public class HttpServletResponseStub implements HttpServletResponse {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private String redirectLocation; private String redirectLocation;
private int status = 200;
private String errorMessage;
private StringWriter outputWriter = new StringWriter();
public String getRedirectLocation() { public String getRedirectLocation() {
return redirectLocation; return redirectLocation;
} }
public int getStatus() {
return status;
}
public String getErrorMessage() {
return errorMessage;
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Stub methods // Stub methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -33,6 +45,22 @@ public class HttpServletResponseStub implements HttpServletResponse {
this.redirectLocation = location; this.redirectLocation = location;
} }
@Override
public void sendError(int status) throws IOException {
this.status = status;
}
@Override
public void sendError(int status, String message) throws IOException {
this.status = status;
this.errorMessage = message;
}
@Override
public PrintWriter getWriter() throws IOException {
return new PrintWriter(outputWriter);
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Un-implemented methods // Un-implemented methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -73,12 +101,6 @@ public class HttpServletResponseStub implements HttpServletResponse {
"HttpServletResponseStub.getOutputStream() not implemented."); "HttpServletResponseStub.getOutputStream() not implemented.");
} }
@Override
public PrintWriter getWriter() throws IOException {
throw new RuntimeException(
"HttpServletResponseStub.getWriter() not implemented.");
}
@Override @Override
public boolean isCommitted() { public boolean isCommitted() {
throw new RuntimeException( throw new RuntimeException(
@ -181,18 +203,6 @@ public class HttpServletResponseStub implements HttpServletResponse {
"HttpServletResponseStub.encodeUrl() not implemented."); "HttpServletResponseStub.encodeUrl() not implemented.");
} }
@Override
public void sendError(int arg0) throws IOException {
throw new RuntimeException(
"HttpServletResponseStub.sendError() not implemented.");
}
@Override
public void sendError(int arg0, String arg1) throws IOException {
throw new RuntimeException(
"HttpServletResponseStub.sendError() not implemented.");
}
@Override @Override
public void setDateHeader(String arg0, long arg1) { public void setDateHeader(String arg0, long arg1) {
throw new RuntimeException( throw new RuntimeException(