Can someone help me with how to write a Test Class for the below Wrapper Class...
public class OppRelatedSolutionsController {
public List<WrapperClass> wrapList{get;set;}
public List<Solution__c> selectedRecords{get;set;}
public OppRelatedSolutionsController(ApexPages.StandardController stdController) {
wrapList = new List<WrapperClass>();
for(Solution__c solRecs : [SELECT Name, Amount__c, Expected_Revenue__c FROM Solution__c WHERE Opportunity__c = NULL]) {
wrapList.add(new WrapperClass(solRecs));
}
if(wrapList.size() <= 0) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'No Records found'));
}
}
public pageReference saveRecords() {
selectedRecords = new List<Solution__c>();
for(WrapperClass wrapRecs : wrapList) {
if(wrapRecs.selected == TRUE) {
wrapRecs.sol.Opportunity__c = ApexPages.currentPage().getParameters().get('id');
selectedRecords.add(wrapRecs.sol);
}
}
update selectedRecords;
if(selectedRecords.size() > 0) {
pageReference ref = new PageReference('/'+ApexPages.currentPage().getParameters().get('id'));
ref.setRedirect(true);
return ref;
}
return null;
}
//Wrapper Class
public class WrapperClass {
public Solution__c sol{get;set;}
public Boolean selected{get;set;}
public WrapperClass(Solution__c s) {
sol = s;
selected = false;
}
}
}
I've gone through a few references and wrote Test Class but I was not able to cover all the code. Can someone help me with what needs to be changed in my test class.
@isTest
public class OppRelatedSolutionsControllerTest {
public static testMethod void method1() {
Solution__c solRec = new Solution__c();
solRec.Name = 'Test Solution';
solRec.Amount__c = 582;
solRec.Expected_Revenue__c = 879;
insert solRec;
Test.startTest();
List<WrapperClassTest> wrapList = new List<WrapperClassTest>();
List<Solution__c> selectedRecords = new List<Solution__c>();
for(Solution__c recs : [SELECT Name, Amount__c, Expected_Revenue__c FROM Solution__c WHERE Opportunity__c = NULL]) {
wrapList.add(new WrapperClassTest(recs));
}
ApexPages.StandardController stdController = new ApexPages.StandardController(solRec);
OppRelatedSolutionsController oppRel = new OppRelatedSolutionsController(stdController);
oppRel.saveRecords();
for(WrapperClassTest selWrap : wrapList) {
if(selWrap.selected == TRUE) {
selWrap.sol.Opportunity__c = ApexPages.currentPage().getParameters().get('id');
selectedRecords.add(selWrap.sol);
}
}
update selectedRecords;
Test.stopTest();
}
public class WrapperClassTest {
public Solution__c sol{get;set;}
public Boolean selected{get;set;}
public WrapperClassTest(Solution__c s) {
sol =s;
selected = false;
}
}
}