+(NSString *) classMethod:(id)someDataObject
{
NSString *returnStr;
//do something with someDataObject and set returnStr
//...
returnStr = [NSString stringWithFormat:@"%@%@", returnStr,[self getCurrentTimestamp]];
return returnStr;
}
+ (NSString *)getCurrentTimestamp
{
NSNumber *t = [NSNumber numberWithLong:[[NSDate date] timeIntervalSince1970]];
return [t stringValue];
}
I am struggling to write test case for the classMethod because when I run OCUnit test and pass OCMock object to classMethod the output will be always different as I add timestamp. What is the best approach to stub class method - getCurrentTimestamp? Is it actually possible to stub class methods of the class that is being tested?
I tried like this, but it is not working:
id mock = [OCMockObject mockForClass:[MyClass class]];
[[[mock stub] andReturn:@1378468455] getCurrentTimestamp];
NSString *str = [MyClass classMethod:someMockObject];