From: Steve F. <sm...@us...> - 2002-09-02 22:40:14
|
Update of /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbook In directory usw-pr-cvs1:/tmp/cvs-serv3673/src/java/nostone/addressbook Modified Files: AddressBookServlet.java AddressBookServletTest.java Log Message: first working servlet test, no answers found Index: AddressBookServlet.java =================================================================== RCS file: /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbook/AddressBookServlet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AddressBookServlet.java 31 Aug 2002 10:55:21 -0000 1.1 +++ AddressBookServlet.java 2 Sep 2002 22:40:11 -0000 1.2 @@ -1,9 +1,19 @@ package nostone.addressbook; import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletException; +import java.io.IOException; public class AddressBookServlet extends HttpServlet { public AddressBookServlet() { } + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException + { + response.setContentType("text/plain"); + response.getWriter().println( "No address found" ); + } } Index: AddressBookServletTest.java =================================================================== RCS file: /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbook/AddressBookServletTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AddressBookServletTest.java 31 Aug 2002 10:55:21 -0000 1.1 +++ AddressBookServletTest.java 2 Sep 2002 22:40:11 -0000 1.2 @@ -16,25 +16,28 @@ HttpServletRequest mockRequest = new NullHttpServletRequest() { public String getMethod() { - return "PUT"; + return "GET"; } public String getProtocol() { return "HTTP/1.1"; } }; - HttpServletResponse mockResponse = new NullHttpServletResponse() /*{ - public void setContentType(String contentType) { - assertEquals("Should be content type", "text/plain", contentType); + HttpServletResponse mockResponse = new NullHttpServletResponse() { + private String contentType; + public void setContentType(String aContentType) { + assertEquals("Content type", "text/plain", aContentType); + contentType = aContentType; } public PrintWriter getWriter() throws IOException { + assertNotNull("Should have content type", contentType); return new PrintWriter(page); } - }*/; + }; AddressBookServlet servlet = new AddressBookServlet(); servlet.service(mockRequest, mockResponse); - // assertEquals("Response page", "No address found", page.toString()); + assertEquals("Should be empty response", "No address found", page.toString().trim()); } } |