YHNetworkServiceTests.m 2.16 KB
//
//  YHNetworkServiceTests.m
//  YH_Analytics
//
//  Created by Zhou Rongjun on 15/4/28.
//  Copyright (c) 2015年 YOHO. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>

#import "YHNetworkService.h"

@interface YHNetworkService (XCTestCase)

@property (copy, nonatomic, readonly) YHNetworkReachabilityStatusBlock networkReachabilityStatusBlock;

@end

@interface YHNetworkServiceTests : XCTestCase {
@private
    id mock;
}

@end

@implementation YHNetworkServiceTests

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
    NSLog(@"%@ setUp", self.name);
    mock = OCMClassMock([YHNetworkService class]);
    XCTAssertNotNil(mock, @"Cannot create YHNetworkService mock");
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    mock = nil;
    [super tearDown];
    NSLog(@"%@ tearDown", self.name);
}

- (void)testSetReachabilityStatusChangeBlockMethod {
    NSLog(@"%@ start", self.name);
    
    OCMExpect([mock setReachabilityStatusChangeBlock:[OCMArg any]]);
    
    [mock setReachabilityStatusChangeBlock:[OCMArg any]];
    
    OCMVerifyAll(mock);
    
    NSLog(@"%@ end", self.name);
}

- (void)testUploadLogDataMethod {
    NSLog(@"%@ start", self.name);
    
    NSURLSessionDataTask *task = [NSURLSessionDataTask new];
    
    OCMExpect([mock uploadLogData:[OCMArg any] completionBlock:[OCMArg any]]).andReturn(operation);
    
    id returnValue = [mock uploadLogData:[OCMArg any] completionBlock:[OCMArg any]];
    
    OCMVerifyAll(mock);
    
    XCTAssertEqualObjects(task, returnValue);
    
    NSLog(@"%@ end", self.name);
}

- (void)testGetNewStrategyMethod {
    NSLog(@"%@ start", self.name);
    
    NSURLSessionDataTask *task = [NSURLSessionDataTask new];
    
    OCMExpect([mock getNewLogStrategy:[OCMArg any] completionBlock:[OCMArg any]]).andReturn(operation);
    
    id returnValue = [mock getNewLogStrategy:[OCMArg any] completionBlock:[OCMArg any]];
    
    OCMVerifyAll(mock);
    
    XCTAssertEqualObjects(task, returnValue);
    
    NSLog(@"%@ end", self.name);
}
@end