Commit b40de9e6 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Added test for JSON

parent 88c57839
Pipeline #65793 passed with stages
in 2 minutes and 54 seconds
......@@ -22,19 +22,27 @@ public class WebServerTest {
@Before
public void setUp() throws IOException {
context.checking(new Expectations() {{
oneOf(req).getParameter("q"); will(returnValue("shakespeare"));
allowing(resp).getWriter(); will(returnValue(new PrintWriter(new NullOutputStream())));
allowing(resp).getOutputStream(); will(returnValue(new NullServletOutputStream()));
}});
context.checking(new Expectations() {
{
oneOf(req).getParameter("q");
will(returnValue("shakespeare"));
allowing(resp).getWriter();
will(returnValue(new PrintWriter(new NullOutputStream())));
allowing(resp).getOutputStream();
will(returnValue(new NullServletOutputStream()));
}
});
}
private void checkContentType(final String format, final String contentType) throws IOException {
context.checking(new Expectations() {{
oneOf(req).getParameter("format"); will(returnValue(format));
allowing(req).getParameter("background_colour");
oneOf(resp).setContentType(contentType);
}});
context.checking(new Expectations() {
{
oneOf(req).getParameter("format");
will(returnValue(format));
allowing(req).getParameter("background_colour");
oneOf(resp).setContentType(contentType);
}
});
website.doGet(req, resp);
}
......@@ -54,14 +62,21 @@ public class WebServerTest {
checkContentType("pdf", "application/pdf");
}
@Test
public void correctContentTypeForJSON() throws IOException {
checkContentType("json", "application/json");
}
private static class NullOutputStream extends OutputStream {
@Override
public void write(int b) throws IOException {}
public void write(int b) throws IOException {
}
}
private static class NullServletOutputStream extends ServletOutputStream {
@Override
public void write(int b) throws IOException { }
public void write(int b) throws IOException {
}
@Override
public boolean isReady() {
......@@ -69,7 +84,8 @@ public class WebServerTest {
}
@Override
public void setWriteListener(WriteListener writeListener) { }
public void setWriteListener(WriteListener writeListener) {
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment