Here is an example of how to remove a dependency and only pass in what you need. Avoids mocking Notification. Instead just extract value.

+ (CGFloat)constraintForKeyboardWithHeight:(CGFloat)keyboardHeight
                                viewHeight:(CGFloat)viewHeight
                               imageHeight:(CGFloat)imageHeight
                               labelHeight:(CGFloat)labelHeight;
{
    if( IS_IPHONE_5 || IS_IPAD )
    {
        navigationBarHeightPortrait = 64;
    }

    CGFloat errorMesageHeight = [self errorMessageHeightForImageHeight:imageHeight labelHeight:labelHeight];
    CGFloat topConstraintHeightPortrait = (viewHeight - keyboardHeight - errorMesageHeight - navigationBarHeightPortrait - bottomMessaageBarHeight)/2;

    // We are currently ignoring device orientation and only returning portrait
    return topConstraintHeightPortrait;
}

#pragma mark Private

+ (CGFloat)keyboardHeightForNotification:(NSNotification *)notification
{
    NSDictionary *userInfo = [notification userInfo];
    NSValue *keyboardFrameBegin = [userInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
    CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];
    CGFloat keyboardHeight = keyboardFrameBeginRect.size.height;
    return keyboardHeight;
}
Advertisements