You need to sign in to do that
Don't have an account?
Getting error on test class coverage for wrapper class
Hai,
Am not able to pass the Id to a class constructor.Once see my constructor and its test class.This class is based on wrapper class.The test code is not covered by passing OID variable also.And also getting error on 1 method because of id is not passed.
Class Constructor :
Public structural_Class(){
ID ids= ApexPages.currentPage().getParameters().get('oid');
try{
list<Structure__c> lststrcs=[select id,Combined_Plan_Area__c,CombinedSurfaceArea__c,Length__c,AddStructure__c,Surface_Area__c,Total_Area__c,
Width__c from Structure__c where AddStructure__c =: ids];----->onload getting records based on ids.
if(lststrcs.size()>0){
for(Structure__c s:lststrcs){
StructreMap.put(s.Id,s);
wrapper1 w1=new wrapper1();
w1.strvtreId=String.ValueOf(s.id);
w1.width=String.valueof(s.Width__c);
w1.Length=String.valueof(s.Length__c);
w1.Total_area=String.valueof(s.Total_Area__c);
w1.surface=String.valueof(s.Surface_Area__c);
CombinedPlanArea =String.valueof(s.Combined_Plan_Area__c);
CombinedSurfaceArea =String.valueof(s.CombinedSurfaceArea__c);
strc_recs.add(w1);
}
}else{
wrapper1 w1=new wrapper1();
w1.width=null;
w1.Length=null;
w1.Total_area=null;
w1.surface=null;
strc_recs.add(w1);
system.debug('values on load.12333.....');
}
}
catch(exception e){
}
show_surfce=false;
}
Test Class:
apexpages.currentpage().getparameters().put('ids',opp.Id);----->passing oid parameter,but it is not passed to constructor
structural_Class src=new structural_Class ();
structural_Class.wrapper1 rp = new structural_Class.wrapper1();
rp.length = String.valueof(sr.Length__c );
rp.width= String.valueof(sr.Width__c );
rp.Total_area = String.valueof( sr.Total_Area__c);
rp.Surface = String.valueof( sr.Surface_Area__c);
rp.strvtreId = String.valueof(sr.Id);
src.add();
src.str_num=String.valueof(2);
src.strc_recs.add(rp);
src.aiding_rows();
src.getnumbs();
src.Total_surface_area();
src.strucutureims();-------------------------Error on this Method because id is not passed on constructor.
Err Msg: System.NullPointerException: Attempt to de-reference a null object
Method :
Public Pagereference strucutureims(){
for(wrapper1 w:strc_recs){
If(w.strvtreId == Null)
{
Structure__c s=new Structure__c();
s.Length__c= Decimal.valueOf(w.length.trim());-------->Here on wards test cls is not covered and error is on this line.
s.Surface_Area__c=Decimal.valueOf(w.surface.trim());
s.Total_Area__c=Decimal.valueOf(w.Total_area.trim());
s.Width__c=Decimal.valueOf(w.width.trim());
s.AddStructure__c=ApexPages.currentPage().getParameters().get('oid');
System.debug('***s.CombinedSurfaceArea__c**'+s.CombinedSurfaceArea__c);
srecs.add(s);
}
Else
{
If(StructreMap.get(w.strvtreId) != Null)
{
Structure__c s=StructreMap.get(w.strvtreId);
s.Length__c= Decimal.valueOf(w.length.trim());
s.Surface_Area__c=Decimal.valueOf(w.surface.trim());
s.Total_Area__c=Decimal.valueOf(w.Total_area.trim());
s.Width__c=Decimal.valueOf(w.width.trim());
s.AddStructure__c=ApexPages.currentPage().getParameters().get('oid');
System.debug('***s.CombinedSurfaceArea__c**'+s.CombinedSurfaceArea__c);
srecs.add(s);
}
}
}
if(srecs.size()>0) {
System.debug('***srecs.size()**'+srecs.size());
Upsert srecs;
}
strc_recs.Clear();
System.debug('***srecs.size()**'+srecs.size());
return new pagereference('/'+ApexPages.currentPage().getParameters().get('oid'));
}
Pls reply ASAP