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

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

#import "YHAssemblyAssistant.h"
#import "YHDevice.h"
#import "YHStatus.h"

@interface YHAssemblyAssistant (XCTestCase)

@property (strong, nonatomic, readonly) YHDevice *device;
@property (strong, nonatomic, readonly) YHStatus *currentStatus;
@property (strong, nonatomic, readonly) NSMutableDictionary *immediUploadItemDic;

@end

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

@end

@implementation YHAssemblyAssistantTests

- (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([YHAssemblyAssistant class]);
    XCTAssertNotNil(mock, @"Cannot create YHAssemblyAssistant 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);
}

#pragma mark - self property

- (void)testDeviceNotNil {
    NSLog(@"%@ start", self.name);
    
    YHAssemblyAssistant *assistant = [[YHAssemblyAssistant alloc] init];
    YHDevice *device = [assistant device];
    XCTAssertNotNil(device, @"YHAssemblyAssistant device can't be nil.");
    
    NSLog(@"%@ end", self.name);
}

- (void)testCurrentStatusNotNil {
    NSLog(@"%@ start", self.name);
    
    YHAssemblyAssistant *assistant = [[YHAssemblyAssistant alloc] init];
    YHStatus *status = [assistant currentStatus];
    XCTAssertNotNil(status, @"YHAssemblyAssistant status can't be nil.");
    
    NSLog(@"%@ end", self.name);
}

- (void)testImmediUploadItemDicNotNil {
    NSLog(@"%@ start", self.name);
    
    YHAssemblyAssistant *assistant = [[YHAssemblyAssistant alloc] init];
    NSMutableDictionary *itemDic = [assistant immediUploadItemDic];
    XCTAssertNotNil(itemDic, @"YHAssemblyAssistant immediUploadItemDic can't be nil.");
    
    NSLog(@"%@ end", self.name);
}

#pragma mark - 方法存在性验证

- (void)testCanPersistingMethod {
    NSLog(@"%@ start", self.name);
    
    OCMExpect([mock canPersisting]).andReturn(YES);
    
    BOOL bPersisting = [mock canPersisting];
    
    XCTAssert(bPersisting, @"canPersisting doesn't return YES.");
    OCMVerifyAll(mock);
    
    NSLog(@"%@ end", self.name);
}

- (void)testSaveItemDataMethodWithConstraint {
    NSLog(@"%@ start", self.name);
    
    YHAnalyItemData *data = [[YHAnalyItemData alloc] init];
    
    [[mock expect] saveItemData:data];
    [mock saveItemData:data];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testGetAllEventCountMethod {
    NSLog(@"%@ start", self.name);
    
    [[[mock expect] andReturnValue:@10] getAllEventCount];
    NSUInteger count = [mock getAllEventCount];
    XCTAssertEqual(count, 10, @"YHAssemblyAssistant getAllEventCount doesn't return 10.");
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testGetUploadDataMethod {
    NSLog(@"%@ start", self.name);
    
    NSDictionary *data = @{@"key": @"value"};
    [[[mock expect] andReturn:data] getUploadData];
    NSDictionary *returndata = [mock getUploadData];
    XCTAssertEqualObjects(data, returndata, @"YHAssemblyAssistant getUploadData doesn't return a dictionary with key:value.");
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testPrepareImmediUploadDicMethod {
    NSLog(@"%@ start", self.name);
    
    [[mock expect] prepareImmediUploadDic:@"appId" sessionId:@"sessionId" channelId:@"channelId"];
    [mock prepareImmediUploadDic:@"appId" sessionId:@"sessionId" channelId:@"channelId"];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testUploadDiskDataMethod {
    NSLog(@"%@ start", self.name);
    
    [[mock expect] uploadDiskData];
    [mock uploadDiskData];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}

- (void)testUploadImmedilyWithEventMethodWithConstraint {
    NSLog(@"%@ start", self.name);
    
    YHAnalyItemData *data = [[YHAnalyItemData alloc] init];
    [[mock expect] uploadImmedilyWithEvent:data];
    [mock uploadImmedilyWithEvent:data];
    [mock verify];
    
    NSLog(@"%@ end", self.name);
}
@end