I am new to Salesforce. I have written a Apex class, where I've used an inner class ( PageSection) and I am creating a list of that innerclass and using in VF as a merge variable.
My question is how can I cover the inner class in Test Method ?
public with sharing class ViewRelatedController {
public Account acct {get; set;}
public List<PageSection> sectionList { get; private set; } // merge variable
public DummyObject__c dummyObj{get; set;} // getting datefield from custom object
public Decimal interactionMonth {get;private set;}
public Decimal maxList {get;private set;}
public Decimal maxTotal {get;private set;}
Map<String, PageSection> emailCategoryMap;
Map<String, PageSection> caseCategoryMap;
// Inner class
private class PageSection {
public String name {get; private set;}
// Only one of the following to members will be populated
public List<String> caseCategoryList {get; private set;}
public List<String> emailCategoryList {get; private set;}
// Only one of the following to members will be populated
public List<Case>caseList {get; private set;}
public List<RepositoryEmail__c> emailList {get; private set;}
public Boolean caseCategoryList() {
return caseCategoryList != null;
}
public Boolean hasCaseCategoryList {
get {
return caseCategoryList != null && !caseCategoryList.isEmpty();
}
set {}
}
public Boolean emailCategoryList() {
return emailCategoryList != null;
}
public Boolean hasEmailCategoryList {
get {
return emailCategoryList != null && !emailCategoryList.isEmpty();
}
set {}
}
public Boolean getHasData() {
return (caseList != null && !caseList.isEmpty())|| ( emailList != null && !emailList.isEmpty());
}
public Boolean hasGetHasData {
get {
return (caseList != null && !caseList.isEmpty())|| ( emailList != null && !emailList.isEmpty());
}
set {}
}
}
//Controller
public ViewRelatedController(){
accountId = ApexPages.currentPage().getParameters().get('id');
acct = fetchAccount(accountId);
dummyObj = new DummyObject__c();
dummyObj.EndDateA__c = System.today();
//Fetching the instance of "My_Constants__c" custom setting.
My_Constants__c appConstantSettings = My_Constants__c.getInstance();
if(appConstantSettings != null && appConstantSettings.ViewRelatedCEInteractionMonths__c != null){
interactionMonth = appConstantSettings.ViewRelatedCEInteractionMonths__c;
}
if(interactionMonth != null && (interactionMonth - interactionMonth.round(RoundingMode.DOWN))== 0.0){
dummyObj.StartDateA__c = date.today().addMonths(-1*(interactionMonth.intValue()));
}else if(appConstantSettings.ViewRelatedCEInteractionMonths__c == null){
dummyObj.StartDateA__c = date.today().addMonths(-1);
}else{
dummyObj.StartDateA__c = date.today().addDays(-1*(interactionMonth*30).intValue());
}
if(appConstantSettings != null && appConstantSettings.ViewRelatedCEInteractionMaxList__c != null){
maxList = (appConstantSettings.ViewRelatedCEInteractionMaxList__c).intValue();
}else{
maxList = 100;
}
if(appConstantSettings != null && appConstantSettings.ViewRelatedCEInteractionMaxTotal__c != null){
maxTotal = (appConstantSettings.ViewRelatedCEInteractionMaxTotal__c).intValue();
}else{
maxTotal = 800;
}
//Instantiate sectionList
sectionList = new List<PageSection>();
emailCategoryMap = new Map<String, PageSection>();
caseCategoryMap = new Map<String, PageSection>();
for(MyConfig__c custObj :
[
SELECT Name,Case_Category__c,Category_Type__c,Email_Category__c
FROM MyConfig__c
ORDER BY Sort_Order__c
]){
PageSection psec = new PageSection();
psec.name = custObj.Name;
psec.emailCategoryList = new List<String>();
if(custObj.Category_Type__c == 'Email' && custObj.Email_Category__c != null) {
psec.emailCategoryList = custObj.Email_Category__c.split(';');
}
emailCategorySet.addAll(psec.emailCategoryList);
psec.caseCategoryList = new List<String>();
if(custObj.Category_Type__c == 'Case' && custObj.Case_Category__c != null) {
psec.caseCategoryList = custObj.Case_Category__c.split(';');
}
caseCategorySet.addAll(psec.caseCategoryList);
psec.caseList = new List<Case>();
psec.emailList = new List<RepositoryEmail__c>();
if(!psec.emailCategoryList.isEmpty() && psec.emailCategoryList!= null){
for(String emailCategory :emailCategorySet){
if(emailCategory != '-null-'){
emailCategoryMap.put(emailCategory, psec);
}else{
emailCategoryMap.put(null, psec);
}
}
}
if(!psec.caseCategoryList.isEmpty() && psec.caseCategoryList!= Null){
for(String caseCategory :caseCategorySet){
if(caseCategory != '-null-'){
caseCategoryMap.put(caseCategory, psec);
}else{
caseCategoryMap.put(null, psec);
}
}
}
sectionList.add(psec);
}
if(sectionList.isEmpty()){
return;
}
}
}