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
Mahesh Tandan 6Mahesh Tandan 6 

test captcha

Hii developers.
I'm using google v2 captcha on my vf extensions class
Now problem is I'm not able to test the captcha

this is the extension coce
public class addContactExtension {

    @TestVisible private static String baseUrl = 'https://www.google.com/recaptcha/api/siteverify';//captcha API endpoint.
    @TestVisible private static String secret = '6LcaHdMAEqDE4TTL****';//captcha API secret key.

    public String sitekey { //Captcha site key
        get {
            return '6LcaHdMUAAAAAKNwNDoR0RD8SXffM3JlwBSGKy6p';//Here, use my site key.
        }set;
	}
    
    public String response  {
        get {
            return ApexPages.currentPage().getParameters().get('g-recaptcha-response');
        }set;
    }
    
   Public pageReference paymentSave(){

        String responseBody = makeRequest(baseUrl,'secret=' + secret +'&response='+ response);
        String success = getValueFromJson(responseBody, 'success');
        if(success.equalsIgnoreCase('true')) {
           //execute code.
         }
}

TestVisible private static String makeRequest(string url, string body) { //Captcha api request start here
        HttpResponse response = null;
        HttpRequest req = new HttpRequest();
        req.setEndpoint(url);
        req.setMethod('POST');
        req.setBody (body);
        try{
            Http http = new Http();
            response = http.send(req);
            return response.getBody();
        }catch(System.Exception e) {
            //System.debug('ERROR: ' + e);
        }
        return '{"success":false}';
    }//Captcha api request Ends here


    public static string getValueFromJson ( String strJson, String field ) {
        JSONParser parser = JSON.createParser(strJson);
        while (parser.nextToken() != null){
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)) {
                if(parser.getText() == field){
                    // Get the value.
                    parser.nextToken();
                    return parser.getText();
                }
            }
        }
        return null;
    }

}
How to test this method .
Somebody please help