Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7527473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:06:54+00:00 2026-05-30T04:06:54+00:00

I have a Mac application, an NSStatusItem really, in which I’m trying to test

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:06:55+00:00Added an answer on May 30, 2026 at 4:06 am

    It’s not clear from your code how you expect the windowController to point to mockWindowController. Have you implemented the category initializer and invokeSupersequent code as in Matt Gallagher’s post?

    It appears from your code that windowController is a property of your weathervane class. I think the simplest approach would be to eschew trying to override NSWindowController‘s initialization and just pass your mock into your controller:

    -(void)testPreferencesInit {    
        mockWindowController = [OCMockObject mockForClass:[NSWindowController class]];
        id mockWindow = [OCMockObject mockForClass:[NSWindow class]];
    
        [[[mockWindowController expect] andReturn:mockWindow] window];
        [[mockWindow expect] makeKeyAndOrderFront:weathervane];
    
        weathervane.windowController = mockWindowController;
    
        [weathervane showPreferences:nil];
    
        [mockWindowController verify];
        [mockWindow verify];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively simple application which I need to make native Mac OSX
I have 3rd party libraries for my mac applications which used to link nicely
I have been trying to make my Mac application enter fullscreen now for a
I have a java desktop application for which I am trying to create a
I have this Mac application that consists of 2 files: firstFile.tst secondFile I would
I have a Mac window based application using CoreData and Cocoa bindings to bind
I am creating a Mac application in which I have mainwindow with some buttons.
I have a little Mac application which should be able to post Data to
Perhaps I'm going crazy here, but I have a desktop mac application which, in
In my mac application I'm currently developing, I have an iKImageBrowserView which displays something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.