+ Start a Discussion
cloudtripcloudtrip 

Stuck at 67% Coverage and need assistance in getting it to 75%

Here is my controller and would appreciate any assistance in trying to get this up to 75% so I can deploy it to production

 

************************************************************************

public class NewItemController {

    New_Item_Tracking__c item;
    Launch_Specific_Products__c[] prodList;
    Launch_Specific_Products__c[] deletions;

    public NewItemController(New_Item_Tracking__c newItem) {
   
    item = newItem;

    prodList = [Select
    Wrigley_Products__c,
    SS_MP_Club__c,
    New_Product_Status__c,
    Est_Distribution__c,
    Order_Volume__c,
    Accepted_Date__c,
    Ordered_Date__c,
    Presented_Pending_Date__c,
    Rejected_Date__c,
    Delete_This__c,
    Month_1_SSU_Early_Launch__c,
    Approved_Early_Ship_1_Month_Prior_Turn__c,
    Month_2_SSU_Early_Launch__c,
    Approved_Early_Ship_2_Month_Prior_Turn__c,
    Month_3_SSU_Early_Launch__c,
    Approved_Early_Ship_3_Month_Prior_Turn__c,
    X1st_Month_Vol__c,
    Mth_1_Vol_Turn__c,
    X2nd_Month_Vol__c,
    Mth_2_Vol_Turn__c,
    X3rd_Month_Vol__c,
    Mth_3_Vol_Turn__c,
    X4th_Month_Vol__c,
    Mth_4_Vol_Turn__c,
    X5th_Month_Vol__c,
    Mth_5_Vol_Turn__c,
    X4_W__c,
    X8_Wks_Dist__c,
    X12_Wks_Dist__c,
    X16_Wks_Dist__c,
    X20_Wks_Dist__c,
    X24_Wks_Dist__c,
    X28_Wks_Dist__c
    From Launch_Specific_Products__c
    WHERE
    New_Item_Tracking__c=:item.Id
    ORDER BY SS_MP_Club__c, Wrigley_Products__c];
    }
    public NewItemController(ApexPages.StandardController controller) {
   
    item = (New_Item_Tracking__c)controller.getSubject();

    prodList = [Select
    Wrigley_Products__c,
    SS_MP_Club__c,
    New_Product_Status__c,
    Est_Distribution__c,
    Order_Volume__c,
    Accepted_Date__c,
    Ordered_Date__c,
    Presented_Pending_Date__c,
    Rejected_Date__c,
    Delete_This__c,
    X1st_Month_Vol__c,
    Mth_1_Vol_Turn__c,
    X2nd_Month_Vol__c,
    Mth_2_Vol_Turn__c,
    X3rd_Month_Vol__c,
    Mth_3_Vol_Turn__c,
    X4th_Month_Vol__c,
    Mth_4_Vol_Turn__c,
    X5th_Month_Vol__c,
    Mth_5_Vol_Turn__c,
    X4_W__c,
    X8_Wks_Dist__c,
    X12_Wks_Dist__c,
    X16_Wks_Dist__c,
    X20_Wks_Dist__c,
    X24_Wks_Dist__c,
    X28_Wks_Dist__c,
    Month_1_SSU_Early_Launch__c,
    Approved_Early_Ship_1_Month_Prior_Turn__c,
    Month_2_SSU_Early_Launch__c,
    Approved_Early_Ship_2_Month_Prior_Turn__c,
    Month_3_SSU_Early_Launch__c,
    Approved_Early_Ship_3_Month_Prior_Turn__c
    From Launch_Specific_Products__c
    WHERE
    New_Item_Tracking__c=:item.Id
    ORDER BY SS_MP_Club__c, Wrigley_Products__c];
/*
    if(prodList.size()==0){
        newProduct();
    }
*/
}
// returns product information into Products
 public Launch_Specific_Products__c[] getprodList() {
  return prodList;
}

 // Inserts all changes into records
 public pagereference savehanges() {
  upsert prodList;
  return null;

 }

 /*
 public pagereference newProduct() {
  Launch_Specific_Products__c d = new Launch_Specific_Products__c();
  d.New_Item_Tracking__c = item.Id;
  prodList.add(d);
  return null;
 }
 */

/*
 public PageReference delProduct() {
 
  upsert prodList;
  deletions= [ SELECT Id FROM Launch_Specific_Products__c WHERE New_Item_Tracking__c=:item.Id AND Delete_This__c=true];
 
  delete deletions;
  prodList = [Select
    Wrigley_Products__c,
    New_Product_Status__c,
    Est_Distribution__c,
    Order_Volume__c,
    Accepted_Date__c,
    Ordered_Date__c,
    Presented_Pending_Date__c,
    Rejected_Date__c,
    Delete_This__c
    From Launch_Specific_Products__c
    WHERE
    New_Item_Tracking__c=:item.Id];
 
    getprodList();
 
  return null;
 }
 */
}

Best Answer chosen by Admin (Salesforce Developers) 
Jake GmerekJake Gmerek

I am not exactly sure what you are doing with the code, but I can see why your coverage is low.

 

First, you have two constructors:

 

public NewItemController(New_Item_Tracking__c newItem)

 public NewItemController(ApexPages.StandardController controller)

 

However, you are only initializing one instance of the class using the first constructor, so the second one is never getting called.  Essentially, you have to create another instance of the class using the second constructor.

 

Also, you have several methods that are not called in the test method:

 

public pagereference newProduct() 

public PageReference delProduct()

 

Since they are not getting called they are not covered by your test method.  If you call them it should help.

 

Let me know if you have any questions.

All Answers

Jake GmerekJake Gmerek

What does your currrent test class look like?

cloudtripcloudtrip

This is my test class I came up with:

*******************************************************************************

public class NewItemControllerTest {
        static testMethod void testNewItemController(){
        
        Account acct = new Account();
        acct.Name = 'TEST ACCT';
        insert acct;
        
        Launch_Window__c lwc = new Launch_Window__c();
        insert lwc;
        
        Wrigley_Products__c prod = new Wrigley_Products__c();
        prod.ZFIN__c = '40568';
        prod.Launch_Window__c = lwc.Id;
        insert prod;
        
        New_Item_Tracking__c nitc = new New_Item_Tracking__c();
        nitc.Account__c = acct.Id;
        nitc.Launch_Window__c = lwc.Id;
        
        insert nitc;
        
        NewItemController newItem = new NewItemController(nitc);
        
        newItem.saveChanges();
        
        List<Launch_Specific_Products__c> lsp = newItem.getProdList();
        
        System.assertNotEquals(lsp, null);

        delete nitc;
        delete lwc;
        delete prod;
        delete acct;
            
    }
}

 



Jake GmerekJake Gmerek

I am not exactly sure what you are doing with the code, but I can see why your coverage is low.

 

First, you have two constructors:

 

public NewItemController(New_Item_Tracking__c newItem)

 public NewItemController(ApexPages.StandardController controller)

 

However, you are only initializing one instance of the class using the first constructor, so the second one is never getting called.  Essentially, you have to create another instance of the class using the second constructor.

 

Also, you have several methods that are not called in the test method:

 

public pagereference newProduct() 

public PageReference delProduct()

 

Since they are not getting called they are not covered by your test method.  If you call them it should help.

 

Let me know if you have any questions.

This was selected as the best answer