I am very new to Apex.. a day into it so sorry for my ingornace. What I am trying to do is return a list of my accounts and then review the contract dates of the account(Contract_Expiration__c). Depending on that date it should update a custome field ( update_active_status_text__c) with null, Active, or Void.
I am not getting any error but I am not getting any code coverage. Any help will go a long way.
Thanks in advance
Apex Class
public class update_active_status {
public static VOID update_active_statustest(){
list<Account> myaccount = [SELECT Id, Contract_Expiration__c, update_active_status_text__c FROM Account WHERE CMS_Customer_Type__c = 'Enterprise' or CMS_Customer_Type__c = 'cloud'];
for(Account a: myaccount){
if (a.Contract_Expiration__c == null ){
a.update_active_status_text__c = null;
update a;
} else if (a.Contract_Expiration__c >= Date.today().addDays(-60)) {
a.update_active_status_text__c = 'Active';
update a;
} else if (a.Contract_Expiration__c < Date.today().addDays(-60)) {
a.update_active_status_text__c = 'Void';
update a;
} else {
a.update_active_status_text__c = 'Void';
update a;
}
}
}
}
Test Class
@isTest
public class testupdate_active_status {
static testMethod void myupdate_active_statusTest() {
Account acc = new Account(Name = 'Test Account');
insert(acc);
Date d = Date.today();
acc.Contract_Expiration__c = d;
update(acc);
acc.update_active_status_text__c = 'Active';
update(acc);
acc = [Select update_active_status_text__c From Account Where Id = : acc.Id];
System.assertEquals('Active', acc.update_active_status_text__c);
}
static testMethod void setToNull() {
Account acc = new Account(Name = 'Test Account');
insert(acc);
Date d = Date.today();
acc.Contract_Expiration__c = d;
update(acc);
acc.Contract_Expiration__c = null;
update(acc);
acc = [Select update_active_status_text__c From Account Where Id = : acc.Id];
System.assertEquals(null, acc.update_active_status_text__c);
}
static testMethod void createWithDate() {
Date d = Date.today().addDays(-70);
Account acc = new Account(Name = 'Test Account', Contract_Expiration__c = d);
insert(acc);
acc.update_active_status_text__c = 'Void';
update(acc);
acc = [Select update_active_status_text__c From Account Where Id = : acc.Id];
System.assertEquals('Void', acc.update_active_status_text__c);
}
}