How to use OCMock to return different result base on different argument -


i trying mock different method return when passing different argument same method.

self.mymock = [ocmockobject mockforclass:[myclass class]]; [[[self.mymock expect] andreturnvalue:5] mystaticmethod:3]; [[[self.mymock expect] andreturnvalue:10] mystaticmethod:6]; 

but takes first one, when argument 3 return 5, , when argument 6, return nil instead of 10. know whether way test this?

the real code:

-(nsmutablearray*)convertchildstringtochilddic:(nsstring*)strchildren {     nsarray *kididarray = [strchildren componentsseparatedbystring:@","];     //处理小孩信息     /*children =             (      {      avatarsmall = "<null>";      currentstatus = 0;      displayname = stu1;      "id_str" = "70938032-3811-e411-946a-005056c00008";      title = child;      }      )*/     nsmutablearray *rstchildarray = [nsmutablearray arraywithcapacity:1];     (nsstring *enrollment_id in kididarray) {         if (enrollment_id.length <= 0) {             continue;         }         **nsmutabledictionary *mdic = [[roominfomanager sharedmanager] getkiddictionarybyid:enrollment_id];**          [mdic setvalue:enrollment_id forkey:@"id_str"];         if (mdic != nil) {             [rstchildarray addobject:mdic];         }     }     return rstchildarray; } 

test:

-(void) testconvertchildstringtochilddic_invalidagruments {     nsmutabledictionary *childdic = [[nsmutabledictionary alloc] init];     childdic[@"id"] = @"josh";      nsmutabledictionary *childdic1 = [[nsmutabledictionary alloc] init];     childdic1[@"id"] = @"joy";       id mockrim = ocmclassmock([roominfomanager class]);     **ocmstub([mockrim getkiddictionarybyid:@"josh"]).andreturn(childdic);     **ocmstub([mockrim getkiddictionarybyid:@"joy"]).andreturn(childdic1);****       roominfomanager *roominfomgr = [roominfomanager alloc];     id mockpartialrim = ocmpartialmock(roominfomgr);      ocmexpect([mockpartialrim sharedmanager]).andreturn(mockrim); // use expect      nsstring *childstr = @"josh,joy";     nsmutablearray *childarray = [[reportoperator alloc] convertchildstringtochilddic:childstr];      nsdictionary *childrenarraydic = @{@"id" : @"josh", @"id_str": @"josh"};     nsmutablearray *resultarray = [nsmutablearray arraywithobjects:childrenarraydic, nil];      [mockpartialrim verify]; // verify expect,验证该对像是否被调用。      xctassertequalobjects(childarray, resultarray); } 

the second call

ocmstub([mockrim getkiddictionarybyid:@"joy"]).andreturn(childdic1); 

does not seem take effect , return nil instead.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -