YHErrorTests.m 2.76 KB
//
//  YHErrorTests.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 "OCMock.h"
#import "YHError.h"

@interface YHErrorTests : XCTestCase{
@private
    YHError *error;
}

@end

@implementation YHErrorTests

- (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);
    error = [[YHError alloc] init];
    XCTAssertNotNil(error, @"Cannot create YHError instance.");
}

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

#pragma mark - super property

- (void)testDataType {
    NSLog(@"%@ start", self.name);
    YHItemDataType type = [error dataType];
    XCTAssert(type == YHItemDataTypeError, @"Error dataType must be YHItemDataTypeError.");
    NSLog(@"%@ end", self.name);
}

- (void)testJsonDictionaryNotNil {
    NSLog(@"%@ start", self.name);
    NSDictionary *jsonDictionary = [error jsonDictionary];
    XCTAssertNotNil(jsonDictionary, @"Error jsonDictionary can't be nil.");
    NSLog(@"%@ end", self.name);
}

#pragma mark - value for json key

- (void)testValueForJsonKeyErrorUID {
    NSLog(@"%@ start", self.name);
    NSDictionary *jsonDictionary = [error jsonDictionary];
    id value = [jsonDictionary objectForKey:JsonKeyErrorUID];
    XCTAssert(value, @"JsonKeyErrorUID value doesn't exist.");
    NSLog(@"%@ end", self.name);
}

- (void)testValueForJsonKeyErrorTS {
    NSLog(@"%@ start", self.name);
    NSDictionary *jsonDictionary = [error jsonDictionary];
    id value = [jsonDictionary objectForKey:JsonKeyErrorTS];
    XCTAssert(value, @"JsonKeyErrorTS value doesn't exist.");
    NSLog(@"%@ end", self.name);
}

- (void)testValueForJsonKeyErrorSID {
    NSLog(@"%@ start", self.name);
    NSDictionary *jsonDictionary = [error jsonDictionary];
    id value = [jsonDictionary objectForKey:JsonKeyErrorSID];
    XCTAssert(value, @"JsonKeyErrorSID value doesn't exist.");
    NSLog(@"%@ end", self.name);
}

- (void)testValueForJsonKeyErrorET {
    NSLog(@"%@ start", self.name);
    NSDictionary *jsonDictionary = [error jsonDictionary];
    id value = [jsonDictionary objectForKey:JsonKeyErrorET];
    XCTAssert(value, @"JsonKeyErrorET value doesn't exist.");
    NSLog(@"%@ end", self.name);
}

- (void)testValueForJsonKeyErrorPARAM {
    NSLog(@"%@ start", self.name);
    NSDictionary *jsonDictionary = [error jsonDictionary];
    id value = [jsonDictionary objectForKey:JsonKeyErrorPARAM];
    XCTAssert(value, @"JsonKeyErrorPARAM value doesn't exist.");
    NSLog(@"%@ end", self.name);
}
@end