I am trying to learn unit testing with ocmock. I am finding it difficult to mock calls of another class from a class which i am unit testing.
Can some one suggest how to make mock call to KeyChainUtils class and HttpRequest class:
Code to unit test with OCMock:
@implementation UserProfileService {
+(BOOL) isValidUser
{
NSString* userId = [KeyChainUtil loadValueForKey:USER_ID]; //mock this call
bool isValidUser = NO;
if(userId && userId.length > 0){
NSDictionary* response = [HTTPDataService getJSONForURL:@"http://xtest.com/checkuserid" forRequestData:@{@"userid": userId}];
if(response && response[@"valid"]){
isValidUser = [response[@"valid"] boolValue];
}else{
NSLog(@"error in connecting to server. response => %@", response);
}
}
return isValidUser;
}
}