I have attempted to write my first test apex class, and although it looks correct when i try and save i get the following error
"Method does not exist or incorrect signature: getPolicy() at line 74 column 37".
I have been looking at this class for the last 2 hours trying to work out what the problem is, however i am keep drawing a blank.
/********************************************************************
*DM_MarketingCloudPolicyController_Test
*
*Test class for DM_MarketingCloudPolicyController
*
*Author:
*Created: 14/09/2015
*The @isTest class annotation indicates this class only contains test methods.
*Classes defined with the @isTest annotation do not count against the organization
*size limit for all Apex scripts.See the Apex Language Reference for more information
*about Testing and Code Coverage. Look @ BG coding standards if any doubts
********************************************************************/
@isTest
private class DM_MarketingCloudPolicyController_Test{
static testMethod void DM_MarketingCloudPolicyController_Test(){
/*
* Test Accept & Decline of Marketing Cloude policy
*/
Profile prof1 = [SELECT Id, Name FROM Profile WHERE Name = 'System Administrator'];
User user1 = new User();
user1.FirstName = 'Daniel';
user1.LastName = 'Mason';
user1.Email = '[email protected]';
user1.Username = '[email protected]';
user1.Alias = 'DMaso';
user1.CommunityNickname = 'DMaso';
user1.TimeZoneSidKey = 'America/Los_Angeles';
user1.LocaleSidKey = 'en_US';
user1.EmailEncodingKey = 'UTF-8';
user1.ProfileId = prof1.Id;
user1.LanguageLocaleKey = 'en_US';
user1.Marketing_Cloud_Acceptance_Date__c = null;
insert user1;
//Setup Custom Setting for profile
Data_Policy_Settings__c dps = new Data_Policy_Settings__c();
dps.Show_Marketing_Policy__c = true;
dps.SetupOwnerId = prof1.Id;
//Create Test Policy
Data_Policy__c dp1 = new Data_Policy__c();
dp1.Name = 'Test Data Policy';
dp1.Start_Date__c = date.today();
dp1.MarketingCloudPolicyText__c = 'Everyone Loves creating test classes ...';
insert dp1;
system.assertEquals(1, [SELECT Count() FROM User WHERE email = '[email protected]' LIMIT 1]);
PageReference pageRef = Page.DataPolicyPage;
System.runAs(user1){
test.startTest();
DM_MarketingCloudPolicyController controllerInstance = new DM_MarketingCloudPolicyController();
boolean redirect = controllerInstance.getRedirect();
test.setCurrentPage(pageRef);
DM_MarketingCloudPolicyController controller = new DM_MarketingCloudPolicyController();
//Declining VF Page
PageReference logout = controller.closePopupDecline();
system.assertEquals('/secur/logout.jsp',logout.getURL());
//Accepting VF Page
controller.closePopupAccept();
user1 = [SELECT Marketing_Cloud_Acceptance_Date__c FROM User WHERE email = '[email protected]'LIMIT 1];
system.assertEquals(date.today(),user1.Marketing_Cloud_Acceptance_Date__c);
Data_Policy__c dataPolicy = getPolicy();
system.assertEquals(true,dataPolicy != null);
test.stopTest();
}
}
}
Here is my controller class
/********************************************************************
* DM_MarketingCloudPolicyController
*
* Controller class for MarketingCloudPolicyPage
*
* Author: Daniel Mason
* Created: 14/09/2015
* add et4ae5__ExactTargetForAppExchangeUser__c = True logic userloggedin
*
********************************************************************/
public class DM_MarketingCloudPolicyController{
Id uid;
User loggedInUser;
public DM_MarketingCloudPolicyController(){
uid = UserInfo.getUserId();
loggedInUser = [SELECT Id, Marketing_Cloud_Acceptance_Date__c
FROM User
WHERE Id = :uid
LIMIT 1];
}
public PageReference closePopupAccept() {
// Method to write back data policy acceptance date to user on accept
loggedInUser.Marketing_Cloud_Acceptance_Date__c = date.today();
update loggedInUser;
PageReference p = new PageReference('/home/home.jsp');
p.setRedirect(true);
return p;
}
public PageReference closePopupDecline() {
// Method to logout user afer decline
PageReference p = new PageReference('/secur/logout.jsp');
p.setRedirect(true);
return p;
}
public static Data_Policy__c getPolicy(){
// Method to obtain data policy text
Data_Policy__c dp = [SELECT Id, Name, Start_Date__c, MarketingCloudPolicyText__c
FROM Data_Policy__c
LIMIT 1];
return dp;
}
public boolean getRedirect(){
// Method to determine show popup
boolean redirect = false;
Data_Policy__c dp = getPolicy();
Data_Policy_Settings__c dps = Data_Policy_Settings__c.getInstance(UserInfo.getProfileId());
if(dps.Show_Marketing_Policy__c == true && (loggedInUser.Marketing_Cloud_Acceptance_Date__c == null && loggedInUser.et4ae5__ExactTargetForAppExchangeUser__c == True || loggedInUser.Marketing_Cloud_Acceptance_Date__c.addYears(1) < date.today() || loggedInUser.Marketing_Cloud_Acceptance_Date__c < dp.Start_Date__c)){
redirect = true;
}
return redirect;
}}
getPolicy()
method in this class. Did you check for that?