You need to sign in to do that
Don't have an account?

please help me to cover the coverage
public class HSRData
{
public Boolean b {set; get; }
public List<Hot_Sheet__c> HSR1 { set; get; }
public List<Hot_Sheet__c> hst { set; get; }
public Set<String> hotset { set;get;}
public List<Hot_Sheet__c> lst {set;get;}
public List<Hot_Sheet__c> lst1 {set;get;}
public List<Hot_Sheet__c> lst2 {set;get;}
public List<User> usrls { set; get; }
public Hot_Sheet__c HSRobj1;
public Hot_Sheet__c HSRobj2;
public Id recid { set; get; }
public string msg { set; get; }
public string msg1 { set;get;}
public string val { set; get; }
public Id accid { set; get; }
public Hot_Sheet__c getHSRObj1()
{
if (HSRobj1 == null)
{
HSRobj1 = new Hot_Sheet__c();
return HSRobj1;
}
else
return HSRobj1;
}
public Hot_Sheet__c getHSRObj2()
{
if (HSRobj2 == null)
{
HSRobj2 = new Hot_Sheet__c();
return HSRobj2;
}
else
return HSRobj2;
}
public HSRData(ApexPages.StandardController controller) {
b = true;
usrls = [SELECT CompanyName,ContactId,Country,Id FROM User ];
hotset= new Set<String>();
lst = [SELECT Account__c, Wins__c, Losses__c, Concerns__c, RFP_Propoals_Sent_This_Week__c, Request_Proposal__c, Estimate_IO_This_Week__c, Owner_Office__c, Name, Id, CreatedDate__c FROM Hot_Sheet__c where CreatedDate__c = THIS_WEEK] ;
grouped=new map<String,List<Hot_Sheet__c>> ();
for (Integer i = 0; i< lst.size(); i++)
{
hotset.add(lst[i].Owner_Office__c); // contains distict accounts
}
System.debug('**************'+hotset);
lst1 = [SELECT Name, Account__c,Wins__c,CreatedById,Owner_Office__c,Losses__c from Hot_Sheet__c where Owner_Office__c IN : hotset and CreatedDate__c = THIS_WEEK];
List<Hot_Sheet__c> newLst1=new List<Hot_Sheet__c> ();
for(String s : hotset)
{
for(Hot_Sheet__c l :lst1){
if(l.Owner_Office__c==s)
newLst1.add(l);
}
grouped.put(s,lst1);
}
}
public map<String,List<Hot_Sheet__c>> grouped{set;get;}
public void displayRecords()
{
lst = [SELECT Account__c, Wins__c, Losses__c, Concerns__c, RFP_Propoals_Sent_This_Week__c, Request_Proposal__c, Estimate_IO_This_Week__c, Owner_Office__c, Name, Id, CreatedDate__c FROM Hot_Sheet__c where CreatedDate__c = THIS_WEEK] ;
grouped=new map<String,List<Hot_Sheet__c>> ();
for (Integer i = 0; i< lst.size(); i++)
{
hotset.add(lst[i].Owner_Office__c); // contains distict accounts
}
lst1 = [SELECT Name, Account__c,Wins__c,CreatedById,Owner_Office__c,Losses__c,Concerns__c,RFP_Propoals_Sent_This_Week__c from Hot_Sheet__c where Owner_Office__c IN : hotset];
List<Hot_Sheet__c> newLst1=new List<Hot_Sheet__c> ();
for(String s : hotset)
{
for(Hot_Sheet__c l :lst1){
if(l.Owner_Office__c==s)
newLst1.add(l);
}
grouped.put(s,newlst1);
}
}
public void getData()
{
msg = ''; msg1=''; b = true;
hotset= new Set<String>();
if( HSRobj1.Date__c == null || HSRobj2.Date__c == null)
{
msg1 = 'Please Select Valid From and To Dates';
lst1 = lst = null;
grouped = null;b=false;
}
if ( HSRobj1.Date__c != null && HSRobj2.Date__c != null)
{
Datetime dt = HSRobj1.Date__c;
Date dates = dt.date();
Datetime dt1 = HSRobj2.Date__c;
Date dates1 = dt1.date();
if ( (Date.valueOf(String.valueOf(dates)) > Date.valueOf(String.valueOf(dates1)) ) || ( ( Date.valueOf(String.valueOf(dates)) > Date.valueOf(System.today())) ) || ( ( Date.valueOf(String.valueOf(dates)) > Date.valueOf(System.today()-1)) && ( Date.valueOf(String.valueOf(dates1)) > Date.valueOf(System.today()))) )
{
msg1 = 'Please Select Valid From and To Dates..............';
lst1 = lst = null;
grouped = null;b = false;
}
else
{
System.debug('I am in else block');
Date d1 = system.today().addDays(+1);
if ( system.today() == Date.valueOf(String.valueOf(dates1))+1 )
{
System.debug('************100**************');
hotset= new Set<String>();
lst = [SELECT Account__c, Wins__c, Losses__c, Concerns__c, RFP_Propoals_Sent_This_Week__c, Request_Proposal__c, Estimate_IO_This_Week__c, Owner_Office__c, Name, Id, CreatedDate__c FROM Hot_Sheet__c ] ;
grouped=new map<String,List<Hot_Sheet__c>> ();
for (Integer i = 0; i< lst.size(); i++)
{
hotset.add(lst[i].Owner_Office__c);
}
System.debug('**************'+hotset);
lst1 = [SELECT Name, Account__c,Wins__c,CreatedById,Owner_Office__c,Losses__c,Concerns__c,RFP_Propoals_Sent_This_Week__c from Hot_Sheet__c where Owner_Office__c IN : hotset];
List<Hot_Sheet__c> newLst1=new List<Hot_Sheet__c> ();
for(String s : hotset)
{
for(Hot_Sheet__c l :lst1){
if(l.Owner_Office__c==s)
newLst1.add(l);
}
grouped.put(s,newlst1);
}
}
}
}
}
}
-------------------------------------------------------
@isTest
public class TestClassOfHSRData
{
public static testMethod void main()
{
map<String,List<Hot_Sheet__c>> m = new map<String,List<Hot_Sheet__c>> ();
Set<String> hotset = new Set<String>();
List<Hot_Sheet__c> hst = new List<Hot_Sheet__c>(); List<Hot_Sheet__c> newLst1=new List<Hot_Sheet__c> ();
List<Hot_Sheet__c> ls = [select Name from Hot_Sheet__c ];
for (Integer i = 0; i< lst.size(); i++)
{
hotset.add(lst[i].Owner_Office__c); // contains distict accounts
}
for(Hot_Sheet__c h : ls)
{
hst.add(h);
}
Hot_Sheet__c hsr = new Hot_Sheet__c();
ApexPages.StandardController hsrController= new ApexPages.standardController(hsr);
HSRData h = new HSRData(hsrController);
h.getHSRObj1();
Hot_Sheet__c h1 = h.getHSRObj1();
h.getHSRObj2();
h.displayRecords();
h.getData() ;
}
}
Covering only 59% can any help me on this.
Hi,
You can add more testcases with a different set of test data to cover the uncovered code.
For Example, in the code bellow, the else part is not covered, because if (HSRobj2 == null) condition is met. So, add another test method and provide a different test data where HSRobj2 will not be equal to null. then the code in the else part will also get covered.
public Hot_Sheet__c getHSRObj2()
{
if (HSRobj2 == null)
{
HSRobj2 = new Hot_Sheet__c();
return HSRobj2;
}
else
return HSRobj2;
}
Similarly, you may have to repaet the same for other blocks of code.