Wrote a test class for a class which code coverage is 86%. How do I test for an exception('addError')?
Have a look
for (Account_Affiliation__c a: c.R00N300000014qT8EAI__r) {
if (a.recordtypeid == rtid && a.Status__c == 'ACTIVE' && a.Primary__c == true) {
if (id1 != null) { * *
if (orgmap.keyset().contains(a.id))
orgmap.get(a.id).addError('A contact should not be allowed to have more than 1 “Primary”, “Active”, “Employment” record at the same time. '); * *
}
id1 = a.Related_Account__c;
}
if (a.recordtypeid == rtIdemp && a.Status__c == 'ACTIVE' && a.Primary__c == true && a.Type__c == 'College') {
if (id2 != null) { * *
if (orgmap.keyset().contains(a.id))
orgmap.get(a.id).addError('- A contact should not be allowed to have more than 1 “Primary”, “Active”, “Education”, “College” record at the same time. '); * *
}
id2 = a.Related_Account__c;
}
if (a.recordtypeid == rtIdemp && a.Status__c == 'ACTIVE' && a.Primary__c == true && (a.Type__c == 'Grad School (Non-MBA)' || a.Type__c == 'MBA')) {
if (id3 != null) { * *
if (orgmap.keyset().contains(a.id))
orgmap.get(a.id).addError('- A contact should not be allowed to have more than 1 “Primary”, “Active”, “Education”, “Grad School (Non-MBA)” OR “MBA” record at the same time'); * *
}
id3 = a.Related_Account__c;
}
}