I have a Mac application, an NSStatusItem really, in which I’m trying to test its preferences window.
I used this code as a model since it works much like my code except that my window is initialized and display in a function other than applicationDidFinishLaunching.
http://bit.ly/wH6QOk
I get the error:
Expected method not invoked: window
I can’t figure out why this happens. Here is my test code:
-(void)testPreferencesInit {
mockWindowController = [OCMockObject mockForClass:[NSWindowController class]];
id mockWindow = [OCMockObject mockForClass:[NSWindow class]];
[[[mockWindowController expect] andReturn:mockWindow] window];
[[mockWindow expect] makeKeyAndOrderFront:weathervane];
[weathervane showPreferences:nil];
[mockWindowController verify];
[mockWindow verify];
id windowController;
object_getInstanceVariable(weathervane, "windowController", (void **)&windowController);
GHAssertEqualObjects(windowController, mockWindowController,
@"windowController not set on appDelegate");
GHAssertTrue([[windowController windowNibName] isEqualToString:@"Preferences"], @"Window Controller nib name not set");
object_setInstanceVariable(weathervane, "windowController", nil);
mockWindowController = nil;
}
It’s not clear from your code how you expect the
windowControllerto point tomockWindowController. Have you implemented the category initializer andinvokeSupersequentcode as in Matt Gallagher’s post?It appears from your code that
windowControlleris a property of your weathervane class. I think the simplest approach would be to eschew trying to overrideNSWindowController‘s initialization and just pass your mock into your controller: