[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / third_party / ocmock / OCMock / OCObserverMockObject.m
blob74be80da05640a5ba5770cefec7ae8ffae9417b4
1 //---------------------------------------------------------------------------------------
2 //  $Id$
3 //  Copyright (c) 2009 by Mulle Kybernetik. See License file for details.
4 //---------------------------------------------------------------------------------------
6 #import "OCObserverMockObject.h"
7 #import "OCMObserverRecorder.h"
10 @implementation OCObserverMockObject
12 #pragma mark  Initialisers, description, accessors, etc.
14 - (id)init
16         self = [super init];
17         recorders = [[NSMutableArray alloc] init];
18         return self;
21 - (void)dealloc
23         [recorders release];
24         [super dealloc];
27 - (NSString *)description
29         return @"OCMockObserver";
32 - (void)setExpectationOrderMatters:(BOOL)flag
34     expectationOrderMatters = flag;
38 #pragma mark  Public API
40 - (id)expect
42         OCMObserverRecorder *recorder = [[[OCMObserverRecorder alloc] init] autorelease];
43         [recorders addObject:recorder];
44         return recorder;
47 - (void)verify
49         if([recorders count] == 1)
50         {
51                 [NSException raise:NSInternalInconsistencyException format:@"%@: expected notification was not observed: %@", 
52                  [self description], [[recorders lastObject] description]];
53         }
54         if([recorders count] > 0)
55         {
56                 [NSException raise:NSInternalInconsistencyException format:@"%@ : %ld expected notifications were not observed.", 
57                  [self description], (unsigned long)[recorders count]];
58         }
63 #pragma mark  Receiving notifications
65 - (void)handleNotification:(NSNotification *)aNotification
67         NSUInteger i, limit;
68         
69         limit = expectationOrderMatters ? 1 : [recorders count];
70         for(i = 0; i < limit; i++)
71         {
72                 if([[recorders objectAtIndex:i] matchesNotification:aNotification])
73                 {
74                         [recorders removeObjectAtIndex:i];
75                         return;
76                 }
77         }
78         [NSException raise:NSInternalInconsistencyException format:@"%@: unexpected notification observed: %@", [self description], 
79           [aNotification description]];
83 @end