Created
October 2, 2009 13:50
-
-
Save ddribin/199758 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@interface AClassThatUsesNSWorkspace : NSObject | |
{ | |
NSWorkspace * _workspace; | |
} | |
// Production code uses this | |
- (id)init; | |
// Useful for testing (to inject a mock NSWorkspace) | |
- (id)initWithWorkspace:(NSWorkspace *)workspace; | |
- (void)openFile; | |
@end | |
@implementation AClassThatUsesNSWorkspace | |
- (id)init | |
{ | |
return [self initWithWorkspace:[NSWorkspace sharedWorkspace]]; | |
} | |
- (id)initWithWorkspace:(NSWorkspace *)workspace | |
{ | |
self = [super init]; | |
if (self == nil) | |
return nil; | |
_workspace = [workspace retain]; | |
return self; | |
} | |
- (void)dealloc | |
{ | |
[_workspace release]; | |
[super dealloc]; | |
} | |
- (void)openFile | |
{ | |
[_workspace openFile:@"file" withApplication:@"app" andDeactivate:YES]; | |
} | |
@end | |
@interface AClassThatUsesNSWorkspaceTest : SenTestCase | |
@end | |
@implementation AClassThatUsesNSWorkspaceTest | |
- (void)testOpenFile | |
{ | |
id mockWorkspace = [OCMockObject mockForClass:[NSWorkspace class]]; | |
AClassThatUsesNSWorkspace * sut = [[[AClassThatUsesNSWorkspace alloc] initWithWorkspace:mockWorkspace] autorelease]; | |
[[mockWorkspace expect] openFile:@"file" withApplication:@"app" andDeactivate:YES]; | |
[sut openFile]; | |
[mockWorkspace verify]; | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment