0

I am trying to develop a test class for a VF page controller, but I am not able to get some of my lines covered. Specifically, I am having trouble covering lines 54-58 and 75-79. Can anyone help explain why?

Test Class:

@IsTest(SeeAllData=true)
private class TestControllerRDA
{
    static testMethod void testRDAcontroller()
    {
        Profile profile1 = [SELECT Id
                            FROM Profile
                            WHERE Name = 'Standard User'];

        User user1 = new User(
            Alias = 'RDAUser',
            Email = 'stdUserRDA@test.com',
            EmailEncodingKey = 'UTF-8',
            LastName = 'TestUserLast',
            LanguageLocaleKey = 'en_US',
            LocaleSidKey = 'en_US',
            ProfileId = profile1.Id,
            TimeZoneSidKey = 'America/New_York',
            UserName = 'stdUserRDA@test.com');
        insert user1;


        RecordType rtAcct = [SELECT id,Name
                        FROM RecordType
                        WHERE SobjectType='Account' and Name='Sales Account' Limit 1];

        Account acct1 = new Account(
            RecordTypeId = rtAcct.Id,
            Name = 'Test Account',
            Industry = 'Test',
            Type = 'Test',
//            CurrencyIsoCode = 'USD',
            Global_Region__c = 'North America',
            Domestic_Region__c = 'US - NYC');
        insert acct1;

        Contact cont1 = new Contact(
//            OwnerId = user1.Id;
            FirstName = 'TestFirst',
            LastName = 'TestLast',
            AccountId = acct1.Id);
        insert cont1;

        RecordType rtOpp = [SELECT id,Name
                            FROM RecordType
                            WHERE SobjectType='Opportunity' and Name='Premier - Pre-Paid' Limit 1];

        Opportunity opp1 = new Opportunity(
            RecordTypeId = rtOpp.Id,
            Name = 'Test Opp',
            AccountId = acct1.Id,
            Type = 'New',
            Commitment_Type__c = 'Commitment',
            CloseDate = System.today(),
            StageName = 'Identified',
            ForecastCategoryName = 'Unlikely',
//            CurrencyIsoCode = 'USD',
            Primary_Contact__c = cont1.Id);
        insert opp1;

/*        OpportunityContactRole ocRole1 = new OpportunityContactRole (
            ContactId = cont1.Id,
            OpportunityId = opp1.Id,
            Role='Signatory',
            IsPrimary=TRUE);
        insert ocRole1;*/

        Task task1 = new Task();
            Task1.WhoId = cont1.Id;
            Task1.WhatId = acct1.Id;
            Task1.Status = 'Completed';
            Task1.Subject = 'Testing';
            Task1.Description = 'Test Desc';
            Task1.OwnerId = user1.Id;
            Task1.RDA__c = TRUE;

        ApexPages.StandardController RDA1 = new ApexPages.standardController(cont1);
        VF_Controller_RDATasks RDA1a = new VF_Controller_RDATasks(RDA1);
        RDA1a.listTask.add(Task1);
        RDA1a.RDA();
        RDA1a.saveRDA();

        Task task1a = new Task();
            Task1a.WhoId = cont1.Id;
            Task1a.WhatId = acct1.Id;
            Task1a.Status = 'Completed';
            Task1a.Subject = 'Testing';
            Task1a.Description = 'Test Desc';
            Task1a.OwnerId = user1.Id;
            Task1a.RDA__c = TRUE;

        ApexPages.StandardController RDA1b = new ApexPages.standardController(cont1);
        VF_Controller_RDATasks RDA1ba = new VF_Controller_RDATasks(RDA1b);
        RDA1ba.listTask.add(Task1a);
        RDA1ba.RDA();
        RDA1ba.saveAdd();

        Task task2 = new Task();
            Task2.WhoId = cont1.Id;
            Task2.WhatId = acct1.Id;
            Task2.Status = 'Completed';
            Task2.Subject = 'Testing';
            Task2.Description = 'Test Desc';
            Task2.OwnerId = user1.Id;
            Task2.RDA__c = TRUE;
            Task2.FollowUp__c = TRUE;

        Task task2a = new Task();
            Task2a.WhoId = cont1.Id;
            Task2a.WhatId = acct1.Id;
            Task2a.Status = 'Completed';
            Task2a.Subject = 'Testing';
            Task2a.Description = 'Test Desc';
            Task2a.OwnerId = user1.Id;
            Task2a.RDA__c = TRUE;

        ApexPages.StandardController RDA2 = new ApexPages.standardController(cont1);
        VF_Controller_RDATasks RDA2a = new VF_Controller_RDATasks(RDA2);
        RDA2a.listTask.add(Task2);
        RDA2a.RDA();
        RDA2a.saveRDA();

        ApexPages.StandardController RDA3 = new ApexPages.standardController(cont1);
        VF_Controller_RDATasks RDA3a = new VF_Controller_RDATasks(RDA3);
        RDA3a.listTask.add(Task2a);
        RDA3a.RDA();
        RDA3a.saveAdd();
}
}

