Skip to content

Commit 4cb15f5

Browse files
committed
wrote objc/swift unit tests for the bug that was fixed in version 2.0
1 parent 8c34590 commit 4cb15f5

File tree

8 files changed

+73
-3
lines changed

8 files changed

+73
-3
lines changed

OCMapper.xcodeproj/project.pbxproj

+14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
92514E941B2CC9870098D34D /* Purchase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92514E8F1B2CC9870098D34D /* Purchase.swift */; };
6868
92514E951B2CC9870098D34D /* Purchase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92514E8F1B2CC9870098D34D /* Purchase.swift */; };
6969
92514E981B2CC99B0098D34D /* ObjectMapperSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92514E961B2CC99B0098D34D /* ObjectMapperSwiftTests.swift */; };
70+
92A297E01B2E32D000B6B2F0 /* ActivationStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92A297DF1B2E32D000B6B2F0 /* ActivationStatus.swift */; };
71+
92A297E11B2E32D000B6B2F0 /* ActivationStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92A297DF1B2E32D000B6B2F0 /* ActivationStatus.swift */; };
72+
92A297E41B2E33B700B6B2F0 /* EmailConfirmation.m in Sources */ = {isa = PBXBuildFile; fileRef = 92A297E31B2E33B700B6B2F0 /* EmailConfirmation.m */; };
73+
92A297E51B2E33B700B6B2F0 /* EmailConfirmation.m in Sources */ = {isa = PBXBuildFile; fileRef = 92A297E31B2E33B700B6B2F0 /* EmailConfirmation.m */; };
7074
/* End PBXBuildFile section */
7175

7276
/* Begin PBXContainerItemProxy section */
@@ -184,6 +188,9 @@
184188
92514E961B2CC99B0098D34D /* ObjectMapperSwiftTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectMapperSwiftTests.swift; sourceTree = "<group>"; };
185189
92514E9C1B2CC9CA0098D34D /* OCMapper-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OCMapper-Bridging-Header.h"; sourceTree = "<group>"; };
186190
92514E9D1B2CC9CA0098D34D /* OCMapperTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OCMapperTests-Bridging-Header.h"; sourceTree = "<group>"; };
191+
92A297DF1B2E32D000B6B2F0 /* ActivationStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActivationStatus.swift; sourceTree = "<group>"; };
192+
92A297E21B2E33B700B6B2F0 /* EmailConfirmation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EmailConfirmation.h; sourceTree = "<group>"; };
193+
92A297E31B2E33B700B6B2F0 /* EmailConfirmation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EmailConfirmation.m; sourceTree = "<group>"; };
187194
/* End PBXFileReference section */
188195

189196
/* Begin PBXFrameworksBuildPhase section */
@@ -410,6 +417,8 @@
410417
15E2B971171BEAEB00526C77 /* User.m */,
411418
15EA38001866102D005CCEA0 /* SpecialUser.h */,
412419
15EA38011866102D005CCEA0 /* SpecialUser.m */,
420+
92A297E21B2E33B700B6B2F0 /* EmailConfirmation.h */,
421+
92A297E31B2E33B700B6B2F0 /* EmailConfirmation.m */,
413422
);
414423
path = Models;
415424
sourceTree = "<group>";
@@ -457,6 +466,7 @@
457466
92514E8D1B2CC9870098D34D /* Customer.swift */,
458467
92514E8E1B2CC9870098D34D /* Location.swift */,
459468
92514E8F1B2CC9870098D34D /* Purchase.swift */,
469+
92A297DF1B2E32D000B6B2F0 /* ActivationStatus.swift */,
460470
);
461471
path = Swift;
462472
sourceTree = "<group>";
@@ -585,6 +595,7 @@
585595
157B309C171E5D32005AAB02 /* CDPost.m in Sources */,
586596
157B313E17234A97005AAB02 /* NSDictionary+ObjectMapper.m in Sources */,
587597
157B313F17234A97005AAB02 /* NSObject+ObjectMapper.m in Sources */,
598+
92A297E41B2E33B700B6B2F0 /* EmailConfirmation.m in Sources */,
588599
92514E921B2CC9870098D34D /* Location.swift in Sources */,
589600
157B314417234ACB005AAB02 /* ObjectInstanceProvider.m in Sources */,
590601
157B314717234ADF005AAB02 /* ManagedObjectInstanceProvider.m in Sources */,
@@ -601,6 +612,7 @@
601612
1502B38E17CD985300C095DE /* AFNetworkActivityIndicatorManager.m in Sources */,
602613
1502B38F17CD985300C095DE /* AFPropertyListRequestOperation.m in Sources */,
603614
1502B39017CD985300C095DE /* AFURLConnectionOperation.m in Sources */,
615+
92A297E01B2E32D000B6B2F0 /* ActivationStatus.swift in Sources */,
604616
1502B39117CD985300C095DE /* AFXMLRequestOperation.m in Sources */,
605617
1502B39217CD985300C095DE /* UIImageView+AFNetworking.m in Sources */,
606618
1502B39B17CDA07100C095DE /* OCMapperConfig.m in Sources */,
@@ -618,10 +630,12 @@
618630
files = (
619631
92514E911B2CC9870098D34D /* Customer.swift in Sources */,
620632
92514E951B2CC9870098D34D /* Purchase.swift in Sources */,
633+
92A297E11B2E32D000B6B2F0 /* ActivationStatus.swift in Sources */,
621634
15E2B992171BEAF400526C77 /* ObjectMapperTests.m in Sources */,
622635
92514E931B2CC9870098D34D /* Location.swift in Sources */,
623636
157B3096171E58C0005AAB02 /* ManagedObjectMapperTest.m in Sources */,
624637
92514E981B2CC99B0098D34D /* ObjectMapperSwiftTests.swift in Sources */,
638+
92A297E51B2E33B700B6B2F0 /* EmailConfirmation.m in Sources */,
625639
);
626640
runOnlyForDeploymentPostprocessing = 0;
627641
};

