Commit ccec1776 by Brent Gulanowski

Rename one file and remove other file. Also new tests.

parent d8464f93
......@@ -29,6 +29,8 @@
#import "BUYFlatCollectionTransformer.h"
#import "BUYDateTransformer.h"
#import "BUYIdentityTransformer.h"
#import "NSEntityDescription+BUYAdditions.h"
#import "NSPropertyDescription+BUYAdditions.h"
#import "TestModel.h"
......@@ -42,16 +44,16 @@ static NSString * const BirdEntity = @"Bird";
+ (instancetype)indexSetWithIndexes:(NSArray *)indexes;
@end
@interface BUYPropertyDescriptionAdditionsTests : XCTestCase
@interface BUYCoreDataModelAdditionsTests : XCTestCase
@property (nonatomic) NSManagedObjectModel *model;
@property (nonatomic) TestModelManager *modelManager;
@end
@implementation BUYPropertyDescriptionAdditionsTests
@implementation BUYCoreDataModelAdditionsTests
+ (void)initialize
{
if (self == [BUYPropertyDescriptionAdditionsTests class]) {
if (self == [BUYCoreDataModelAdditionsTests class]) {
[NSValueTransformer setValueTransformer:[BUYFlatCollectionTransformer arrayTransformer] forName:@"Array"];
[NSValueTransformer setValueTransformer:[BUYFlatCollectionTransformer setTransformer] forName:@"Set"];
}
......@@ -85,6 +87,7 @@ static NSString * const BirdEntity = @"Bird";
- (void)testJSONTransformerName
{
XCTAssertEqualObjects(BUYDateTransformerName, [self attributeWithName:@"date" forEntity:LeafEntity].JSONValueTransformerName);
XCTAssertEqualObjects(BUYIdentityTransformerName, [self attributeWithName:@"identifier" forEntity:RootEntity].JSONValueTransformerName);
}
- (void)testJSONPropertyKey
......@@ -97,6 +100,20 @@ static NSString * const BirdEntity = @"Bird";
XCTAssertEqualObjects([BUYFlatCollectionTransformer class], [[self attributeWithName:@"tags" forEntity:LeafEntity].JSONValueTransformer class]);
}
- (void)testNilAttribute
{
NSAttributeDescription *idAttribute = [self attributeWithName:@"identifier" forEntity:RootEntity];
XCTAssertNil([idAttribute buy_JSONForValue:nil]);
XCTAssertEqualObjects([idAttribute buy_valueForJSON:nil object:nil], [NSNull null]);
}
- (void)testNullAttribute
{
NSAttributeDescription *idAttribute = [self attributeWithName:@"identifier" forEntity:RootEntity];
XCTAssertEqualObjects([idAttribute buy_JSONForValue:[NSNull null]], [NSNull null]);
XCTAssertEqualObjects([idAttribute buy_valueForJSON:[NSNull null] object:nil], [NSNull null]);
}
- (void)testInteger
{
NSAttributeDescription *idAttribute = [self attributeWithName:@"identifier" forEntity:RootEntity];
......@@ -162,6 +179,20 @@ static NSString * const BirdEntity = @"Bird";
XCTAssertEqualObjects(actual, tags);
}
- (void)testNilRelationship
{
Branch *branch = [self.modelManager buy_objectWithEntityName:BranchEntity JSONDictionary:nil];
NSRelationshipDescription *nestRelationship = [self relationshipWithName:@"nest" forEntity:BranchEntity];
XCTAssertNil([nestRelationship buy_valueForJSON:nil object:branch]);
}
- (void)testNullRelationship
{
Branch *branch = [self.modelManager buy_objectWithEntityName:BranchEntity JSONDictionary:nil];
NSRelationshipDescription *nestRelationship = [self relationshipWithName:@"nest" forEntity:BranchEntity];
XCTAssertNil([nestRelationship buy_valueForJSON:[NSNull null] object:branch]);
}
- (void)testRelationship
{
Branch *branch = [self.modelManager buy_objectWithEntityName:BranchEntity JSONDictionary:nil];
......@@ -190,13 +221,26 @@ static NSString * const BirdEntity = @"Bird";
// Semi-random leaf objects
branch.leaves = [NSSet setWithArray:@[[self leafWithDate:[self dateWithComponents:[self november4_1605]] tags:[self tagsWithIndexes:@[@1, @5, @11]]],
[self leafWithDate:[self dateWithComponents:[self november4_1605]] tags:[self tagsWithIndexes:@[@9]]],
[self leafWithDate:[self dateWithComponents:[self november4_1605]] tags:[self tagsWithIndexes:@[@12, @0, @8, @4]]]]];
[self leafWithDate:[self dateWithComponents:[self june21_1970]] tags:[self tagsWithIndexes:@[@9]]],
[self leafWithDate:[self dateWithComponents:[self jan1_2000]] tags:[self tagsWithIndexes:@[@12, @0, @8, @4]]]]];
id json = [leafRelationship buy_JSONForValue:branch.leaves];
id actual = [leafRelationship buy_valueForJSON:json object:branch];
XCTAssertEqualObjects(actual, branch.leaves);
}
- (void)testEntityIsPrivate
{
NSEntityDescription *forestEntity = [self entityForName:[Forest entityName]];
XCTAssertTrue([forestEntity buy_isPrivate]);
}
- (void)testFetchedProperty
{
NSFetchedPropertyDescription *fetchedProperty = [[NSFetchedPropertyDescription alloc] init];
XCTAssertNil([fetchedProperty buy_valueForJSON:nil object:nil]);
XCTAssertNil([fetchedProperty buy_JSONForValue:nil]);
}
- (Leaf *)leafWithDate:(NSDate *)date tags:(NSSet *)tags
{
Leaf *leaf = [self.modelManager buy_objectWithEntityName:[Leaf entityName] JSONDictionary:nil];
......@@ -238,6 +282,16 @@ static NSString * const BirdEntity = @"Bird";
return components;
}
- (NSDateComponents *)jan1_2000
{
NSDateComponents *components = [[NSDateComponents alloc] init];
components.year = 2000;
components.month = 1;
components.day = 1;
components.second = 1;
return components;
}
@end
@implementation NSIndexSet (BUYTestAdditions)
......
//
// BUYEntityDescriptionAdditionsTests.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <XCTest/XCTest.h>
@interface BUYEntityDescriptionAdditionsTests : XCTestCase
@end
@implementation BUYEntityDescriptionAdditionsTests
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testExample {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
- (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
}
@end
......@@ -80,8 +80,7 @@
8491103A1CCE718100E53B93 /* BUYExceptionAdditionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 849110391CCE718100E53B93 /* BUYExceptionAdditionsTests.m */; };
8491103C1CCE731900E53B93 /* BUYURLAdditionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8491103B1CCE731900E53B93 /* BUYURLAdditionsTests.m */; };
8491103E1CCE988600E53B93 /* BUYFontAdditionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8491103D1CCE988600E53B93 /* BUYFontAdditionsTests.m */; };
849110401CCE9DFB00E53B93 /* BUYPropertyDescriptionAdditionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8491103F1CCE9DFB00E53B93 /* BUYPropertyDescriptionAdditionsTests.m */; };
849110421CCE9E0A00E53B93 /* BUYEntityDescriptionAdditionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 849110411CCE9E0A00E53B93 /* BUYEntityDescriptionAdditionsTests.m */; };
849110401CCE9DFB00E53B93 /* BUYCoreDataModelAdditionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8491103F1CCE9DFB00E53B93 /* BUYCoreDataModelAdditionsTests.m */; };
849110441CCE9F3F00E53B93 /* BUYTransformerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 849110431CCE9F3F00E53B93 /* BUYTransformerTests.m */; };
84980F291CB75AC200CFAB58 /* BUYObjectProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 84980F281CB75AC200CFAB58 /* BUYObjectProtocol.h */; };
84980F2A1CB75AC200CFAB58 /* BUYObjectProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 84980F281CB75AC200CFAB58 /* BUYObjectProtocol.h */; };
......@@ -448,8 +447,7 @@
849110391CCE718100E53B93 /* BUYExceptionAdditionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYExceptionAdditionsTests.m; sourceTree = "<group>"; };
8491103B1CCE731900E53B93 /* BUYURLAdditionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYURLAdditionsTests.m; sourceTree = "<group>"; };
8491103D1CCE988600E53B93 /* BUYFontAdditionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYFontAdditionsTests.m; sourceTree = "<group>"; };
8491103F1CCE9DFB00E53B93 /* BUYPropertyDescriptionAdditionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYPropertyDescriptionAdditionsTests.m; sourceTree = "<group>"; };
849110411CCE9E0A00E53B93 /* BUYEntityDescriptionAdditionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYEntityDescriptionAdditionsTests.m; sourceTree = "<group>"; };
8491103F1CCE9DFB00E53B93 /* BUYCoreDataModelAdditionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYCoreDataModelAdditionsTests.m; sourceTree = "<group>"; };
849110431CCE9F3F00E53B93 /* BUYTransformerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYTransformerTests.m; sourceTree = "<group>"; };
84980F281CB75AC200CFAB58 /* BUYObjectProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYObjectProtocol.h; sourceTree = "<group>"; };
84980F2B1CB75B5E00CFAB58 /* BUYModelManagerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYModelManagerProtocol.h; sourceTree = "<group>"; };
......@@ -810,13 +808,12 @@
BEB9AE7A1BA866D000575F8A /* BUYClientTestBase.h */,
BEB9AE7C1BA8685600575F8A /* BUYClientTestBase.m */,
849110341CCE70CE00E53B93 /* BUYDictionaryAdditionsTests.m */,
849110411CCE9E0A00E53B93 /* BUYEntityDescriptionAdditionsTests.m */,
849110391CCE718100E53B93 /* BUYExceptionAdditionsTests.m */,
8491103D1CCE988600E53B93 /* BUYFontAdditionsTests.m */,
90F592F81B0D5F4C0026B382 /* BUYIntegrationTest.m */,
90F592FE1B0D5F4C0026B382 /* BUYLineItemTest.m */,
90F592FF1B0D5F4C0026B382 /* BUYObjectTests.m */,
8491103F1CCE9DFB00E53B93 /* BUYPropertyDescriptionAdditionsTests.m */,
8491103F1CCE9DFB00E53B93 /* BUYCoreDataModelAdditionsTests.m */,
8491102F1CCE708900E53B93 /* BUYRegularExpressionAdditionsTests.m */,
849110301CCE708900E53B93 /* BUYStringAdditionsTests.m */,
90F593001B0D5F4C0026B382 /* BUYTestConstants.h */,
......@@ -1479,7 +1476,6 @@
files = (
BEB9AE7D1BA885E300575F8A /* BUYClientTestBase.m in Sources */,
8491103E1CCE988600E53B93 /* BUYFontAdditionsTests.m in Sources */,
849110421CCE9E0A00E53B93 /* BUYEntityDescriptionAdditionsTests.m in Sources */,
8491103A1CCE718100E53B93 /* BUYExceptionAdditionsTests.m in Sources */,
849110441CCE9F3F00E53B93 /* BUYTransformerTests.m in Sources */,
849110351CCE70CE00E53B93 /* BUYDictionaryAdditionsTests.m in Sources */,
......@@ -1497,7 +1493,7 @@
906CF1B11B8B66AE001F7D5B /* BUYCNPostalAddress.m in Sources */,
84CA59BC1CD1378100B2A956 /* BUYTestModel.xcdatamodeld in Sources */,
8491103C1CCE731900E53B93 /* BUYURLAdditionsTests.m in Sources */,
849110401CCE9DFB00E53B93 /* BUYPropertyDescriptionAdditionsTests.m in Sources */,
849110401CCE9DFB00E53B93 /* BUYCoreDataModelAdditionsTests.m in Sources */,
84CA59C01CD1609400B2A956 /* TestModel.m in Sources */,
906CF1AD1B8B5F7D001F7D5B /* BUYNSPersonNameComponents.m in Sources */,
BE98DB5C1BB1F4D000C29564 /* OHHTTPStubsResponse+Helpers.m in Sources */,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment