function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Merry SMerry S 

Need help with on a test class for an extension controller

This test class is only getting 33% coverage, and I know it must have something to do with this line in the controller, but I am not sure how to get this covered.
list_of_accountmanagement = new List<string>{'Key (WIG)','Active Project','Active Opportunity > $50K','Partner-Managed','TAM-Managed','TSE-Managed (Tech Support)','Inactive'};

The bolded/underlined parts of the extension are what are not covered.
 
public final Account accounts;

    Public MAP<String,LIST<Account>> accsBucketedByType{get;set;} 
    public List<string> list_of_accountmanagement{get;set;}
    public ColumnControllerExt(ApexPages.StandardController stdController) {
    list_of_accountmanagement = new List<string>{'Key (WIG)','Active Project','Active Opportunity > $50K','Partner-Managed','TAM-Managed','TSE-Managed (Tech Support)','Inactive'};
    accsBucketedByType = new Map<String, List<Account>>();
    }
    public map<string,List<account>> getmap_values(){
        accsBucketedByType .put('Key (WIG)' ,[Select 

Id,name,Opportunity_Order_Status__c,NPS_Status__c,Case_Status_Stoplight__c,MSA_Status__c,Version_Status__c,Risk_Status__c,Team_Management_Status__c,Overall_Status__c,Total_RR_Converted_to_USD__c,Account_Management_Type__c,x3re__c from Account where 

Account_Management_Type__c =: 'Key (WIG)'order by Name]);

Here is the test class:
@isTest
private class TEST_ColumnController {
	
	static testMethod void ColumnController_test1() {

 Profile p = [SELECT Id FROM Profile WHERE Id='xx'];

//create dummy User
  User u = new User(Alias = 'testcc', Email='PopulateCountry@testorg.com', EmailEncodingKey='UTF-8', 
  LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', Department = 'Some Department',
  ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='PopulateCountry@testorg.com');       
  insert u;
  System.assert(u.Id != null);

//Create dummy accounts
    Account acc = new Account(Name = '1',Type = 'Customer',OwnerId = u.Id);
     
    insert acc; 

    Test.startTest();
    Test.setCurrentPage(Page.MyPage);

// create a new Account standard controller by passing it the account record
    ApexPages.StandardController controller = new ApexPages.StandardController(acc);

    // now pass it to the extension
    ColumnControllerExt stdController = new ColumnControllerExt(controller);

    system.assert(stdController != null); // controller has successfully been created

    
    Test.stopTest();
  }
}
Thanks for any help.
 
Best Answer chosen by Merry S
badibadi
Remove  
List<Account> a1 = [SELECT Id,name,Opportunity_Order_Status__c,NPS_Status__c,Case_Status_Stoplight__c,MSA_Status__c,Version_Status__c,Risk_Status__c,Team_Management_Status__c,Overall_Status__c,Total_RR_Converted_to_USD__c,Account_Management_Type__c,x3re__c FROM Account WHERE Id IN :acc AND Account_Management_Type__c =:'Key (WIG)'order by Name];
    System.debug('***************************************** List= '+a1);
    g.put('Key (WIG)' ,a1);

and add this line
 
MAP<String,LIST<Account>> g = stdController.accsBucketedByType; 
    
	g= stdController.getmap_values();

 

All Answers

badibadi
add this line to your test class
List<String> loa=stdController.list_of_accountmanagement;
System.assertNotEquals(0, loa.size());
Merry SMerry S
Hi badI,
Thanks for that, I have added it to the class, but it made no difference in the coverage. I guess I was wrong on my assumption. :(

These are the lines that are not covered:

User-added image

Here is the full controller code:
 
public final Account accounts;

    Public MAP<String,LIST<Account>> accsBucketedByType{get;set;} 
    public List<string> list_of_accountmanagement{get;set;}
    public ColumnControllerExt(ApexPages.StandardController stdController) {
    list_of_accountmanagement = new List<string>{'Key (WIG)','Active Project','Active Opportunity > $50K','Partner-Managed','TAM-Managed','TSE-Managed (Tech Support)','Inactive'};
    accsBucketedByType = new Map<String, List<Account>>();
    }
    public map<string,List<account>> getmap_values(){
        accsBucketedByType .put('Key (WIG)' ,[Select 

Id,name,Opportunity_Order_Status__c,NPS_Status__c,Case_Status_Stoplight__c,MSA_Status__c,Version_Status__c,Risk_Status__c,Team_Management_Status__c,Overall_Status__c,Total_RR_Converted_to_USD__c,Account_Management_Type__c,x3re__c from Account where 

Account_Management_Type__c =: 'Key (WIG)'order by Name]);
        accsBucketedByType .put('Active Project' , [Select 

Id,name,Opportunity_Order_Status__c,NPS_Status__c,Case_Status_Stoplight__c,MSA_Status__c,Version_Status__c,Risk_Status__c,Team_Management_Status__c,Overall_Status__c,Total_RR_Converted_to_USD__c,Account_Management_Type__c,x3re__c from Account where 

Account_Management_Type__c =: 'Active Project'order by Name]);
        accsBucketedByType .put('Active Opportunity > $50K' ,[Select 

Id,name,Opportunity_Order_Status__c,NPS_Status__c,Case_Status_Stoplight__c,MSA_Status__c,Version_Status__c,Risk_Status__c,Team_Management_Status__c,Overall_Status__c,Total_RR_Converted_to_USD__c,Account_Management_Type__c,x3re__c from Account where  

Account_Management_Type__c =: 'Active Opportunity > $50K'order by Name]);
// goes through all of the different types

    return accsBucketedByType;
    }
        PageReference pageRef = ApexPages.currentPage();
        Public Map <String,String>pageMap = pageRef.getParameters();
        String var1 = pageMap.get('var1');
And the test class - I made some changes thinking I figured it out - but alas, no.
 
static testMethod void ColumnController_test1() {




 Profile p = [SELECT Id FROM Profile WHERE Id='xx'];

//create dummy User
  User u = new User(Alias = 'testcc', Email='PopulateCountry@testorg.com', EmailEncodingKey='UTF-8', 
  LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', Department = 'Some Department',
  ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='PopulateCountry@testorg.com');       
  insert u;
  System.assert(u.Id != null);

//Create dummy accounts
    Account[] acc = new Account[]
    {
       new Account(Name = '1',Type = 'Customer',OwnerId = u.Id,MSA_Amount__c = 1000,MSA_Billing_Frequency__c = 'annually',Hosting_Fee__c = 2000, MC_University_Amount__c = 3000,SPARK_Amount__c = 30000,Currency_Type__c = 'USD', Account_Management_Type__c = 'Key (WIG)',       MasterControl_Inc_FTE__c = 300, Override_NPS_Score_Comments__c = 'do it', Override_NPS_Score__c = 'Promoter - 9.5'),
//more accounts


    };    
    insert acc; 

    Test.startTest();
    PageReference pg = Page.anycustomeremployeetimeoverview;
    Test.setCurrentPage(pg);

// create a new Account standard controller by passing it the account record
    ApexPages.StandardController controller = new ApexPages.StandardController(acc[0]);

    // now pass it to the extension
    ColumnControllerExt stdController = new ColumnControllerExt(controller);

    system.assert(stdController != null); // controller has successfully been created
   
    List<String> loa=stdController.list_of_accountmanagement;
    System.assertNotEquals(0, loa.size());

    MAP<String,LIST<Account>> g = stdController.accsBucketedByType; 
    

    List<Account> a1 = [SELECT Id,name,Opportunity_Order_Status__c,NPS_Status__c,Case_Status_Stoplight__c,MSA_Status__c,Version_Status__c,Risk_Status__c,Team_Management_Status__c,Overall_Status__c,Total_RR_Converted_to_USD__c,Account_Management_Type__c,x3re__c FROM Account WHERE Id IN :acc AND Account_Management_Type__c =:'Key (WIG)'order by Name];
    System.debug('***************************************** List= '+a1);
    g.put('Key (WIG)' ,a1);



    Test.stopTest();
  }
}



 
badibadi
Remove  
List<Account> a1 = [SELECT Id,name,Opportunity_Order_Status__c,NPS_Status__c,Case_Status_Stoplight__c,MSA_Status__c,Version_Status__c,Risk_Status__c,Team_Management_Status__c,Overall_Status__c,Total_RR_Converted_to_USD__c,Account_Management_Type__c,x3re__c FROM Account WHERE Id IN :acc AND Account_Management_Type__c =:'Key (WIG)'order by Name];
    System.debug('***************************************** List= '+a1);
    g.put('Key (WIG)' ,a1);

and add this line
 
MAP<String,LIST<Account>> g = stdController.accsBucketedByType; 
    
	g= stdController.getmap_values();

 
This was selected as the best answer
Merry SMerry S
badI
Thank you! If you are at Dreamforce this year I would like to buy you a coffee/soda/drink. I seriously ran around hugging people.
badibadi
Merry S,
No, Unfortunately I cannot make it to Dreamforce this year. Thank you :)