public class QMT_ReviewSubmit {
public static QMT_Apex_Debug_Logs__c logger = new QMT_Apex_Debug_Logs__c(Apex_Class__c = 'QMT_ReviewSubmit', Type__c = 'UI');
public static String QMTThumbnail = System.Label.QMT_Thumbnail;
public static String QMTcontentimage = System.Label.QMT_Content;
public static String QMTVideolink = System.Label.QMT_Video_link;
public static String editorProfile = System.Label.Commn_QMTEditor;
// Added by Shankar on Mar 06 2018
public static QMT_Content__c QMTContent;
@AuraEnabled
public static Contact getCurrentUser(){
user CurrentuserforSender = null;
Contact USerAsContacts = null;
try {
CurrentuserforSender = [select Id, Username, Email, Name from User where Id = : UserInfo.getUserId()];
USerAsContacts = [SELECT Id, Name, LastName, Email from Contact where Email =: CurrentuserforSender.Email];
} catch (QueryException ex) {
insert new QMT_Apex_Debug_Logs__c(Apex_Class__c = 'QMT_ReviewSubmit', Type__c = 'UI',
Message__c = System.Label.QMT_Database_SOQL_Failure,
Method__c = 'getCurrentUser',
Stack_Trace__c = ex.getStackTraceString());
}
return USerAsContacts;
}
Test Class:
@isTest
public class QMT_ReviewSubmitTest {
static testMethod void test1() {
Profile p = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];
User u = new User(Alias = 'asdsad', Email = '[email protected]',
EmailEncodingKey = 'UTF-8', LastName = 'Testing', LanguageLocaleKey = 'en_US',
LocaleSidKey = 'en_US', ProfileId = p.Id,
TimeZoneSidKey = 'America/Los_Angeles', UserName = '[email protected]');
insert u;
Account a = new Account();
a.name = 'test';
insert a;
Contact con = new Contact();
con.LastName = 'test';
con.AccountId = a.id;
con.FirstName = 'test';
con.Email = '[email protected]';
con.QMT_PersonnelNbr__c = 2.0;
insert con;
QMT_Content__c c = new QMT_Content__c();
c.name = 'test';
c.QMT_Main_Body__c = 'test1tesdt2';
c.Featured_Image_ID__c = 'test';
c.QMT_Primary_Title__c = 'test';
Recordtype RecordTypeIdcomm = [Select Id, Name From RecordType where Name = 'News / Alert' limit 1];
c.RecordTypeId = RecordTypeIdcomm.id;
QMT_Segment__c segment = new QMT_Segment__c();
insert segment;
c.SegmentId__c = segment.Id;
insert c;
QMT_Segment_Definition__c segmentDefinition = QMT_UnitTestData.createSegmentDefinition(segment.Id);
insert segmentDefinition;
system.assertEquals('[email protected]', con.Email);
List<String> allSelectedTopics = new List<String> {'test', 'test1'};
QMT_CM_Topic_Master__c ci = new QMT_CM_Topic_Master__c();
ci.TopicName__c = 'test';
insert ci;
QMT_CM_RestrictedAudience_Master__c ci2 = new QMT_CM_RestrictedAudience_Master__c();
ci2.RAName__c = 'test';
insert ci2;
List<Folder> contentimagefolder = [Select Id From Folder Where Name =: Label.QMT_Content];
List<Folder> thumbnailimagefolder = [Select Id From Folder Where Name =: Label.QMT_Thumbnail];
Document document = new Document();
document.Body = Blob.valueOf('Some Text');
document.ContentType = 'application/pdf';
document.DeveloperName = 'QMT_ContentImage';
document.IsPublic = true;
document.Name = 'QMT content Image';
if (contentimagefolder.size() > 0)
document.FolderId = contentimagefolder[0].Id; //[select id from folder where name = 'QMT Content'].id;
insert document;
Document document1 = new Document();
document1.Body = Blob.valueOf('Some Text');
document1.ContentType = 'application/pdf';
document1.DeveloperName = 'QMT_ThumbnailImage';
document1.IsPublic = true;
document1.Name = 'QMT Thumbnail Image';
if (contentimagefolder.size() > 0)
document1.FolderId = thumbnailimagefolder[0].id; //[select id from folder where name = 'QMT Content'].id;
insert document1;
QMT_Content_Topic_Jun__c CTopicJun = new QMT_Content_Topic_Jun__c(CM_Topic_Name__c = ci.Id, CommunicationContentName__c = c.Id);
insert CTopicJun;
// Recordtype RecordTypeIdcomm =[Select Id,Name From RecordType where Name='News / Alert' limit 1];
String date1 = '2018-05-14T07:00:00.000Z';
String date2 = 'May 14, 2018 7:00:00 AM';
system.runAs(u) {
try{
Test.startTest();
QMT_ReviewSubmit QMT = new QMT_ReviewSubmit();
QMT_ReviewSubmit.getCurrentUser();
Test.stopTest();
} catch (DmlException e) {
}
}
}
Test class is passing but catch block is not covering? Can any one suggest me how to do that?
} catch (QueryException ex) {
insert new QMT_Apex_Debug_Logs__c(Apex_Class__c = 'QMT_ReviewSubmit', Type__c = 'UI',
Message__c = System.Label.QMT_Database_SOQL_Failure,
Method__c = 'getCurrentUser',
Stack_Trace__c = ex.getStackTraceString());
}