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
sfuser12sfuser12 

cover wrapper class

Hello,

I am writing test class for wrapper class. I have done everything. still covergae for wrapper class in only 1%. Can anyone help?

Class:
 public void assignLeads() {
        System.debug('CFRRetentionSiteDashboardController2.assignLeads - start ' + LEAD_QUALIFICATION_CAMPAIGN + '::' + LeadSourceSelection);

        TotalNumberOfAllocatedLeads = 0;
        System.debug('CFRRetentionSiteDashboardController2.sumOfTheLeads()-agentWrappers-' + agentWrappers);
        for (UserWrapper agentUserWrapper : agentWrappers) {
            TotalNumberOfAllocatedLeads += agentUserWrapper.numberOfLeadsToAssign;
        }
        System.debug('TotalNumberOfAllocatedLeads' + TotalNumberOfAllocatedLeads);

        List<Lead> leads = getLeadsToBeAssigned();
        List<Lead> leadsToUpdate = new List<Lead>();

        Integer totalLeads = leads.size();
        System.debug('totalLeads--' + totalLeads);
        if (leads.isEmpty() || totalLeads < TotalNumberOfAllocatedLeads) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error, 'Number of allocated leads are more than available leads.'));
        } else {
            List<UserWrapper> assignLeadsToAgents = new List<UserWrapper>();
            for (UserWrapper agentUserWrapper : agentWrappers) {
                if (agentUserWrapper.numberOfLeadsToAssign > 0) {
                    assignLeadsToAgents.add(agentUserWrapper);
                }
            }

            Integer startLeadAssignment = 0;
            for (UserWrapper agentUserWrapper : assignLeadsToAgents) {
                Integer agentLeads = agentUserWrapper.numberOfLeadsToAssign;
                for (Integer startAgentLead = 0; startAgentLead < agentLeads; startAgentLead++) {
                    Lead tmpLead = leads[startLeadAssignment];
                    tmpLead.OwnerId = agentUserWrapper.agent.Id;
                    tmpLead.Retention_Owner__c = agentUserWrapper.agent.Name;
                    if (currentSite != null) {
                        tmpLead.Retention_Site__c = currentSite.Id;
                    }
                    leadsToUpdate.add(tmpLead);
                    startLeadAssignment++;
                }
            }

            update leadsToUpdate;
            System.debug('CFRRetentionSiteDashboardController2.assignLeads-- leadsToUpdate' + leadsToUpdate);
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.CONFIRM, 'Lead Assignment has been successfully processed.'));
            refresh();

Test Class:

        Profile profile = [SELECT Id FROM Profile WHERE Name='System Administrator'];

        User user = new User(firstname = 'testUserFname',
                lastName = 'testULastname',
                email = 'testUser@test.org',
                Username = 'testUserassignleads@test.org',
                EmailEncodingKey = 'ISO-8859-1',
                Alias ='testUser',
                TimeZoneSidKey = 'America/Los_Angeles',
                LocaleSidKey = 'en_US',
                LanguageLocaleKey = 'en_US',
                ProfileId = profile.Id
        );
        insert user;

        CFRRetentionSiteDashboardController2 controller = new CFRRetentionSiteDashboardController2();
        controller.assignLeads();
       
        CFRRetentionSiteDashboardController2.UserWrapper userWrapper = new CFRRetentionSiteDashboardController2.UserWrapper(user,true);
        List<Lead> leads = controller.getLeadsToBeAssigned();