Objective-J Test API 0.1.0
|
00001 @import <Foundation/CPObject.j> 00002 @import "CPArray+Find.j" 00003 @import "CPArray+DeepEqual.j" 00004 00005 @implementation OJMoqSelector : CPObject 00006 { 00007 CPString name @accessors(readonly); 00008 CPNumber timesCalled @accessors(readonly); 00009 id returnValue @accessors; 00010 CPArray arguments @accessors; 00011 Function callback @accessors; 00012 } 00013 00014 + (CPArray)find:(OJMoqSelector)aSelector in:(CPArray)selectors ignoreWildcards:(BOOL)shouldIgnoreWildcards 00015 { 00016 return [selectors findBy:function(anotherSelector) 00017 { 00018 if(!shouldIgnoreWildcards && ([anotherSelector matchesAllArgs] || [aSelector matchesAllArgs])) 00019 { 00020 return [aSelector isEqualToNameOf:anotherSelector] 00021 } 00022 else 00023 { 00024 return [aSelector equals:anotherSelector]; 00025 } 00026 }]; 00027 } 00028 00029 + (CPArray)find:(OJMoqSelector)aSelector in:(CPArray)selectors 00030 { 00031 return [self find:aSelector in:selectors ignoreWildcards:NO]; 00032 } 00033 00034 - (id)initWithName:(CPString)aName withArguments:(CPArray)someArguments 00035 { 00036 if(self = [super init]) 00037 { 00038 name = aName; 00039 arguments = someArguments; 00040 timesCalled = 0; 00041 returnValue = undefined; 00042 callback = undefined; 00043 } 00044 return self; 00045 } 00046 00047 - (void)call 00048 { 00049 timesCalled = timesCalled + 1; 00050 } 00051 00052 - (BOOL)isEqualToNameOf:(OJMoqSelector)anotherSelector 00053 { 00054 return name === [anotherSelector name]; 00055 } 00056 00057 - (BOOL)equals:(OJMoqSelector)anotherSelector 00058 { 00059 return [self isEqualToNameOf:anotherSelector] && [arguments deepEqual:[anotherSelector arguments]]; 00060 } 00061 00062 - (BOOL)matchesAllArgs 00063 { 00064 return [arguments count] === 0; 00065 } 00066 00067 - (CPComparisonResult)compareTimesCalled:(CPNumber)anotherNumber 00068 { 00069 return [timesCalled compare:anotherNumber]; 00070 } 00071 00072 @end