I have been trying to create a test class for a Visualforce page controller and have run into a slight issue. I have total coverage except for a section of the controller that looks at the Owner.Name. When I use a system.debug in my test class, it appears that even though I am creating a test user in the test class with firstname and lastname filled out, the Name field is appearing null.
Can anyone help with this? Let me know if you need to see the controller as well.
Test Class:
@isTest
public class AttachmentUploadController_Test {
private static testMethod void AttachmentUploadController_Test()
{
Profile p = [select id from profile where name='Standard User'];
User u = new User(alias = 'standt', email='[email protected]',
emailencodingkey='UTF-8', firstname='fake', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='[email protected]');
insert u;
Apttus__APTS_Agreement__c agmt1 = new Apttus__APTS_Agreement__c();
agmt1.Ownerid = u.id;
insert agmt1;
Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
test.starttest();
PageReference pgRef = Page.Attach_File_Upload;
Test.setCurrentPageReference (pgRef);
ApexPages.currentPage().getParameters().put('Id',agmt1.id);
AttachmentUploadControllerDemo attch = new AttachmentUploadControllerDemo(new ApexPages.StandardController(agmt1));
System.assertEquals(true, attch.preattached);
attch.unAttach();
attch.upload();
AttachmentUploadControllerDemo.attachmentName = 'Test';
AttachmentUploadControllerDemo.attachmentBody = bodyBlob;
attch.upload();
u.firstname='LPO';
u.lastname='Storage';
update u;
system.debug('USER NAME: ' + u.name + ' FIRST NAME: ' + u.firstname + ' LAST NAME: ' + u.lastname);
AttachmentUploadControllerDemo attch2 = new AttachmentUploadControllerDemo(new ApexPages.StandardController(agmt1));
attch2.upload();
test.stopTest();
}
}