I'm trying to get proper code coverage for a schedulable class, but I'm only hitting the 45% mark and I'm not sure why. Here's the class:
global class opportunityContactReferralIdCopy implements Schedulable {
global void execute(SchedulableContext SC) {
// Create a map
Map<ID,String> updateTheseOpps = new Map<ID,String>();
// Create a loop with SOQL and add results to the list
for(OpportunityContactRole ocr : [ SELECT OpportunityId,Contact.Referral_ID__c
FROM OpportunityContactRole
WHERE ContactId IN (SELECT Id FROM Contact WHERE Referral_ID__c != null)
AND OpportunityId IN (SELECT Id FROM Opportunity WHERE Referral_ID__c = null)
AND CreatedDate = TODAY]) {
updateTheseOpps.put(ocr.OpportunityId,ocr.Contact.Referral_Id__c);
}
// Determine the size of the list
Integer ListSize = updateTheseOpps.size();
if( ListSize < 1 ) {
system.debug('List is too small');
} else {
// List is a proper size
system.debug('List is big enough');
// Update needs to know the type so create objects of the right type
Opportunity[] updates = new Opportunity[] {};
// Loops and creates the update
for (Id id : updateTheseOpps.keySet()) {
updates.add(new Opportunity(Id = id, Referral_Id__c = updateTheseOpps.get(id)));
}
update updates;
}
}
}
And the test class:
@isTest
private class opportunityContactReferralIdCopyTest {
static testMethod void test2() {
Test.StartTest();
Account a = new Account(Name='TestAccount');
insert a;
String aId = a.id;
Contact c = new Contact(AccountId=a.Id,FirstName='Bob',LastName='Smith',LeadSource='Advertising',Lead_Source_Detail__c='PPC');
insert c;
String cId = c.id;
Opportunity o = new Opportunity(Name='FakeOp',
Type='New Business',
StageName='Nurture',
CloseDate=system.today()+90,
Competitors__c='None',
ACV__c=decimal.valueof('20'),
AccountId=a.Id
);
insert o;
String oId = o.id;
OpportunityContactRole ocr = new OpportunityContactRole(ContactId=cId,OpportunityId=oId,Role='Champion');
insert ocr;
opportunityContactReferralIdCopy sh1 = new opportunityContactReferralIdCopy();
String sch = '0 0 23 * * ?';
system.schedule('TestOppCopy', sch, sh1);
Test.stopTest();
}
}
Any ideas why this wouldn't achieve proper coverage?