Hi dcarew,
Thanks for your reply.
i played around as like what you have mentioned the two ways but i found that both the ways are not passing the methods and so obviously the coverage on this method(s) coming as zero '0'. Still i am getting the NullPtrException.
The method is shown below:
/**
338 * The Edit Action method is called when the user clicks on the edit button
339 * from the maintainUDI page. The method populates with all the details in
340 * the AddEditUDI page.
341 */
342 @Secured("ACTION_RM_RECIPE_MAINTAINER")
343 public void editAction ( )
344 {
345 0 this.setCustDistItem( this.distributorItemService
346 0 .editAndUpdate( this.selectedRow ) );
347 0 this.setNewDistributorId( this.custDistItem
348 0 .getCustDistributor().getId() );
349
350 // Disable the DistributorCode text-box since its edit option
351 0 this.setCheckCode( true );
352
353 0 this.setSaveUpdateButton( RMConstants.BUTTON_NAME_UPDATE );
354 0 if ( this.isDisableUpdate() )
355 {
356 0 this.setAddEditLabel( RMConstants.HEADER_NAME_VIEW );
357 }
358 else
359 {
360 0 this.setAddEditLabel( RMConstants.HEADER_NAME_EDIT );
361 }
362 0 this.setAddEditFlag( false );
363 0 }
and the test case generated for this method are as below :
/**
* Run the void editAction() method test.
*
* @generatedBy CodePro at 4/24/09 11:02 AM
*/
public void testEditAction_1()
throws Exception
{
DistributorItemBean fixture = new DistributorItemBean();
CustItem custItem = new CustItem();
CustDistributor custDistributor = new CustDistributor();
custDistributor.setId(new Long(0L));
custItem.setCustDistributor(custDistributor);
fixture.setCustDistItem(custItem);
fixture.setDisableUpdate(false);
fixture.setCheckCode(true);
fixture.setDistCode(new Long(0L));
fixture.setItemNum("");
fixture.setStoreAllUOM(new HashMap<String, String>());
fixture.setUserProfileDTO(new UserProfileDTO());
fixture.setDeleteRow(new Long(0L));
fixture.setStoreWeightUOM(new HashMap<String, String>());
fixture.setAddEditDistributorList(new ArrayList<SelectItem>());
fixture.setSelectedRow(new Long(0L));
fixture.setDistributorItemService(EasyMock.createNiceMock(DistributorItemService.class));
fixture.setItemDesc("");
fixture.setAddEditLabel("");
fixture.setRmUOMService(EasyMock.createNiceMock(RMUOMService.class));
fixture.setDistributorsList(new ArrayList<SelectItem>());
fixture.setAddEditFlag(true);
fixture.setNewDistributorId(new Long(0L));
fixture.setDistributorService(EasyMock.createNiceMock(DistributorService.class));
fixture.setSaveUpdateButton("");
fixture.setItemList(new ArrayList<CustItem>());
fixture.setDeleteItemFlag(true);
fixture.setCustDistributorList(new ArrayList<CustDistributor>());
fixture.editAction();
// add additional test code here
// An unexpected exception was thrown while executing this test:
// java.lang.NullPointerException
// at com.gfs.ebiz.rm.app.ui.controller.DistributorItemBean.editAction(DistributorItemBean.java:348)
}
/**
* Run the void editAction() method test.
*
* @generatedBy CodePro at 4/24/09 11:02 AM
*/
public void testEditAction_2()
throws Exception
{
DistributorItemBean fixture = new DistributorItemBean();
CustItem custItem = new CustItem();
CustDistributor custDistributor = new CustDistributor();
custDistributor.setId(new Long(0L));
custItem.setCustDistributor(custDistributor);
fixture.setCustDistItem(custItem);
fixture.setDisableUpdate(true);
fixture.setCheckCode(true);
fixture.setDistCode(new Long(0L));
fixture.setItemNum("");
fixture.setStoreAllUOM(new HashMap<String, String>());
fixture.setUserProfileDTO(new UserProfileDTO());
fixture.setDeleteRow(new Long(0L));
fixture.setStoreWeightUOM(new HashMap<String, String>());
fixture.setAddEditDistributorList(new ArrayList<SelectItem>());
fixture.setSelectedRow(new Long(0L));
fixture.setDistributorItemService(EasyMock.createNiceMock(DistributorItemService.class));
fixture.setItemDesc("");
fixture.setAddEditLabel("");
fixture.setRmUOMService(EasyMock.createNiceMock(RMUOMService.class));
fixture.setDistributorsList(new ArrayList<SelectItem>());
fixture.setAddEditFlag(true);
fixture.setNewDistributorId(new Long(0L));
fixture.setDistributorService(EasyMock.createNiceMock(DistributorService.class));
fixture.setSaveUpdateButton("");
fixture.setItemList(new ArrayList<CustItem>());
fixture.setDeleteItemFlag(true);
fixture.setCustDistributorList(new ArrayList<CustDistributor>());
fixture.editAction();
// add additional test code here
// An unexpected exception was thrown while executing this test:
// java.lang.NullPointerException
// at com.gfs.ebiz.rm.app.ui.controller.DistributorItemBean.editAction(DistributorItemBean.java:348)
}
Both still throw the NullPointerExeption. I had the following setting as u had said CodePro > JUnit > Generated Code, check the 'Enable flow path based test generator', and in the Fixtures i have unselected the 'Generate test fixture as field'.
Its something like as below i am expecting the tool to generate :
public void testEditAction ( )
{
this.itemBean.setSelectedRow( 7L );
custDistributor.setId( 7L );
custItem.setCustDistributor( custDistributor );
custItem.setBreakInd( true );
custItem.setFullcaseUomCode( "CASE" );
custItem.setLesscaseUomCode( "CASE" );
custItem.setCatchWeightInd( true );
itemBean.setDisableUpdate( true );
expect( this.distributorItemService.editAndUpdate( 7L ) ).andReturn(
custItem );
replay( this.distributorItemService );
this.itemBean.editAction();
verify( this.distributorItemService );
}
where in the mock object for the distributorItemService is created in the Setup method, and the expect ,reply & verify are all inthe same method.
Is it that the test cases are not generated fully means is it necessary to edit the test cases every time generated?
Also to say actually non of the Bean methods that have the Service Class method calls are getting covered with this. I donno waht i am missing or whether any setting is lost or what?
I am totally confused or you can say like almost lost in what to do, how to generate the test case with this tool has been the big question to me.
Please help on this ASAP!
