public with sharing class ChangePasswordController {
public String oldPassword {get; set;}
public String newPassword {get; set;}
public String verifyNewPassword {get; set;}
public PageReference outputText{get;set;}
public PageReference changePassword() {
system.debug('In ChangePasswordController 1 >>>>');
system.debug('oldPassword====' + oldPassword);
outputText = Site.changePassword(newPassword, verifyNewPassword, oldPassword);
system.debug(outputText);
try
{
if(outputText != null && outputText.getRedirect()) ***//test case is not covering this loop***
{
system.debug('In ChangePasswordController 2 >>>>');
CommonService commonService = new CommonService();
CRSessionService sessionService = new CRSessionService();
String userId = commonService.getStandardUserbyID(UserInfo.getUserId()).custUserID__c;
system.debug('userId >>>> ' + userId);
Users__c user = sessionService.getUserInformationByUserID(userId);
system.debug(user);
user.isFirstLogin__c = true;
//user.Password__c = newPassword;
UserService userService = new UserService();
userService.UpdateUser(user);
return new PageReference('/apex/CRRedirector');
}
return outputText;
}
catch(Exception ex)
{
system.debug(ex);
ExceptionService.saveException(ex, 'ChangePasswordController', 'ChangePassword', null);
return null;
}
}
public ChangePasswordController() {}
}
FOr this code I have written test case but its always returning me the null value why its so ?can u please tell me why or you can fix it.
TestClass is --->
@IsTest
public with sharing class ChangePasswordControllerTest {
private static User testUser ;
private static User u2 ;
static {
Contact c = [select AccountId , firstName, email, lastname from Contact where FirstName = 'TestUser' limit 1];
Profile applicantProfile = [Select Id, Name from Profile where Name = 'CashRelease User'];
testUser = new User(lastname = 'test',firstname = 'test', email = '[email protected]',username= '[email protected]',
profileId= applicantProfile.id,contactId= c.id,alias = 'test',emailencodingkey='UTF-8',
languagelocalekey='en_US',localesidkey='en_US', timezonesidkey='America/Los_Angeles');
insert(testUser);
}
@IsTest(SeeAllData=true) public static void testChangePasswordController1() {
System.setPassword(testUser.Id, 'abc123456');
ChangePasswordController controller = new ChangePasswordController();
controller.oldPassword = 'abc123456';
controller.newPassword = 'qwerty1234';
controller.verifyNewPassword = 'qwerty1234';
PageReference retVal = null;
System.runAs(testUser) {
retVal = controller.changePassword();
System.debug(retVal);
System.debug('RETURN URL '+Site.getOriginalURL());
System.assertEquals(retVal, null); // Everytime its returning null value
}
}
}
I am unable to cover if loop lines of code in ChangePassword() method because every time outputtext giving me null value .How can i cover these lines?