I keep getting an assertion failure with my test class for the following trigger:
trigger WebToCaseCountry on Case (after insert)
{
Set<String> countries = new Set<String>();
for (Case c : Trigger.new)
{
if (!String.isEmpty(c.CountryWebFormText__c) && c.Newsletter__c == TRUE)
{
countries.add(c.CountryWebFormText__c);
}
}
if (countries.size() > 0)
{
Map<String, Id> filteredCountries = new Map<String, Id>();
for (Area__c a : [select Name, Id from Area__c where Name in :countries])
{
filteredCountries.put(a.Name, a.Id);
}
if (filteredCountries.size() > 0)
{
List<Case> caseUpdates = new List <Case>();
List<Contact> contactUpdates = new List <Contact>();
for (Case c : Trigger.new)
{
if (filteredCountries.containsKey(c.CountryWebFormText__c))
{
Id areaId = filteredCountries.get(c.CountryWebFormText__c);
caseUpdates.add(new Case(Id = c.Id, Country_of_Origin__c = areaId));
if (c.ContactId != null)
{
contactUpdates.add(new Contact(Id = c.ContactId, Country__c = areaId));
}
}
}
update caseUpdates;
update contactUpdates;
}
}
}
This is my test class:
@isTest(SeeAllData=true)
public class WebToCaseCountryTest
{
public static testMethod void testTrigger()
{
Area__c ar = new Area__c(Name = 'CA');
insert ar;
Case caseObj = new Case(CountryWebFormText__c ='CA', Newsletter__c = TRUE);
insert caseObj;
System.debug(caseObj);
System.assertEquals(caseObj.CountryWebFormText__c, caseObj.Country_of_Origin__c);
}
}
This is the error I am getting:
System.AssertException: Assertion Failed: Expected: CA, Actual: null -- STACK TRACE: Class.WebToCaseCountryTest.testTrigger: line 19, column 1
Anyone know why this is happening?
System.debug
in your code you would also be able to know how this is happening.