From: <Vin...@ge...> - 2003-08-15 19:09:09
|
I guess you have to change request.expectAndReturn("getSession", session); for request.expectAndReturn("getSession", session.proxy()); in your setUp(). The class cast fails since Mock is not an HttpSession, but Mock.proxy() is ... -- Vincent > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > SADER, KEITH D (Contractor) > Sent: Friday, August 15, 2003 2:09 PM > To: moc...@li... > Subject: [MO-java-dev] FW: [MO-java-users] ClassCastException when > sending mocks. > > > Forwarding to the dev list, since I've seen no traffic on the > user list. > > Summer vacations must be going well :-) > -----Original Message----- > From: SADER, KEITH D (Contractor) > Sent: Tuesday, August 12, 2003 11:12 AM > To: moc...@li... > Subject: [MO-java-users] ClassCastException when sending mocks. > > > Greetings. > > I've got the following test case: > > //Hand waving declarations... > > Mock request; > Mock response; > Mock session; > > protected void setUp() throws Exception > { > action = new MyAction();// Struts based action... > mapping = new ActionMapping();// More struts... > form = new DynaActionForm();// Isn't struts grand? > request = new Mock(HttpServletRequest.class); > response = new Mock(HttpServletResponse.class); > session = new Mock(HttpSession.class); > > request.expectAndReturn("getSession", session); > } > > public void testSessionIsInRequest() throws Exception > { > ActionForward expected = new ActionForward("success", > "path", false); > ActionForward actual = action.doExecute(mapping, form, > (HttpServletRequest)request.proxy(), > (HttpServletResponse)response.proxy()); > assertEquals(expected.getName(), actual.getName()); > request.verify(); > response.verify(); > session.verify(); > } > > // Code under test... > public ActionForwad doExecute(ActionMapping mapping, > ActionForm form, HttpServletRequest request, > HttpServletResponse response) throws Exception > { > HttpSession sess = request.getSession(); > return mapping.findForward("success"); > } > > The problem I'm having is that the code in doExecute throws a > ClassCastException on request. > java.lang.ClassCastException: com.mockobjects.dynamic.Mock > at $Proxy24.getSession()(Unknown Source) > ...doExecute() > ...testSessionIsInRequest() > > > What am I doing wrong here? By my interpretation of the > examples this code *should* work. > What am I missing? > > thanks, > --- > Keith Sader > Nash Resources Group sub-contracting for Computer Sciences Corporation > IAD:TFAS > Email:kei...@df... > We've got a blind date with destiny, and it looks like she > ordered the lobster. > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet _072303_01/01 _______________________________________________ Mockobjects-java-dev mailing list Moc...@li... https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |