ddribin (owner)

Revisions

gist: 199758 Download_button fork
public
Public Clone URL: git://gist.github.com/199758.git
Embed All Files: show embed
Objective-C #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@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