Controller:

public with sharing class VF_Controller_RDATasks{

    public list<Task> listTask{get;set;}
//    public Task taskFollow{get;set;}
    public list<Task> listTaskFollow{get;set;}
    public integer n;

    Set<Task>Tasks = new Set<Task>();
    Set<Task>FollowTasks = new Set<Task>();

    private final Contact con;
    public VF_Controller_RDATasks(ApexPages.StandardController myController){
        listTask = new List<Task>();
        listTaskFollow = new List<Task>();
        con=(Contact)myController.getRecord();
    }

//  Adds RDA Task to list
    public void RDA()
    {
        listTask.add(new Task(
           WhoId = con.Id,
           Status = 'Completed',
           ActivityDate = system.TODAY(),
           Subject = '',
           Description = '',
           OwnerId = UserInfo.getUserId(),
           WhatId = con.AccountId,
           RDA__c = TRUE)
           );
    }

//  Adds RDA Follow-Up Task to list
    public void RDAfollow()
    {
        n=listTask.size()-1;
        listTaskFollow.add(new Task(
           WhoId = con.Id,
           Status = 'In Progress',
           ActivityDate = system.TODAY()+7,
           Subject = 'Follow-Up: '+listTask[n].Subject,
           OwnerId = UserInfo.getUserId(),
           WhatId = con.AccountId,
           RDA__c = TRUE)
           );
    }

//  Saves of RDA & follow-up tasks & add another
    public PageReference saveAdd(){
        insert listTask;
        insert listTaskFollow;

        if(!listTaskFollow.isEmpty()){
            Tasks.addAll(listTask);
            FollowTasks.addAll(listTaskFollow);
        if(!Tasks.containsAll(FollowTasks)){
            integer last = listTaskFollow.size()-1;
            listTask.add(listTaskFollow[last]);
        }
        }
        RDAfollow();
            {
            PageReference contactPage = new PageReference('/apex/RDA_Task?id=' + con.Id);
            contactPage.setRedirect(true);
            return contactPage;
            }
    }

//  Saves RDA & Follow-up Tasks added no additional
    public PageReference saveRDA(){
        insert listTask;
        insert listTaskFollow;

        if(!listTaskFollow.isEmpty()){
            Tasks.addAll(listTask);
            FollowTasks.addAll(listTaskFollow);
        if(!Tasks.containsAll(FollowTasks)){
            integer last = listTaskFollow.size()-1;
            listTask.add(listTaskFollow[last]);
        }
        }
        RDAfollow();
            {
            PageReference contactPage = new PageReference('/' + con.Id);
            contactPage.setRedirect(true);
            return contactPage;
            }
    }
}
  • 2
    That is not a unit test. It tests way more than one unit and does not contain a single assertion. – Adrian Larson Jan 26 '17 at 22:10
  • I don't understand? – John Neilan Jan 26 '17 at 22:24
  • 2
    Try and break up your test method into multiple tests. Then, it will be more readable and you might even find out why those lines aren't getting hit. – akcorp2003 Jan 26 '17 at 22:36
  • N.B. there is no good reason to use seeAllData=true – cropredy Jan 27 '17 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.