Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv21824/src/examples/com/mockobjects/examples/dynamic
Added Files:
Tag: DynamicMockExperiment
SimpleServletTest.java SimpleServlet.java
Log Message:
First stab at dynamic mocks with named calls etc.
--- NEW FILE: SimpleServletTest.java ---
/*
* Created on 04-Apr-2003
*
* To change this generated comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.mockobjects.examples.dynamic;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.mockobjects.constraint.*;
import com.mockobjects.dynamic.*;
import junit.framework.*;
/**
* @author dev
*
* To change this generated comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class SimpleServletTest extends TestCase {
public SimpleServletTest(String name) {
super(name);
}
// public void testDoGet() throws ServletException, IOException {
// Mock mockHttpServletResponse = new Mock(HttpServletResponse.class);
// Mock mockHttpServletRequest = new Mock(HttpServletRequest.class);
//
// //CallSequence calls = new CallSequence();
// //calls.add("getParameter", "body", "this is the body");
// //calls.add("getParameter", "subject", "mail from tim");
// //calls.add("getParameterValues", "recipients", new String[] {"na...@te...", "st...@mp..."} );
//
// CallSequence params = new CallSequence();
// params.expectAndReturn( new Constraint[] { C.eq("body") }, "this is the body" );
// params.expectAndReturn( new Constraint[] { C.eq("subject") }, "mail from tim" );
// params.expectAndReturn( new Constraint[] { C.eq("recipients") }, new String[] { "nat...@b1...", "st...@m3..." } );
//
// mockHttpServletRequest.expect( "getParameter", params );
//
// SimpleServlet aServlet = new SimpleServlet();
// aServlet.doGet((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy());
//
// mockHttpServletRequest.verify();
// mockHttpServletResponse.verify();
// }
public void testDoGetNew() throws ServletException, IOException {
Mock mockHttpServletResponse = new Mock(HttpServletResponse.class, "response");
Mock mockHttpServletRequest = new Mock(HttpServletRequest.class);
mockHttpServletRequest.expect( new SingleCall( "getParameter", C.args(C.eq("subject")) ) );
mockHttpServletRequest.expect( new SingleCall( "getParameter", C.args(C.eq("body")) ) );
// mockHttpServletRequest.expect( "getParameter", "subject"); //.returnValue("mail subject");
//mockHttpServletRequest.expect( "getParameter", "body").returnValue("mail body");
//mockHttpServletRequest.expect( "getParameter", "recipients").returnValue( new String[] { "person1", "person2" } );
final StringWriter contentWriter = new StringWriter();
mockHttpServletResponse.expect( new SingleCall( "setContentType", C.args(C.eq("text/html")) ) );
//mockHttpServletResponse.expect( "getWriter" ).returnValue( contentWriter );
SimpleServlet aServlet = new SimpleServlet();
aServlet.doGet((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy());
mockHttpServletRequest.verify();
mockHttpServletResponse.verify();
}
}
--- NEW FILE: SimpleServlet.java ---
/*
* Created on 04-Apr-2003
*
*/
package com.mockobjects.examples.dynamic;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* @author dev
*/
public class SimpleServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//super.doGet(arg0, arg1);
String subject = request.getParameter("subjectx");
}
}
|