|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
how to test exception condition in Juniti am trying to write a test case for the exception scenario.
my code looks as below.
public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionForward actionforward = null; try{SimpleDateFormat format = new SimpleDateFormat(ReportingConstant.DATE_FORMAT);ReportRequest reportReq = new ReportRequest();String distID = request.getParameter( "distId");String beginDate = request.getParameter( "beginDate");String endDate = request.getParameter( "endDate"); if(null != beginDate){reportReq.setBeginDate(format.parse(beginDate)); } else{ LOG.error("Begin date not present in the received form "); throw new ReportingException("Begin date not present in the received form");} if(null != endDate){reportReq.setEndDate(format.parse(endDate)); } else{ LOG.error("End date not present in the received form "); throw new ReportingException("End date not present in the received form");} if(null != distID){reportReq.setDistributorId(distID); } else{ LOG.error("Distributor Id not present in the received form "); throw new ReportingException("Distributor Id not present in the received form ");} some code.... } catch(Exception e){ LOG.error("Error sending XLS file to the client ",e);actionforward = mapping.findForward( "exception");} return actionforward;}
now i would like to test a execute method for exception i.e. i am expecting that if the request obj do not have any parameters set then my code will throw an exception. and i need to verify that. my test case method is like.. public void testDownloadXLSReportFailure()throws Exception{ httpServletRequestMock.expects(once()).method( "getParameter").with(eq( "distId")).will(returnValue( null));request = (HttpServletRequest)httpServletRequestMock.proxy(); try{ActionForward forward = downloadReportAction.execute(actionMapping, reportForm, request, response);fail( "Error ..");} catch(Exception e){} } org.jmock.core.DynamicMockError: mockHttpServletRequest: unexpected invocation at org.jmock.core.AbstractDynamicMock.mockInvocation(AbstractDynamicMock.java:58) can sombody tell me how do i chk the exception condition here?
thanks, sush |
|
|
Re: how to test exception condition in JunitThis message
org.jmock.core.DynamicMockError: mockHttpServletRequest: unexpected invocation Invoked: mockHttpServletRequest.getParameter("beginDate") Allowed: expected once and has been invoked: getParameter( eq("distId") ), returns null is telling you that you called getParameter() but didn't set up either a stub or expectation, so the mock doesn't know what to do. S. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free Forum Powered by Nabble | Forum Help |