Skip to content

Commit

Permalink
Implemented MockHttpServletResponse.getStatus: from caelum/vraptor#549
Browse files Browse the repository at this point in the history
  • Loading branch information
garcia-jj committed Sep 13, 2013
1 parent 532e176 commit 46e8a63
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
private PrintWriter writer;
private String contentType;
private ByteArrayOutputStream content = new ByteArrayOutputStream();
private int status;

public PrintWriter getWriter() {
if (this.writer == null) {
Expand All @@ -60,198 +61,129 @@ public String getContentType() {
public void setContentType(String type) {
this.contentType = type;
}
/**
* TODO Not implemented
*/

public String getCharacterEncoding() {
return null;
}
/**
* TODO Not implemented
*/

public ServletOutputStream getOutputStream() throws IOException {
return null;
}
/**
* TODO Not implemented
*/

public void setCharacterEncoding(String charset) {
}

/**
* TODO Not implemented
*/

public void setContentLength(int len) {
}
/**
* TODO Not implemented
*/

public void setBufferSize(int size) {
}

/**
* TODO Not implemented
*/
public int getBufferSize() {
return 0;
}
/**
* TODO Not implemented
*/

public void flushBuffer() throws IOException {
}
/**
* TODO Not implemented
*/

public void resetBuffer() {
}
/**
* TODO Not implemented
*/

public boolean isCommitted() {
return false;
}
/**
* TODO Not implemented
*/

public void reset() {
}
/**
* TODO Not implemented
*/

public void setLocale(Locale loc) {
}
/**
* TODO Not implemented
*/

public Locale getLocale() {
return null;
}
/**
* TODO Not implemented
*/

public void addCookie(Cookie cookie) {

}
/**
* TODO Not implemented
*/

public boolean containsHeader(String name) {
return false;
}
/**
* TODO Not implemented
*/

public String encodeURL(String url) {
return null;
}
/**
* TODO Not implemented
*/

public String encodeRedirectURL(String url) {
return null;
}
/**
* TODO Not implemented
*/

public String encodeUrl(String url) {
return null;
}
/**
* TODO Not implemented
*/

public String encodeRedirectUrl(String url) {
return null;
}
/**
* TODO Not implemented
*/

public void sendError(int sc, String msg) throws IOException {

}
/**
* TODO Not implemented
*/

public void sendError(int sc) throws IOException {

}
/**
* TODO Not implemented
*/

public void sendRedirect(String location) throws IOException {

}
/**
* TODO Not implemented
*/

public void setDateHeader(String name, long date) {

}
/**
* TODO Not implemented
*/

public void addDateHeader(String name, long date) {

}
/**
* TODO Not implemented
*/

public void setHeader(String name, String value) {

}
/**
* TODO Not implemented
*/

public void addHeader(String name, String value) {

}
/**
* TODO Not implemented
*/

public void setIntHeader(String name, int value) {

}
/**
* TODO Not implemented
*/

public void addIntHeader(String name, int value) {

}
/**
* TODO Not implemented
*/

public void setStatus(int sc) {

this.status = sc;
}
/**
* TODO Not implemented
*/

public void setStatus(int sc, String sm) {

}
/**
* TODO Not implemented
*/

public int getStatus() {
return 0;
return status;
}
/**
* TODO Not implemented
*/

public String getHeader(String name) {
return null;
}
/**
* TODO Not implemented
*/

public Collection<String> getHeaders(String name) {
return null;
}
/**
* TODO Not implemented
*/

public Collection<String> getHeaderNames() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public MockSerializationResult() {
this(new JavassistProxifier(new ObjenesisInstanceCreator()), new NullProxyInitializer());
}

public MockSerializationResult(MockHttpServletResponse response) {
this();
this.response = response;
}

public MockSerializationResult(XStreamBuilder builder) {
this(new JavassistProxifier(new ObjenesisInstanceCreator()), new NullProxyInitializer(), builder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ public void setUp() throws Exception {
}

@Test
public void shoudBeAbleToReturnContentIntoWriteAsString() throws IOException {
response.getWriter().write("X");
response.getWriter().flush();
assertEquals("X", response.getContentAsString());
public void shouldBeAbleToReturnContentIntoWriteAsString() throws IOException {
response.getWriter().write("X");
response.getWriter().flush();
assertEquals("X", response.getContentAsString());
}

@Test
public void shouldBeAbleToReturnResponseStatusCode() {
response.setStatus(401);
assertEquals(401, response.getStatus());
}
}

0 comments on commit 46e8a63

Please sign in to comment.