OLD | NEW |
| (Empty) |
1 //------------------------------------------------------------------------------
--------- | |
2 // $Id: OCMockRecorderTests.m 61 2010-07-21 02:38:57Z erik $ | |
3 // Copyright (c) 2004-2009 by Mulle Kybernetik. See License file for details. | |
4 //------------------------------------------------------------------------------
--------- | |
5 | |
6 #import "OCMockRecorderTests.h" | |
7 #import <OCMock/OCMockRecorder.h> | |
8 #import "OCMReturnValueProvider.h" | |
9 #import "OCMExceptionReturnValueProvider.h" | |
10 | |
11 | |
12 @implementation OCMockRecorderTests | |
13 | |
14 - (void)setUp | |
15 { | |
16 NSMethodSignature *signature; | |
17 | |
18 signature = [NSString instanceMethodSignatureForSelector:@selector(initW
ithString:)]; | |
19 testInvocation = [NSInvocation invocationWithMethodSignature:signature]; | |
20 [testInvocation setSelector:@selector(initWithString:)]; | |
21 } | |
22 | |
23 | |
24 - (void)testStoresAndMatchesInvocation | |
25 { | |
26 OCMockRecorder *recorder; | |
27 NSString *arg; | |
28 | |
29 arg = @"I love mocks."; | |
30 [testInvocation setArgument:&arg atIndex:2]; | |
31 | |
32 recorder = [[[OCMockRecorder alloc] initWithSignatureResolver:[NSString
string]] autorelease]; | |
33 [(id)recorder initWithString:arg]; | |
34 | |
35 STAssertTrue([recorder matchesInvocation:testInvocation], @"Should match
."); | |
36 } | |
37 | |
38 | |
39 - (void)testOnlyMatchesInvocationWithRightArguments | |
40 { | |
41 OCMockRecorder *recorder; | |
42 NSString *arg; | |
43 | |
44 arg = @"I love mocks."; | |
45 [testInvocation setArgument:&arg atIndex:2]; | |
46 | |
47 recorder = [[[OCMockRecorder alloc] initWithSignatureResolver:[NSString
string]] autorelease]; | |
48 [(id)recorder initWithString:@"whatever"]; | |
49 | |
50 STAssertFalse([recorder matchesInvocation:testInvocation], @"Should not
match."); | |
51 } | |
52 | |
53 | |
54 - (void)testAddsReturnValueProvider | |
55 { | |
56 OCMockRecorder *recorder; | |
57 NSArray *handlerList; | |
58 | |
59 recorder = [[[OCMockRecorder alloc] initWithSignatureResolver:[NSString
string]] autorelease]; | |
60 [recorder andReturn:@"foo"]; | |
61 handlerList = [recorder invocationHandlers]; | |
62 | |
63 STAssertEquals((NSUInteger)1, [handlerList count], @"Should have added o
ne handler."); | |
64 STAssertEqualObjects([OCMReturnValueProvider class], [[handlerList objec
tAtIndex:0] class], @"Should have added correct handler."); | |
65 } | |
66 | |
67 - (void)testAddsExceptionReturnValueProvider | |
68 { | |
69 OCMockRecorder *recorder; | |
70 NSArray *handlerList; | |
71 | |
72 recorder = [[[OCMockRecorder alloc] initWithSignatureResolver:[NSString
string]] autorelease]; | |
73 [recorder andThrow:[NSException exceptionWithName:@"TestException" reaso
n:@"A reason" userInfo:nil]]; | |
74 handlerList = [recorder invocationHandlers]; | |
75 | |
76 STAssertEquals((NSUInteger)1, [handlerList count], @"Should have added o
ne handler."); | |
77 STAssertEqualObjects([OCMExceptionReturnValueProvider class], [[handlerL
ist objectAtIndex:0] class], @"Should have added correct handler."); | |
78 | |
79 } | |
80 | |
81 @end | |
OLD | NEW |