Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: third_party/ocmock/OCMock/OCObserverMockObjectTest.m

Issue 9240023: Roll OCMock r77:7f521db0628086185123666b0979e48d6ecaeac1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 //------------------------------------------------------------------------------ ---------
2 // $Id: OCObserverMockObjectTest.m 57 2010-07-19 06:14:27Z erik $
3 // Copyright (c) 2009 by Mulle Kybernetik. See License file for details.
4 //------------------------------------------------------------------------------ ---------
5
6 #import <OCMock/OCMock.h>
7 #import "OCObserverMockObjectTest.h"
8
9 static NSString *TestNotificationOne = @"TestNotificationOne";
10
11
12 @implementation OCObserverMockObjectTest
13
14 - (void)setUp
15 {
16 center = [[[NSNotificationCenter alloc] init] autorelease];
17 mock = [OCMockObject observerMock];
18 }
19
20 - (void)testAcceptsExpectedNotification
21 {
22 [center addMockObserver:mock name:TestNotificationOne object:nil];
23 [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]] ;
24
25 [center postNotificationName:TestNotificationOne object:self];
26
27 [mock verify];
28 }
29
30 - (void)testAcceptsExpectedNotificationWithSpecifiedObjectAndUserInfo
31 {
32 [center addMockObserver:mock name:TestNotificationOne object:nil];
33 NSDictionary *info = [NSDictionary dictionaryWithObject:@"foo" forKey:@" key"];
34 [[mock expect] notificationWithName:TestNotificationOne object:self userInfo :info];
35
36 [center postNotificationName:TestNotificationOne object:self userInfo:info];
37
38 [mock verify];
39 }
40
41 - (void)testAcceptsNotificationsInAnyOrder
42 {
43 [center addMockObserver:mock name:TestNotificationOne object:nil];
44 [[mock expect] notificationWithName:TestNotificationOne object:self];
45 [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]] ;
46
47 [center postNotificationName:TestNotificationOne object:[NSString string ]];
48 [center postNotificationName:TestNotificationOne object:self];
49 }
50
51 - (void)testAcceptsNotificationsInCorrectOrderWhenOrderMatters
52 {
53 [mock setExpectationOrderMatters:YES];
54
55 [center addMockObserver:mock name:TestNotificationOne object:nil];
56 [[mock expect] notificationWithName:TestNotificationOne object:self];
57 [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]] ;
58
59 [center postNotificationName:TestNotificationOne object:self];
60 [center postNotificationName:TestNotificationOne object:[NSString string ]];
61 }
62
63 - (void)testRaisesExceptionWhenSequenceIsWrongAndOrderMatters
64 {
65 [mock setExpectationOrderMatters:YES];
66
67 [center addMockObserver:mock name:TestNotificationOne object:nil];
68 [[mock expect] notificationWithName:TestNotificationOne object:self];
69 [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]] ;
70
71 STAssertThrows([center postNotificationName:TestNotificationOne object:[ NSString string]], @"Should have complained about sequence.");
72 }
73
74 - (void)testRaisesEvenThoughOverlappingExpectationsCouldHaveBeenSatisfied
75 {
76 // this test demonstrates a shortcoming, not a feature
77 [center addMockObserver:mock name:TestNotificationOne object:nil];
78 [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]] ;
79 [[mock expect] notificationWithName:TestNotificationOne object:self];
80
81 [center postNotificationName:TestNotificationOne object:self];
82 STAssertThrows([center postNotificationName:TestNotificationOne object:[ NSString string]], nil);
83 }
84
85 - (void)testRaisesExceptionWhenUnexpectedNotificationIsReceived
86 {
87 [center addMockObserver:mock name:TestNotificationOne object:nil];
88
89 STAssertThrows([center postNotificationName:TestNotificationOne object:self] , nil);
90 }
91
92 - (void)testRaisesWhenNotificationWithWrongObjectIsReceived
93 {
94 [center addMockObserver:mock name:TestNotificationOne object:nil];
95 [[mock expect] notificationWithName:TestNotificationOne object:self];
96
97 STAssertThrows([center postNotificationName:TestNotificationOne object:[ NSString string]], nil);
98 }
99
100 - (void)testRaisesWhenNotificationWithWrongUserInfoIsReceived
101 {
102 [center addMockObserver:mock name:TestNotificationOne object:nil];
103 [[mock expect] notificationWithName:TestNotificationOne object:self
104 userInfo:[NSDictionar y dictionaryWithObject:@"foo" forKey:@"key"]];
105 STAssertThrows([center postNotificationName:TestNotificationOne object:[ NSString string]
106 userI nfo:[NSDictionary dictionaryWithObject:@"bar" forKey:@"key"]], nil);
107 }
108
109 - (void)testRaisesOnVerifyWhenExpectedNotificationIsNotSent
110 {
111 [center addMockObserver:mock name:TestNotificationOne object:nil];
112 [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]] ;
113
114 STAssertThrows([mock verify], nil);
115 }
116
117 - (void)testRaisesOnVerifyWhenNotAllNotificationsWereSent
118 {
119 [center addMockObserver:mock name:TestNotificationOne object:nil];
120 [[mock expect] notificationWithName:TestNotificationOne object:[OCMArg any]] ;
121 [[mock expect] notificationWithName:TestNotificationOne object:self];
122
123 [center postNotificationName:TestNotificationOne object:self];
124 STAssertThrows([mock verify], nil);
125 }
126
127 @end
OLDNEW
« no previous file with comments | « third_party/ocmock/OCMock/OCObserverMockObjectTest.h ('k') | third_party/ocmock/OCMock/OCPartialMockObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698