+ Start a Discussion
Frances AllenFrances Allen 

Test Classes only at 71% Despite Additions

I don't understand what else I need to add. 

This is my class and I'm testing this correctly. 
public with sharing class Volunteer implements Comparable {

    public Boolean isSelected { get; set; }
    public Boolean isActive { get; set; }
    public Boolean isAvailable { get; set; }
    public Decimal totalAvailability { get; set; }
    public Contact con { get; private set; }
    public List<Availability> availabilities { get; private set; }
    public List<Cohort_Assignment__c> existingAssignments { get; private set; }
    public Cohort_Assignment__c currentAssignment;
    private Cohort__c cohort;

    public Volunteer(Contact con, Cohort__c cohort) {
        this.con = con;
        this.isSelected = false;
        this.isActive = false;
        this.isAvailable = true;
        this.cohort = cohort;
        this.availabilities = new List<Availability>();
        this.existingAssignments = new List<Cohort_Assignment__c>();
        this.totalAvailability = 0;
    }

    public void addAvailability(Volunteer_Availability__c volunteerAvailability) {
        Availability newAvailability = new Availability(volunteerAvailability);
        this.availabilities.add(newAvailability);
        totalAvailability += newAvailability.hours;
    }

    public void addExistingAssignment(Cohort_Assignment__c assignment) {
        if(assignment.Cohort__c == this.cohort.Id) {
            this.currentAssignment = assignment;
            this.isSelected = true;
            if(assignment.Active__c) {
                this.isActive = true;
            }
        } 
    }

    public Integer getNumberOfAssignments() {
        return this.existingAssignments.size();
    }

    public class Availability {

        public Decimal hours { get; private set; }
        public String day { get; private set; }
        public String startTime { get; private set; }
        public String endTime { get; private set; }
        public Boolean allDay { get; private set; }

        public Availability(Volunteer_Availability__c volunteerAvailability) {
            day = volunteerAvailability.Day__c;
            startTime = volunteerAvailability.Start_Time__c;
            endTime = volunteerAvailability.End_Time__c;
            allDay = volunteerAvailability.All_Day__c;

            hours = allDay ? 10 : volunteerAvailability.End_Time_Hour__c - volunteerAvailability.Start_Time_Hour__c;
        }
    }

    public Integer compareTo(Object compareTo) {

        Volunteer compareToVolunteer = (Volunteer)compareTo;

        // compare Active
        if(isActive && !compareToVolunteer.isActive) return -1;
        if(!isActive && compareToVolunteer.isActive) return 1;

        // compare existing assignments
        if(existingAssignments.size() < compareToVolunteer.existingAssignments.size()) return -1;
        if(existingAssignments.size() > compareToVolunteer.existingAssignments.size()) return 1;

        // compare Colleges
        if(con.AccountId == cohort.College__c && compareToVolunteer.con.AccountId != cohort.College__c) return -1;
        if(con.AccountId != cohort.College__c && compareToVolunteer.con.AccountId == cohort.College__c) return 1;
        if(con.Account.Name > compareToVolunteer.con.Account.Name) return -1;
        if(con.Account.Name < compareToVolunteer.con.Account.Name) return 1;

        // compare availability
        if(totalAvailability > compareToVolunteer.totalAvailability) return 1;
        if(totalAvailability < compareToVolunteer.totalAvailability) return -1;

        return 0;
    }

}
This is the test class: 
@isTest

public class VolunteerTest {

    
   //create a cohort with Tuesday default 
    static testMethod void testVolunteerSorting() {
        
        
        Cohort__c cohort = new Cohort__c(
                Default_Day__c = 'Tuesday'
        );

        Contact con1 = TestDataFactory.getContact();
        Contact con2 = TestDataFactory.getContact();

        Cohort_Assignment__c assignment = new Cohort_Assignment__c(
                Active__c = true
        );

        Volunteer_Availability__c availability = new Volunteer_Availability__c(
                Day__c = 'Tuesday',
                Start_Time__c = '8:00 AM',
                End_Time__c = '9:00 AM'
        );
        
        availability.recalculateFormulas();

        Volunteer_Availability__c availabilityAllDay = new Volunteer_Availability__c(
                Day__c = 'Tuesday',
                All_Day__c = true
        );
        
        availabilityAllday.recalculateFormulas();

        Volunteer v1 = new Volunteer(con1, cohort);
        v1.addAvailability(availability);
        v1.addExistingAssignment(assignment);

        Volunteer v2 = new Volunteer(con1, cohort);
        v2.addAvailability(availabilityAllDay);
        v2.addExistingAssignment(assignment);
        
         Cohort_Assignment__c secondassignment = new Cohort_Assignment__c(
                Active__c = false 
             );
        
                Volunteer_Availability__c falseavailability = new Volunteer_Availability__c(
                Day__c = 'Tuesday',
                Start_Time__c = '8:00 AM',
                End_Time__c = '9:00 AM'
        );
        falseavailability.recalculateFormulas();

        Volunteer_Availability__c newavailabilityAllDay = new Volunteer_Availability__c(
                Day__c = 'Tuesday',
                All_Day__c = true
        );
        
        newavailabilityAllday.recalculateFormulas();

        Volunteer v3 = new Volunteer(con2, cohort);
        v3.addAvailability(falseavailability);
        v3.addExistingAssignment(secondassignment);

        Volunteer v4 = new Volunteer(con2, cohort);
        v4.addAvailability(availabilityAllDay);
        v4.addExistingAssignment(secondassignment);
        
        // new tests now 
        Cohort_Assignment__c thirdassignment = new Cohort_Assignment__c(
                Active__c = true 
             );
        
                Volunteer_Availability__c alldayavailability = new Volunteer_Availability__c(
                Day__c = 'Monday',
                All_day__c = true
        );
        
        alldayavailability.recalculateFormulas();

        Volunteer_Availability__c secondallday = new Volunteer_Availability__c(
                Day__c = 'Wednesday',
                All_Day__c = true
        );
        
        secondallday.recalculateFormulas();

        
        Volunteer v5 = new Volunteer(con2, cohort);
        v5.addAvailability(alldayavailability);
        v5.addExistingAssignment(thirdassignment);

        Volunteer v6 = new Volunteer(con2, cohort);
        v6.addAvailability(secondallday);
        v6.addExistingAssignment(thirdassignment);
        
        Test.startTest();
           testvolunteersorting();
        Test.stopTest();
        
        System.debug (v2.availabilities);
        System.assert(v2.isActive, true );
        System.assert(v2.isAvailable, true);
    }   
    
 }