This is my rest api class,in this class need to write mock test class
global class Searchaddress {
@RemoteAction
global static list<String> restapi(string accName){
string jsonStr;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setHeader('Accept','application/JSON');
req.setEndpoint('http://api-adresse.data.gouv.fr/search/?q='+ EncodingUtil.urlEncode(accName,'UTF-8'));//+'&'+'limit'+'='+'10');//
req.setMethod('GET');
HttpResponse res = h.send(req);
// List<String> calOut = new List<String>();
// jsonStr= res.getBody();
system.debug('res1===>'+res.getBody());
// JSONParser parser = JSON.createParser(jsonStr);
List<String> calOut1 = new List<String>();
JSON2Apex parsed = JSON2Apex.parse(res.getBody());
for (JSON2Apex.Features f : parsed.Features)
{
JSON2Apex.Properties p = f.Properties ;
// calOut1.add(p.label+ ', ' + p.context+ ',' + p.city+ ', ' + p.postcode);
calOut1.add(p.label+' '+'FRANCE');
}
return calOut1;
}
}
This is my mock test class:
@isTest
private class Rfleet_CalloutClassTest {
@isTest static void testCallout() {
Test.setMock(HttpCalloutMock.class, new Rfleet_MockHttpResponseGenerator());
HttpResponse res = Searchaddress.restapi('france');
// Verify response received contains fake values
String contentType = res.getHeader('Content-Type');
System.assert(contentType == 'application/json');
String actualValue = res.getBody();
String expectedValue = '{"foo":"bar"}';
System.assertEquals(actualValue, expectedValue);
System.assertEquals(200, res.getStatusCode());
}
}
I am getting error "Error: Compile Error: Illegal assignment from List to System.HttpResponse at line 7 column 23" how to resolve this error?