Simple Mock

@interface LibraryApiTests : FooTestCase
@property (nonatomic, strong) PlaybackStatus *mockStatus;

@interface CallMessageHandler()
- (NSDictionary *)constructMessage:(PlaybackStatus *)playbackStatus;

@implementation LibraryApiTests

- (void)setUp
    self.mockStatus = mock([PlaybackStatus class]);

- (void)testGetSavedPayload
    // given
    [given([self.mockStatus saved]) willReturnBool:YES];
    [given([self.mockStatus canSave]) willReturnInt:0];
    [given([self.mockStatus trackURI]) willReturn:[NSURL URLWithString:@""]];

    // when
    MessageHandler *handler = [[MessageHandler alloc] init];
    NSDictionary *payload = [handler constructMessage:self.mockStatus];

    // then
    XCTAssertEqual([payload[key1] intValue], 1);
    XCTAssertEqual([payload[key2] intValue], 0);
    XCTAssertEqual(payload[key3], @"");



 * The @c PlayerStateDelegate is used to get notifications.
@protocol PlayerStateDelegate <NSObject>

 * Called when the player state has been updated.
 * @param playerState The new player state.
- (void)playerStateDidChange:(id<PlayerState>)playerState;


 * The @c SPTAppRemotePlayerAPI is used to ...
@protocol SPTAppRemotePlayerAPI <NSObject>

/// The delegate receiving player state updates
@property (nonatomic, weak) id<PlayerStateDelegate> delegate;

- (void)play:(NSString *)entityIdentifier callback:(nullable RemoteCallback)callback;




[userAPI fetch:uri callback:^(id <SPTLibraryState> libraryState, 


p (BOOL)[libraryState isAdded];

Links that help

5 Comments (+add yours?)

  1. Jody
    Oct 10, 2012 @ 23:26:44

    Something that always bothered me about Apple’s APIs, or at least examples of their usage, is the messyness of implementation. Is it lack of OO design?

    i.e. The table view delegate from above implements the cellForRowAtIndex, and this one method is responsible for dequeueing or creating a cell (factory) as well as populating it (builder/strategy?)


    • JR
      Oct 11, 2012 @ 19:12:48

      I’ve heard arguments both ways.

      Some people I know love the API. They think it’s one of the most mature, stable platforms they’ve ever worked on.

      Others have thoughts similar to you. They think certain abstractions leak responsibility and are messy from an OO point-of-view.

      I personally like the API. But I would be the first to agree it isn’t perfect (the ALAssetLibrary I find particularly cumbersom).

      Thanks for the comment Jody.


  2. rob v
    Jan 03, 2013 @ 02:24:51

    some of your examples would be great to add into the code snippets library in the XCode inspector panel as user snippet, even if temporarily, until they become familiar. thanks for posting


  3. chandresh maurya
    Jun 11, 2014 @ 17:24:17

    how to use nsmutablearray to add multiple images in a single use of cell


  4. chandresh maurya
    Jun 11, 2014 @ 17:25:26

    how to use Ns mutable array to add multiple images in a single row of cell for ios


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: