This repository has been archived by the owner on May 19, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a simple mock object class which is currently best suited for m…
…ocking value objects.
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// RXMockObject.h | ||
// Created by Rob Rix on 2010-03-20 | ||
// Copyright 2010 Monochrome Industries | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface RXMockObject : NSObject { | ||
NSMutableDictionary *responses; | ||
} | ||
|
||
+(RXMockObject *)mockObject; | ||
+(RXMockObject *)mockObjectRespondingToSelector:(SEL)selector withObject:(id)response; | ||
|
||
-(void)respondToSelector:(SEL)selector withObject:(id)response; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// RXMockObject.m | ||
// Created by Rob Rix on 2010-03-20 | ||
// Copyright 2010 Monochrome Industries | ||
|
||
#import "RXMockObject.h" | ||
|
||
@implementation RXMockObject | ||
|
||
+(RXMockObject *)mockObject { | ||
return [[[self alloc] init] autorelease]; | ||
} | ||
|
||
+(RXMockObject *)mockObjectRespondingToSelector:(SEL)selector withObject:(id)response { | ||
RXMockObject *object = [[[self alloc] init] autorelease]; | ||
[object respondToSelector: selector withObject: response]; | ||
return object; | ||
} | ||
|
||
|
||
-(id)init { | ||
if(self = [super init]) { | ||
responses = [[NSMutableDictionary alloc] init]; | ||
} | ||
return self; | ||
} | ||
|
||
-(void)dealloc { | ||
[responses release]; | ||
[super dealloc]; | ||
} | ||
|
||
|
||
-(void)respondToSelector:(SEL)selector withObject:(id)response { | ||
[responses setObject: response forKey: NSStringFromSelector(selector)]; | ||
} | ||
|
||
|
||
-(id)responseForSelector:(SEL)selector { | ||
return [responses objectForKey: NSStringFromSelector(selector)]; | ||
} | ||
|
||
|
||
-(NSMethodSignature *)methodSignatureForSelector:(SEL)selector { | ||
NSMethodSignature *signature = nil; | ||
if([self responseForSelector: selector]) { | ||
signature = [super methodSignatureForSelector: @selector(self)]; | ||
} | ||
return signature; | ||
} | ||
|
||
-(void)forwardInvocation:(NSInvocation *)invocation { | ||
id response = [self responseForSelector: invocation.selector]; | ||
[invocation setReturnValue: &response]; | ||
} | ||
|
||
@end |