-
-
Notifications
You must be signed in to change notification settings - Fork 874
/
Copy pathConfigUnitTests.m
115 lines (82 loc) · 3.28 KB
/
ConfigUnitTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <OCMock/OCMock.h>
@import Bolts;
#import "PFConfigController.h"
#import "PFConfig_Private.h"
#import "PFCoreManager.h"
#import "PFCurrentConfigController.h"
#import "PFUnitTestCase.h"
#import "Parse_Private.h"
@interface ConfigUnitTests : PFUnitTestCase
@property (nonatomic, strong) PFConfigController *mockedConfigController;
@end
@implementation ConfigUnitTests
///--------------------------------------
#pragma mark - XCTestCase
///--------------------------------------
- (void)setUp {
[super setUp];
[Parse _currentManager].coreManager.configController = self.mockedConfigController;
}
- (void)tearDown {
self.mockedConfigController = nil;
[super tearDown];
}
///--------------------------------------
#pragma mark - Helpers
///--------------------------------------
- (PFConfigController *)mockedConfigController {
if (_mockedConfigController == nil) {
_mockedConfigController = PFStrictClassMock([PFConfigController class]);
BFTask *mockedTask = [BFTask taskWithResult:[self sampleConfig]];
OCMStub([_mockedConfigController fetchConfigAsyncWithSessionToken:nil]).andReturn(mockedTask);
PFCurrentConfigController *mockedCurrentController = PFStrictClassMock([PFCurrentConfigController class]);
OCMStub([_mockedConfigController currentConfigController]).andReturn(mockedCurrentController);
OCMStub([mockedCurrentController getCurrentConfigAsync]).andReturn(mockedTask);
}
return _mockedConfigController;
}
- (PFConfig *)sampleConfig {
return [[PFConfig alloc] initWithFetchedConfig:@{ @"params": @{ @"testKey": @"testValue" } }];
}
///--------------------------------------
#pragma mark - Tests
///--------------------------------------
- (void)testCurrentConfig {
PFConfig *config = [PFConfig currentConfig];
XCTAssertEqualObjects(config[@"testKey"], @"testValue");
XCTAssertEqualObjects([config objectForKey:@"testKey"], @"testValue");
}
- (void)testGetConfig {
PFConfig *config = [PFConfig getConfig];
XCTAssertEqualObjects(config[@"testKey"], @"testValue");
XCTAssertEqualObjects(config, [self sampleConfig]);
}
- (void)testGetConfigInBackground {
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
[PFConfig getConfigInBackgroundWithBlock:^(PFConfig *config, NSError *error) {
XCTAssertNotNil(config);
XCTAssertEqualObjects(config[@"testKey"], @"testValue");
XCTAssertEqualObjects(config, [self sampleConfig]);
[expectation fulfill];
}];
[self waitForTestExpectations];
}
- (void)testEquality {
PFConfig *config = [self sampleConfig];
PFConfig *currentConfig = [PFConfig currentConfig];
PFConfig *thirdConfig = [[PFConfig alloc] init];
XCTAssertEqual([config hash], [currentConfig hash]);
XCTAssertNotEqual([config hash], [thirdConfig hash]);
XCTAssertEqualObjects(config, currentConfig);
XCTAssertNotEqualObjects(config, thirdConfig);
XCTAssertNotEqualObjects(config, @"Hello World!");
}
@end