Below is the code of negative scenario: public void onAddExistingGuest(){ selectedGroups = new Set<Grouping__c>();
ApexPages.Message msg;
msg = new ApexPages.Message(ApexPages.Severity.Error, System.Label.Value_Here);
ApexPages.addMessage(msg);
try{
Kids_Club_Requests__c Kidsclubreq= getKidsclubreq();
Boolean tempVal = false;
if(Kidsclubreq != null ){
for( Grouping__c objgrouping : [select id,Name from Grouping__c where id = :Kidsclubreq.Tour_Grouping_Name__c limit 1]){
mapOfGrouping.put(objgrouping.id,objgrouping);}
lstgrouping.clear();
lstgrouping.addAll(mapOfGrouping.values());
displayaddexistingPopUp = false;
for(Grouping__c lstgroupingVar : mapOfGrouping.values()){
strToHoldGrpIds += lstgroupingVar.id + ConstantsClass.COMMA_VALUE;
}
}else{
**msg = new ApexPages.Message(ApexPages.Severity.Error, ConstantsClass.KIDS_CLUB_ERROR_MESSAGE);
ApexPages.addMessage(msg);
errorMessageToShow = ConstantsClass.KIDS_CLUB_ERROR_MESSAGE;**
}**strong text**
}catch (Exception excep){
//ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.Error, 'Error!'+excep.getMessage());
msg = new ApexPages.Message(ApexPages.Severity.Error, System.Label.Error_Group_Add);
ApexPages.addMessage(msg);
errorMessageToShow = System.Label.Error_Group_Add;
}
}
I need to cover the code coverage of negative scenarios like above: msg = new ApexPages.Message(ApexPages.Severity.Error, System.Label.Error_Group_Add); ApexPages.addMessage(msg); errorMessageToShow = System.Label.Error_Group_Add;