Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- User currentUser = [SELECT contactId FROM User WHERE Id = :UserInfo.getUserId()];
- System.debug('Current user' + currentUser);
- //Fetch the current contact object
- if(String.isNotBlank(currentUser.ContactId)) {
- contact = [
- SELECT AccountId, firstName, lastName, MiddleName, Nickname__c, Suffix, MailingStreet, MailingCity,
- MailingStateCode, Certify_Complete_and_Correct__c, Certify_Download_Instructions_to_PreCan__c
- FROM Contact
- WHERE Id = :currentUser.ContactId
- LIMIT 1
- ];
- System.debug('contact information: ' + contact );
- //Fetch the current application object
- application = [
- SELECT Id, Contact__c, Attend_College_after_High_School__c
- FROM Application__c
- WHERE Contact__c =: currentUser.contactId
- LIMIT 1];
- }
- }
- And the following submit method in the apex class
- public pagereference submit() {
- if (
- contact.Certify_Complete_and_Correct__c == false ||
- contact.Certify_Download_Instructions_to_PreCan__c == false
- )
- {
- ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please make sure all required fields are populated.');
- ApexPages.addMessage(myMsg);
- return null;
- }
- // ALO Code
- if(application.Attend_College_after_High_School__c == 'No')
- {
- acc = [
- SELECT Id, OwnerId
- FROM Account
- WHERE Id =: contact.AccountId
- ];
- contact.ALO__c = acc.OwnerId;
- }
- else if(application.Attend_College_after_High_School__c == 'Yes')
- {
- ziptoLOD = [
- SELECT Id, Name, LOD__c
- FROM Zip_3_to_LOD__c
- WHERE Name =: contact.Extract_Zipcode__c
- ];
- contact.ALO__c = ziptoLOD.LOD__c;
- }
- static testMethod void submit_Test() {
- Profile AdminProfile = [select id from profile where name='System Administrator'];
- UserRole AdminRole = [SELECT id from UserRole where name = 'Admin'];
- User currentuser = new User();
- currentuser.firstname ='James';
- currentuser.lastname ='Dobb';
- currentuser.email ='[email protected]';
- currentuser.username ='[email protected]';
- currentuser.alias ='jdobb';
- currentuser.TimeZoneSidKey ='GMT';
- currentuser.LocaleSidKey ='en_US';
- currentuser.emailencodingkey ='UTF-8';
- currentuser.languagelocalekey ='en_US';
- currentuser.ProfileId = AdminProfile.Id;
- currentuser.userroleid = AdminRole.Id;
- insert currentuser;
- Account acc= new Account();
- acc.OwnerId='005r0000001i9xA';
- acc.Name='Atlanta Area Tech School';
- acc.RecordTypeId='012r00000005DsA';
- Zip_3_to_LOD__c zip= new Zip_3_to_LOD__c();
- zip.Name = '480';
- zip.LOD__c = '005t0000001LDpi';
- Contact contact = new Contact();
- contact.firstName = 'Alex';
- contact.lastName = 'Cauller';
- contact.email = '[email protected]';
- contact.AccountId = acc.Id;
- system.runas(currentuser){
- insert acc;
- insert contact;
- insert zip;
- }
- Application__c app= new Application__c();
- app.Contact__c = contact.Id;
- app.Attend_College_after_High_School__c= 'No';
- system.runas(currentuser){
- insert app;
- }
- Profile pr = [select id from profile where name='......'];
- User u = new User();
- u.firstname ='James';
- u.lastname ='Dobb';
- u.email ='[email protected]';
- u.username ='[email protected]';
- u.alias ='jdobb';
- u.TimeZoneSidKey ='GMT';
- u.LocaleSidKey ='en_US';
- u.emailencodingkey ='UTF-8';
- u.languagelocalekey ='en_US';
- u.ProfileId = pr.Id;
- u.contactId =contact.id;
- insert u;
- system.runAs(u){
- System.Test.startTest();
- Page4Controller controllerClass = new Page4Controller();
- controllerClass.contact.Certify_Complete_and_Correct__c = false;
- controllerClass.contact.Certify_Download_Instructions_to_PreCan__c = false;
- controllerClass.submit();
- System.AssertEquals(controllerClass.contact.ALO__c,acc.OwnerId);
- controllerClass.application.Attend_College_after_High_School__c = 'Yes';
- controllerClass.submit();
- System.AssertEquals(controllerClass.contact.ALO__c,zip.LOD__c);
- controllerClass.previouspage();
- System.Test.stopTest();
- }
- When I run the test case, the test case fails and generates the following error on both the assert statements
- System.AssertException: Assertion Failed: Expected: null, Actual: 005r0000001i9xAAAQ
- }
Add Comment
Please, Sign In to add comment