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
Akshay MhetreAkshay Mhetre 

test class ( Confused in string and Integer parameter)

Main Class:::

public without sharing class Geotag {
    @AuraEnabled
    
    public static void updateFiles(String contentVersionIds, String Latitude, String Longitude) 
    {
        String[] contentVersionIdArr =     contentVersionIds.split(',');

        Set<String> contentDocumentIds = new Set<String>();

        for(String docId : contentVersionIdArr)
        {
            if(docId != null && docId.length() > 0)
                contentDocumentIds.add(docId);
        }

        List<ContentVersion> versionList = [SELECT FileExtension, Title FROM ContentVersion 
                                            WHERE ContentDocumentId IN :contentDocumentIds and IsLatest=true ] ;

        List<ContentVersion> contentVersionsToUpdate = new List<ContentVersion>();

        for(ContentVersion contVersion : versionList)
        {
            contVersion.Latitude__c = Decimal.valueOf(Latitude);
            contVersion.Longitude__c = Decimal.valueOf(Longitude);
        }

        update versionList;
    }
    @AuraEnabled(cacheable=true)
    public static Case getLatLong(String recordId){
        return [select Id,Latitude__c,Longitude__c from Case where Id=:recordId];
    }
}

\\\\\\\\\\\\\\\\\\\\\\My test class with 82% coverage////////////////////I need 85%

@isTest
public class GeotagTest {
   @isTest
    public static void updatefilestest(){
        
       // List<ContentVersion> cvlist = new List<ContentVersion>();
        
       // string[] idval = new string
        
        ContentVersion cv = new ContentVersion();
        cv.Title = 'Test Document';
        cv.PathOnClient = 'TestDocument.pdf';
        cv.VersionData = Blob.valueOf('Test Content');
        cv.IsMajorVersion = true;
        cv.Latitude__c = 23;
        cv.Longitude__c = 22;
        Insert cv;
        
        ContentVersion cv1 = new ContentVersion();
        cv1.Title = 'Test Document';
        cv1.PathOnClient = 'TestDocument.pdf';
        cv1.VersionData = Blob.valueOf('Test Content');
        cv1.IsMajorVersion = true;
        cv1.Latitude__c = 23;
        cv1.Longitude__c = 22;
        Insert cv1;
        
       // cvlist.add(cv);
        //cvlist.add(cv1);
        
      //  insert cvlist;
        
        
        Test.startTest();
        Geotag.updatefiles(cv.Id,'23','26');
        Test.stopTest();
    }
    @isTest
    public static void getlatlongtest(){
        
        Case c1 = new Case();
        c1.Address_Type__c = 'RESIDENCE ADDRESS';
        c1.AddressLine1__c = 'line1';
        c1.AddressLine2__c = 'line2';
        c1.AddressLine3__c = 'line3';
        c1.Agency_Name__c = 'agen1';
        insert c1;
        
        Test.startTest();
         Geotag.getlatlong(c1.Id);
        Test.stopTest();
    }
    
}

 

Best Answer chosen by Akshay Mhetre
Suraj Tripathi 47Suraj Tripathi 47
Hi Akshay,

This test class with 100% coverage. You can take reference from this below code.
@istest
public class GeotagTest {
    @isTest
    public static void updatefilestest(){
        Case c1 = new Case();
        c1.Latitude__c = 34;
        c1.Longitude__c = 345;
        insert c1;
        
        ContentVersion cv = new ContentVersion();
        cv.Title = 'Test Document';
        cv.PathOnClient = 'TestDocument.pdf';
        cv.VersionData = Blob.valueOf('Test Content');
        cv.IsMajorVersion = true;
        cv.Latitude__c = 23;
        cv.Longitude__c = 22;
        Insert cv;
        
        ContentVersion contentVersion_2 = [SELECT Id, Title, ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id LIMIT 1];
        
        ContentDocumentLink contentlink = new ContentDocumentLink();
        contentlink.contentdocumentid = contentVersion_2.contentdocumentid;
        contentlink.LinkedEntityId = c1.Id;
        insert contentlink; 
        
        Test.startTest();
        Geotag.updatefiles(contentVersion_2.contentdocumentid,'23','26');
        Geotag.getlatlong(c1.Id);
        Test.stopTest();
    }
    
}

In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 

Thanks and Regards
Suraj Tripathi.