Unable to cover the code coverage for the below boolean method any suggestions please i tried the below test class and checked logs, its not going inside exception catch block even though i tried to get an exception by making user inactive.am i not calling the method right?
- class: psController
- method:isPLUser
public static boolean isPLUser() {
try{
if (((user)currentUser).Contact.Account.Recordtypeid != Utility.partnerRecType){
throw new pscUtility.pscException('01', ' Record type is not valid.');
} else if (!((user)currentUser).isActive) {
throw new pscUtility.pscException('03', 'Partner user is not active');
} else {
return true;
}
} catch(exception e) {
}
return false;
Test class:
User testUser = [SELECT Id,contact.id,isactive ,contact.account.id FROM User WHERE Profile.name = 'Partner Sales'and isactive = true LIMIT 1];
test.startTest();
boolean ispilot = pscMainController.isPLUser();
user u = pscMainController.getUserContext();
try{
boolean ispilot2 = psController.isPLUser();
testUser.IsActive = false;
} catch (DmlException ex) {
system.assertEquals(ispilot, testUser.IsActive,'Partner user is not active' );
System.assertEquals('Partner user is not active', ex.getMessage());
}
test.stopTest();