OCMapper/Models/EmailConfirmation.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// EmailConfirmation.h
3+
// OCMapper
4+
//
5+
// Created by Aryan on 6/14/15.
6+
// Copyright (c) 2015 Aryan Ghassemi. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface EmailConfirmation : NSObject
12+
13+
@property (nonatomic, strong) NSString *value;
14+
15+
@end

OCMapper/Models/EmailConfirmation.m

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// EmailConfirmation.m
3+
// OCMapper
4+
//
5+
// Created by Aryan on 6/14/15.
6+
// Copyright (c) 2015 Aryan Ghassemi. All rights reserved.
7+
//
8+
9+
#import "EmailConfirmation.h"
10+
11+
@implementation EmailConfirmation
12+
13+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// ActivationStatus.swift
3+
// OCMapper
4+
//
5+
// Created by Aryan on 6/14/15.
6+
// Copyright (c) 2015 Aryan Ghassemi. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public class ActivationStatus: NSObject {
12+
13+
public var value: String?
14+
15+
}

OCMapper/Models/Swift/Customer.swift

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class Customer: NSObject {
1616
public var location: Location?
1717
public var billing: Location?
1818
public var home: Location?
19+
public var status: ActivationStatus?
1920
public var purchases: [Purchase]?
2021

2122
}

OCMapper/Models/User.h

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#import <Foundation/Foundation.h>
2929
#import "Address.h"
30+
#import "EmailConfirmation.h"
3031

3132
@interface User : NSObject
3233

@@ -37,6 +38,7 @@
3738
@property (nonatomic, strong) NSNumber *age;
3839
@property (nonatomic, strong) Address *address;
3940
@property (nonatomic, strong) Address *work;
41+
@property (nonatomic, strong) EmailConfirmation *econfirmed;
4042
@property (nonatomic, strong) NSMutableArray *comments;
4143
@property (nonatomic, strong) NSMutableArray *randomKeywords;
4244

OCMapperTests/ObjectMapperSwiftTests.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ class ObjectMapperSwiftTests : XCTestCase {
8686
"fName": "Aryan",
8787
"ageee": 28,
8888
"dob": date,
89-
"address": ["name": "SF"],
90-
"billing-address": ["name": "SD"],
89+
"address": ["name": "SF"],
90+
"billing-address": ["name": "SD"],
91+
"status": ["value": "banned"],
9192
"orders": [
9293
["summary": "bla 1", "price": 123.4],
9394
["summary": "bla 2", "price": 55],
@@ -106,7 +107,10 @@ class ObjectMapperSwiftTests : XCTestCase {
106107

107108
XCTAssertNotNil(customer.billing, "FAIL")
108109
XCTAssertTrue(customer.billing!.name == "SD", "FAIL")
109-
110+
111+
XCTAssertNotNil(customer.status, "FAIL")
112+
XCTAssertTrue(customer.status!.value == "banned", "FAIL")
113+
110114
let purchases = customer.valueForKey("purchases") as! NSArray
111115

112116
// Can't access calues directly in unit test target, swift throws exception because it doesn't know which target the models belong to, main target or unit test target. This won't be an issue outside of test environment

OCMapperTests/ObjectMapperTests.m

+6
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,12 @@ - (void)testShouldConvertValuesInDictionaryFromNSNumberToNSStringIfNeeded {
521521
XCTAssertTrue([user.firstName isEqualToString:@"123"]);
522522
}
523523

524+
- (void)testShouldautomaticallyMapClassesWithTwoKeywords {
525+
NSDictionary *userDictionary = @{@"econfirmed" : @{@"value" : @"not-confirmed"}};
526+
User *user = [self.mapper objectFromSource:userDictionary toInstanceOfClass:[User class]];
527+
XCTAssertTrue([user.econfirmed.value isEqualToString:@"not-confirmed"]);
528+
}
529+
524530
- (void)testObjectInstanceProviderShouldReturnTrueForNSObjectSubclasses
525531
{
526532
ObjectInstanceProvider *instanceProvider = [[ObjectInstanceProvider alloc] init];

0 commit comments

Comments
 (0)