Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created new constructor in MockSerializationResult and implemented getStatus in MockHttpServletResponse #549

Merged
merged 2 commits into from
Jul 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
private String contentType;
private ByteArrayOutputStream content = new ByteArrayOutputStream();

private int status;

public PrintWriter getWriter() {
if (this.writer == null) {
this.writer = new PrintWriter(content);
Expand Down Expand Up @@ -224,7 +226,7 @@ public void addIntHeader(String name, int value) {
* TODO Not implemented
*/
public void setStatus(int sc) {

this.status = sc;
}
/**
* TODO Not implemented
Expand All @@ -236,7 +238,7 @@ public void setStatus(int sc, String sm) {
* TODO Not implemented
*/
public int getStatus() {
return 0;
return status;
}
/**
* TODO Not implemented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public MockSerializationResult() {
this(new JavassistProxifier(new ObjenesisInstanceCreator()), new NullProxyInitializer());
}

public MockSerializationResult(MockHttpServletResponse response) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to use MockHttpServletResponse instead of HttpServletResponse?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. because MockSerializationResult uses MockHttpServletResponse internal methods that don't come from the inferface (HttpServletResponse), like that:

public String serializedResult() throws Exception {

    if("application/xml".equals(response.getContentType())){
        return response.getContentAsString();
    }

    if("application/json".equals(response.getContentType())){
        return response.getContentAsString();
    }

    return null;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then =)

this(new JavassistProxifier(new ObjenesisInstanceCreator()), new NullProxyInitializer());
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 {
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());
}
}