1 //---------------------------------------------------------------------------------------
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.
17 recorders = [[NSMutableArray alloc] init];
27 - (NSString *)description
29 return @"OCMockObserver";
32 - (void)setExpectationOrderMatters:(BOOL)flag
34 expectationOrderMatters = flag;
38 #pragma mark Public API
42 OCMObserverRecorder *recorder = [[[OCMObserverRecorder alloc] init] autorelease];
43 [recorders addObject:recorder];
49 if([recorders count] == 1)
51 [NSException raise:NSInternalInconsistencyException format:@"%@: expected notification was not observed: %@",
52 [self description], [[recorders lastObject] description]];
54 if([recorders count] > 0)
56 [NSException raise:NSInternalInconsistencyException format:@"%@ : %ld expected notifications were not observed.",
57 [self description], (unsigned long)[recorders count]];
63 #pragma mark Receiving notifications
65 - (void)handleNotification:(NSNotification *)aNotification
69 limit = expectationOrderMatters ? 1 : [recorders count];
70 for(i = 0; i < limit; i++)
72 if([[recorders objectAtIndex:i] matchesNotification:aNotification])
74 [recorders removeObjectAtIndex:i];
78 [NSException raise:NSInternalInconsistencyException format:@"%@: unexpected notification observed: %@", [self description],
79 [aNotification description]];