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
sumit dsumit d 

test class of prediction object

Hi All,
//Class use to parse image response
public without sharing class EinsteenPredictionService {

   public cls_probabilities[] probabilities;
    public Predictions__c pdt;    //predictresponse
    class cls_probabilities {
        public String label;    //nachos
        public Double probability;    //0.9994034
    }
    public static String getImagePrediction(String imageURL){
        String stringToParse = '{"probabilities":[{"label":"nachos","probability":0.9994034},{"label":"chips","probability":5.965742E-4}],"object":"predictresponse"}';
        parseImagePrediction(stringToParse);
        return stringToParse;
    }
    
    public static String parseImagePrediction(String imageURL){
        //return (EinsteenPredictionService) System.JSON.deserialize(imageURL, EinsteenPredictionService.class);
        String json=        '{"probabilities":[{"label":"nachos","probability":0.9994034},{"label":"chips","probability":5.965742E-4}],"object":"predictresponse"}';
        return json;
    }
    
}
how to write test class for this class.
Any suggestions?
v varaprasadv varaprasad
Hi Sumit,

Try below sample code once : 

 
@isTest
private class TestEinsteenPredictionService 
{
    public static void myUnitTest()
    {
	//Test Class for inner class..
	EinsteenPredictionService.cls_probabilities ein = new EinsteenPredictionService.cls_probabilities();
	 ein.label = 'nachos';
     ein.probability = 0.9994034;
	
    //Test Class for main class..
    EinsteenPredictionService et = new EinsteenPredictionService();
	string imageurl = 'www.google.com';	// Add your image urls here
	string resp2 = et.parseImagePrediction(imageurl);
	string resp1 = et.getImagePrediction(imageurl);
    }
}

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/

Salesforce latest interview questions  :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1

 
sumit dsumit d
Hi ,
 its showing this error:-System.JSONException: Unexpected character ('w' (code 119)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]