You need to sign in to do that
Don't have an account?

Unit Test in Apex Code Help
Hi,
The following code throws a nullPointerException at the red highlighted line.
/** * An apex page controller that exposes the change password functionality */ public class ChangePasswordController { public String oldPassword {get; set;} public String newPassword {get; set;} public String verifyNewPassword {get; set;} public PageReference changePassword() { //return Site.changePassword(newPassword, verifyNewPassword, oldpassword); Site.changePassword(newPassword, verifyNewPassword, oldpassword); return new PageReference(Site.getOriginalUrl()); } public ChangePasswordController() {} public static testMethod void testChangePasswordController() { // Instantiate a new controller with all parameters in the page ChangePasswordController controller = new ChangePasswordController(); controller.oldPassword = '123456'; controller.newPassword = 'qwerty1'; controller.verifyNewPassword = 'qwerty1'; System.assertEquals(controller.changePassword(),null); } }
As it is, the code coverage is at 100% (with the error)... I tried fixing the error by checking the "oldPassword", "newPassword", and "verifyNewPassword" individually, but then the code coverage drops to 57% (the blue highlighted section doesn't get checked). This is not ideal... Can anyone give me some guidance as to how I can fix the error and keep the code coverage at 100%?
Thanks
Add a check in your "changePassword" method:
Thanks a lot! That did the trick, although code coverage dropped to 90%...
Thanks again.