function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pravallika BadepallyPravallika Badepally 

CAN SOMEONE HELP ME IN TEST CLASS TO GET CODE COVERAGE OF ABOVE 80 AND METHOD IS NOT PASSING

APEX CLASS----
public class LGTN_eArkivInvoiceFiles_LCC {  
    @AuraEnabled 
    public static String getInvoiceContentDocument(String invoiceNumber){
        String contentDocumentId=null;
        String versionIdentifier='Invoice_'+invoiceNumber;
        List<ContentVersion> versions = [Select Id,ContentDocumentId from ContentVersion where eArkivDocumentIdentifier__c=:versionIdentifier];
        if(versions.isEmpty()){
            List< ApexCalloutLog__c > calloutlogsToUpsert = new List< ApexCalloutLog__c > ();
            LGTN_eArkivInvoiceFile_WS eArkiv_ws= new LGTN_eArkivInvoiceFile_WS (invoiceNumber,Label.LGTN_eArkiv_Invoice_IntegrationName,false);
            eArkiv_ws.setEndPoint(eArkiv_ws.endpoint+'='+invoiceNumber);
            eArkiv_ws.send(false);
            calloutlogsToUpsert.addAll(eArkiv_ws.callOutLogs);
            if(eArkiv_ws.callout.error == null) { 
                if(!UTIL_Apex.empty(eArkiv_ws.eArkivInvoiceFileLink)){
                    LGTN_eArkivInvoiceFile_WS eArkiv_File_ws= new LGTN_eArkivInvoiceFile_WS (invoiceNumber,Label.LGTN_eArkiv_Invoice_IntegrationName,true);
                    eArkiv_File_ws.setEndPoint(eArkiv_ws.eArkivInvoiceFileLink); 
                    eArkiv_File_ws.send(false);  
                    if(eArkiv_File_ws.callout.error == null) { 
                        contentDocumentId=eArkiv_File_ws.documentFileId; 
                    }
                    calloutlogsToUpsert.addAll(eArkiv_File_ws.callOutLogs);   
                }
            }
            if(!calloutlogsToUpsert.isEmpty())DataBase.upsert(calloutlogsToUpsert);
        }else{
            contentDocumentId=versions[0].ContentDocumentId;
        }
        return contentDocumentId;
    }
}


I HAVE TRIED THIS TEST CLASS AND GOT CODE CODE COVERAGE OF 71% BUT THE LINES WHICH I HAVE MARKED AS "BOLD" ARE NOT COVERING AND METHOD IS NOT PASSING.PLEASE HELP ME IN THIS.
TEST CLASS----
public class LGTN_eArkivInvoiceFiles_LCC_TEST {
    
    @isTest static void TestgetInvoiceContentDocument()
    {
        UTIL_TestFactory.setUpOrg();
        User tempUser4 = UTIL_TestFactory.createUserWithoutSetup('testsetupOrgUser'+DateTime.now().millisecond()+'@Test14.com','System Administrator');
        System.runAs(tempUser4){
            StaticResourceCalloutMock successfulMock = new StaticResourceCalloutMock();
            successfulMock.setStaticResource('TestInvoiceFiles');
            successfulMock.setStatusCode(200);
            successfulMock.setHeader('Content-Type', 'text/json');
            Test.startTest();
            Test.setMock(HttpCalloutMock.class, successfulMock); 
            LGTN_eArkivInvoiceFiles_LCC.getInvoiceContentDocument('Test');
            Test.stopTest();
            
        }
    }
}
Deviprasad Hegde 30Deviprasad Hegde 30
Could you please post the code for "StaticResourceCalloutMock" class ? Also does this class implement the "respond" method from HttpCalloutMock interface?