Stubbing the protocol return as Nil
AyeChanPyaeSone opened this issue · 3 comments
I've tried to stub the protocol method but it return as nil. Please check the following code.
@protocol Client
- (Account* _Nullable) login:(nullable NSString*)username
password:(nonnull NSData*)login;
And I have a object called ClientImplementation that implements Client protocol.
In my testcase, I mock the class like this in setup().
@property(nonatomic, strong) ClientImplementation<Client> *mockClient;
self.mockClient = mockObjectAndProtocol([ClientImplementation class],@protocol(Client));
But when i Stub the method it return as nil.
Account *account = [[Account alloc]init];
account.name = @"fdsafdsfs";
[given([self.mockClient login:@""passwrod:anything()]) willReturn:account];
May I know what did i do wrong?
I'm sorry you've waited so long for an answer — I don't seem to be receiving any notifications from GitHub.
For all mocked methods, nil
is returned unless the given
condition is met. My guess is that there's something about your given
that doesn't match what your code calls. You are using anything()
to match any password
argument, so that's fine. Is the code passing empty string for login
?
I just wanted to mention that I've had the same problem when the matched-against or returned objects are typedefs. Might give a clue about what's going on?
Thank you, @jasongrlicky. If you get a chance and are able to boil it down to an executable example, that would be really helpful.