blob: 87420342ed9349a18aeadfb25a14e789fab006a4 (
plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
//---------------------------------------------------------------------------------------
// $Id: OCMockRecorderTests.m 50 2009-07-16 06:48:19Z erik $
// Copyright (c) 2004-2009 by Mulle Kybernetik. See License file for details.
//---------------------------------------------------------------------------------------
#import "OCMockRecorderTests.h"
#import <OCMock/OCMockRecorder.h>
#import "OCMReturnValueProvider.h"
#import "OCMExceptionReturnValueProvider.h"
@implementation OCMockRecorderTests
- (void)setUp
{
NSMethodSignature *signature;
signature = [NSString instanceMethodSignatureForSelector:@selector(initWithString:)];
testInvocation = [NSInvocation invocationWithMethodSignature:signature];
[testInvocation setSelector:@selector(initWithString:)];
}
- (void)testStoresAndMatchesInvocation
{
OCMockRecorder *recorder;
NSString *arg;
arg = @"I love mocks.";
[testInvocation setArgument:&arg atIndex:2];
recorder = [[[OCMockRecorder alloc] initWithSignatureResolver:[NSString string]] autorelease];
[(id)recorder initWithString:arg];
STAssertTrue([recorder matchesInvocation:testInvocation], @"Should match.");
}
- (void)testOnlyMatchesInvocationWithRightArguments
{
OCMockRecorder *recorder;
NSString *arg;
arg = @"I love mocks.";
[testInvocation setArgument:&arg atIndex:2];
recorder = [[[OCMockRecorder alloc] initWithSignatureResolver:[NSString string]] autorelease];
[(id)recorder initWithString:@"whatever"];
STAssertFalse([recorder matchesInvocation:testInvocation], @"Should not match.");
}
- (void)testAddsReturnValueProvider
{
OCMockRecorder *recorder;
NSArray *handlerList;
recorder = [[[OCMockRecorder alloc] initWithSignatureResolver:[NSString string]] autorelease];
[recorder andReturn:@"foo"];
handlerList = [recorder invocationHandlers];
STAssertEquals(1u, [handlerList count], @"Should have added one handler.");
STAssertEqualObjects([OCMReturnValueProvider class], [[handlerList objectAtIndex:0] class], @"Should have added correct handler.");
}
- (void)testAddsExceptionReturnValueProvider
{
OCMockRecorder *recorder;
NSArray *handlerList;
recorder = [[[OCMockRecorder alloc] initWithSignatureResolver:[NSString string]] autorelease];
[recorder andThrow:[NSException exceptionWithName:@"TestException" reason:@"A reason" userInfo:nil]];
handlerList = [recorder invocationHandlers];
STAssertEquals(1u, [handlerList count], @"Should have added one handler.");
STAssertEqualObjects([OCMExceptionReturnValueProvider class], [[handlerList objectAtIndex:0] class], @"Should have added correct handler.");
}
@end
|