I want to test a method which makes URL request. When response is received in NSURLConnectionDelegate
method I save the response. The logic I really want to test is whether response was saved or not.
How to test NSURLConnectionDelegate
method?
Method I want to test :
- (void) getProfilePictureURL :(NSString *)fbId
{
//to get picture URL
NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", fbId];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (!connection)
{
NSLog(@"error while starting the connection");
}
}
// NSURLConnectionDelegate method
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
// Save response in user defaults
}