You need to sign in to do that
Don't have an account?
nikkey
Wrapper class IF Condition are not getting covered in a test class
Can any one help me out why the Wrapper class IF Condition are not getting covered in a test class.Their are Rollup summary field and formula fields ,Checkbox as pick.How to call them in a wrapper class Any help very much appreciated.
public with sharing class InvoiceController { ** Test Code is not covered here Inside ** List<wrapperClass> appointmentList {get;set;} List<wrapperClass> appointmentList1 {get;set;} public list<string> address{get;set;} public string address1{get;set;} public string address2{get;set;} public string address3{get;set;} public string address4{get;set;} public string address5{get;set;} public string address6{get;set;} public string address7{get;set;} public String showaddressonVf{get;set;} public string wholeaddress{get;set;} //Added by sumit List<String> stringList ; public String all{get;set;}// ** Test Code is not covered here //------------ public InvoiceController(){ ** Test Code is not covered here Inside ** list<opportunity> op=[select id,Shipment_Info__c from opportunity where id=:apexpages.currentpage().getparameters().get('id')]; //opportunity op=[select id,Shipment_Info__c from opportunity where id=:apexpages.currentpage().getparameters().get('id')]; //---------------------Added by sumit---------------------- stringList= new List<String>(); if(op.size()>0) if(op[0].Shipment_Info__c!=NULL && op[0].Shipment_Info__c!=''){ List<String> stringList=(op[0].Shipment_Info__c).split(','); for(integer i=0;i<stringList.size();i++){ all=all+stringList[i]+'<br/>'; } all=all.remove('null'); } //------------------------------------------------------------ } public Id OppId{get;set;} ** Test Code is not covered here Inside ** public InvoiceController(ApexPages.StandardController sc) { oppId=Apexpages.currentPage().getparameters().get('Id'); } public List<wrapperClass> getappointmentList (){ wrapperClass tempObj; tempObj = new wrapperClass(); List<wrapperClass> aReList = new List<wrapperClass>(); List<Opportunity> opp=[select id,Name,AccountId from Opportunity where id=:oppid limit 1]; List<opportunity> Opp1=[select id,name,CreatedDate from opportunity where id=:oppid]; //Opportunity opp1=[select id,Name,AccountId from Opportunity where id=:oppid limit 1]; //Opportunity Opp=[select id,name,CreatedDate from opportunity where id=:oppid ]; List<OpportunityLineItem> OPplineitem= [SELECT OpportunityId,Quantity,PricebookEntry.Product2.Name,Sys_total_Amount__c,LN__c,Extension__c,ListPrice ,Pick__c,Schedule_Ship_date__c,Bin_Item_Code__c ,PricebookEntry.Product2.Product_Line__c,OpportunityLineItem.Opportunity.Subtotal__c,OpportunityLineItem.Opportunity.Non_Pick_Total__c, OpportunityLineItem.Opportunity.Pick_Total__c,Newextension__c,unit_price__c ,ItemNumber__c,product_code__c,UnitPrice FROM OpportunityLineItem where OpportunityId=:oppId]; system.debug('HHHHHHHHHH'+OPplineitem.size()); for(integer i=0; i < OPplineitem.size(); i++) { ** Test Code is not covered here Inside ** tempObj = new wrapperClass(); tempObj.productname= OPplineitem[i].PricebookEntry.Product2.Name; tempObj.BinItemCode=OPplineitem[i].Bin_Item_Code__c; tempObj.quantity=OPplineitem[i].Quantity; tempObj.Listprice=OPplineitem[i].ListPrice; tempObj.unitprice=OPplineitem[i].UnitPrice; tempobj.extension=OPplineitem[i].Extension__c ; tempObj.totalamount=OPplineitem[i].Sys_total_Amount__c; tempObj.Subtotal =OPplineitem[i].Opportunity.Subtotal__c; tempObj.NonPickTotal=OPplineitem[i].Opportunity.Non_Pick_Total__c; tempObj.PickTotal=OPplineitem[i].Opportunity.Pick_Total__c; tempObj.Newextension=OPplineitem[i].Newextension__c; tempObj.Unitprice=OPplineitem[i].unit_price__c; tempObj.ItemNumber=OPplineitem[i].ItemNumber__c; tempObj.productcode=OPplineitem[i].product_code__c; tempobj.LineNumber=OPplineitem[i].LN__c; tempobj.Pick= OPplineitem[i].Pick__c; tempobj.ScheduledShipDate = Opplineitem[i].schedule_ship_date__c; if(tempobj!=null){ aReList.add(tempObj); } } return aReList; } ** Test Code is not covered here Inside ** public List<wrapperClass> getappointmentList1 (){ wrapperClass tempObj1 ; List<wrapperClass> aReList1 = new List<wrapperClass>(); List<Opportunity> opp=[select id,Name,AccountId,Shipment_Info__c, Shipping_Address_Line1__c, Shipping_Address_Line2__c, Shipping_Address_Line3__c, Shipping_City__c, Shipping_State_Province__c, Shipping_Zipcode__c, Shipping_Country__c ** Test Code is not covered here Inside IF Statement** from Opportunity where id=:oppid]; for(integer i=0; i < opp.size(); i++) { tempObj1 = new wrapperClass(); tempObj1.billingAddress= opp[i].Shipment_Info__c; } aReList1.add(tempObj1); /* Below code commented by Kiranmai as Shipment Info field is split into multiple fields //------- Added by Sumit----------- stringList= new List<String>(); if(aReList1[0].billingAddress!=NULL && aReList1[0].billingAddress!=''){ List<String> stringList=(aReList1[0].billingAddress).split(','); for(integer i=0;i<stringList.size();i++){ all=all+stringList[i]+'<br/>'; } } */ all = all + opp[0].Shipping_Address_Line1__c + '<br/>'; if(opp[0].Shipping_Address_Line2__c!=NULL && opp[0].Shipping_Address_Line2__c!=''){ all = all + opp[0].Shipping_Address_Line2__c + '<br/>'; } if(opp[0].Shipping_Address_Line3__c!=NULL && opp[0].Shipping_Address_Line3__c!=''){ all = all + opp[0].Shipping_Address_Line3__c + '<br/>'; } if(opp[0].Shipping_City__c!=NULL && opp[0].Shipping_City__c!=''){ all = all + opp[0].Shipping_City__c + '<br/>'; } if(opp[0].Shipping_State_Province__c!=NULL && opp[0].Shipping_State_Province__c!=''){ all = all + opp[0].Shipping_State_Province__c + '<br/>'; } if(opp[0].Shipping_Zipcode__c!=NULL && opp[0].Shipping_Zipcode__c!=''){ all = all + opp[0].Shipping_Zipcode__c + '<br/>'; } if(opp[0].Shipping_Country__c!=NULL && opp[0].Shipping_Country__c!=''){ all = all + opp[0].Shipping_Country__c + '<br/>'; } /* all = all + opp[0].Shipping_City__c + ', '+opp[0].Shipping_State_Province__c + ' - ' + opp[0].Shipping_Zipcode__c + '<br/>'; all = all + opp[0].Shipping_Country__c + '<br/>';*/ all=all.remove('null'); /*-----------------------------------*/ return aReList1; } public class wrapperClass{ // public String Item{get;private set;} public String productname{get; set;} public String BinItemCode{get;set;} public Decimal Quantity{get;set;} public Decimal totalamount{get;set;} public Decimal Subtotal{get;set;} public Decimal NonPickTotal{get;set;} public Decimal PickTotal{get;set;} public Decimal Listprice{get;set;} public Decimal unitprice{get;set;} public Decimal Newextension{get;set;} public String ItemNumber{get;set;} public date todaysdate{get;set;} public decimal extension{get;set;} public string LineNumber{get;set;} public string productcode{get;set;} public string billingAddress{get;set;} public string splittedaddress{get;set;} public string productline{get;set;} public string wholeaddress{get;set;} public boolean Pick{get;set;} public date ScheduledShipDate{get;set;} public wrapperClass(){} } }Test Class
@istest Public class TestInvoiceController{ static Testmethod void Invoicemethodtest(){ test.startTest(); Date closeDt = Date.Today(); date myDate = date.today(); // set up Account and Verify that the results are as expected. Account a = new Account(); a.Name = 'icrm test acc'; insert a; // set up opportunity and Verify that the results are as expected. //list<opportunity> opp = new list<opportunity>(); //for(integer i=0;i<20;i++){ opportunity opp = new opportunity (Name='test DIE 4/6/2015' , AccountId= a.Id,StageName = 'Prospecting', CloseDate = closeDt, Shipment_Info__c='test', Shipping_Address_Line1__c='Road No 37', Shipping_Address_Line2__c='Jubilee Hills', Shipping_Address_Line3__c='Land Mark Neerus', Shipping_City__c='Hyd', Shipping_State_Province__c='TS', Shipping_Zipcode__c='500081', Shipping_Country__c ='India', Bill_of_Lading__c='This is waybill1 this is waybill 2 waybill3 -34958309458 waybill - 44570375'); // opp.add(op); //} insert opp; // set up product and Verify that the results are as expected. Product2 pro = new Product2(Product_Line__c='DIE',Name='BXCD',Product_Code_Item_Number__c='BXCD24', isActive=true); insert pro; // set up pricebook and Verify that the results are as expected. Pricebook2 pb2 = new Pricebook2(Name='DIE'); insert pb2; // set up pricebookentry and Verify that the results are as expected. PricebookEntry pbe =new PricebookEntry(unitprice=0.01,Product2Id=pro.Id,Pricebook2Id=Test.getStandardPricebookId(),isActive=true,UseStandardPrice = false ); insert pbe; // set up opportunitylineitem and Verify that the results are as expected. // list<OpportunityLineItem> OPplineitem=new list<OpportunityLineItem>(); // for(integer j=0;j<20;j++){ OpportunityLineItem OPplineitem = new OpportunityLineItem (Quantity=2, OpportunityId=opp.Id,UnitPrice=0.01,PriceBookEntryId=pbe.Id, Newextension__c=1000,Bin_Item_Code__c='BXCD2424',Schedule_Ship_Date__c=myDate); // OPplineitem.add(Oli); //} insert OPplineitem; // Query the Opportunity again to get the updated rollup summary field. Opportunity oppAfterInsert = [Select Subtotal__c,Non_Pick_Total__c,Pick_Total__c from Opportunity where Id= :opp.Id]; System.assertEquals(1000.00, oppAfterInsert.Subtotal__c); test.stopTest(); InvoiceController ic = new InvoiceController(); apexpages.currentpage().getparameters().put('oppId',opp.id); InvoiceController.wrapperClass tempObj = new InvoiceController.wrapperClass (); list<InvoiceController.wrapperClass> tempObj_list =new list<InvoiceController.wrapperClass>(); tempObj_list.add(tempObj); InvoiceController.wrapperClass tempObj1 = new InvoiceController.wrapperClass (); list<InvoiceController.wrapperClass> tempObj1_list =new list<InvoiceController.wrapperClass>(); tempObj1_list.add(tempObj1); } static Testmethod void Invoicemethodtest1(){ test.startTest(); Date closeDt = Date.Today(); date myDate = date.today(); // set up account and Verify that the results are as expected. Account a = new Account(Name = 'icrm test acc'); insert a; /// set up opportunity and Verify that the results are as expected. opportunity opp = new opportunity(Name='test NonDIE 4/6/2015' , AccountId= a.Id,StageName = 'Prospecting', CloseDate = closeDt,Shipment_Info__c='test', Shipping_Address_Line1__c='Road No 37', Shipping_Address_Line2__c='Jubilee Hills', Shipping_Address_Line3__c='Land Mark Neerus', Shipping_City__c='Hyd', Shipping_State_Province__c='TS', Shipping_Zipcode__c='500081', Shipping_Country__c ='India' , Bill_of_Lading__c='This is waybill1 this is waybill 2 waybill3 -34958309458 waybill - 44570375'); insert opp; // set up product and Verify that the results are as expected. Product2 pro = new Product2(Product_Line__c='NONDIE',Name='BXRC',Product_Code_Item_Number__c='BXRC27', isActive=true); insert pro; // set up pricebook and Verify that the results are as expected. Pricebook2 pb2 = new Pricebook2(Name='NONDIE'); insert pb2; // set up pricebookentry and Verify that the results are as expected. PricebookEntry pbe = new PricebookEntry(unitprice=1,Product2Id=pro.Id,isActive=true,Pricebook2Id=Test.getStandardPricebookId(),UseStandardPrice = false ); insert pbe; // set up opportunitylineitem and Verify that the results are as expected. OpportunityLineItem OPplineitem= new OpportunityLineItem (Quantity=2, OpportunityId=opp.Id,UnitPrice=1,PriceBookEntryId=pbe.id, Newextension__c=1000,Bin_Item_Code__c='BXCR',Schedule_Ship_Date__c=myDate ); insert OPplineitem; // Query the Opportunity again to get the updated rollup summary field. Opportunity oppAfterInsert = [Select Subtotal__c,Non_Pick_Total__c,Pick_Total__c from Opportunity where Id= :opp.Id]; System.assertEquals(1000.00, oppAfterInsert.Subtotal__c); test.stopTest(); InvoiceController ic = new InvoiceController(); apexpages.currentpage().getparameters().put('oppId',opp.id); InvoiceController.wrapperClass tempObj = new InvoiceController.wrapperClass (); list<InvoiceController.wrapperClass> tempObj_list =new list<InvoiceController.wrapperClass>(); tempObj_list.add(tempObj); InvoiceController.wrapperClass tempObj1 = new InvoiceController.wrapperClass (); list<InvoiceController.wrapperClass> tempObj1_list =new list<InvoiceController.wrapperClass>(); tempObj1_list.add(tempObj1); } }