Skip to content

Commit 2d2147f

Browse files
Remedying Xcode 9.2 compiler warnings in unit tests (#244)
1 parent 5121c96 commit 2d2147f

File tree

8 files changed

+55
-35
lines changed

8 files changed

+55
-35
lines changed

OptimizelySDKCore/OptimizelySDKCoreTests/OPTLYBuilderTest.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ - (void)testBuilderCanAssignErrorHandler {
8080
}
8181

8282
- (void)testBuilderCanAssignEventDispatcher {
83-
id<OPTLYEventDispatcher> eventDispatcher = [[NSObject alloc] init];
83+
id<OPTLYEventDispatcher> eventDispatcher = (id<OPTLYEventDispatcher>)[[NSObject alloc] init];
8484

8585
Optimizely *defaultOptimizely = [Optimizely init:^(OPTLYBuilder *builder) {
8686
builder.datafile = datafile;
@@ -116,7 +116,10 @@ - (void)testBuilderCanAssignLogger {
116116
}
117117

118118
- (void)testInitializationWithoutBuilder {
119+
#pragma clang diagnostic push
120+
#pragma clang diagnostic ignored "-Wnonnull"
119121
Optimizely *optimizely = [Optimizely init:nil];
122+
#pragma clang diagnostic pop
120123
XCTAssertNil(optimizely);
121124
}
122125

OptimizelySDKCore/OptimizelySDKCoreTests/OPTLYErrorHandlerTest.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ - (void)tearDown {
3535

3636
- (void)testConformsToOPTLYLoggerProtocol
3737
{
38-
id<OPTLYErrorHandler> errorHandler = [NSObject new];
39-
BOOL conformsToProtocol = [OPTLYErrorHandler conformsToOPTLYErrorHandlerProtocol:[errorHandler class]];
40-
NSAssert(conformsToProtocol == FALSE, @"Object does not conform to protocol.");
41-
42-
errorHandler = [OPTLYErrorHandlerDefault new];
43-
conformsToProtocol = [OPTLYErrorHandler conformsToOPTLYErrorHandlerProtocol:[errorHandler class]];
44-
NSAssert(conformsToProtocol == TRUE, @"Object should conform to protocol.");
38+
{
39+
NSObject* errorHandler = [NSObject new];
40+
BOOL conformsToProtocol = [OPTLYErrorHandler conformsToOPTLYErrorHandlerProtocol:[errorHandler class]];
41+
XCTAssert(conformsToProtocol == FALSE, @"Object does not conform to protocol.");
42+
}
43+
{
44+
id<OPTLYErrorHandler> errorHandler = [OPTLYErrorHandlerDefault new];
45+
BOOL conformsToProtocol = [OPTLYErrorHandler conformsToOPTLYErrorHandlerProtocol:[errorHandler class]];
46+
XCTAssert(conformsToProtocol == TRUE, @"Object should conform to protocol.");
47+
}
4548
}
4649

4750
@end

OptimizelySDKCore/OptimizelySDKCoreTests/OPTLYEventDispatcherTest.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ - (void)tearDown {
3535

3636
- (void)testConformsToOPTLYEventDispatcherProtocol
3737
{
38-
id<OPTLYEventDispatcher> eventDispatcher = [NSObject new];
39-
BOOL conformsToProtocol = [OPTLYEventDispatcherUtility conformsToOPTLYEventDispatcherProtocol:[eventDispatcher class]];
40-
NSAssert(conformsToProtocol == FALSE, @"Object does not conform to protocol.");
41-
42-
eventDispatcher = [OPTLYEventDispatcherNoOp new];
43-
conformsToProtocol = [OPTLYEventDispatcherUtility conformsToOPTLYEventDispatcherProtocol:[eventDispatcher class]];
44-
NSAssert(conformsToProtocol == TRUE, @"Object should conform to protocol.");
38+
{
39+
NSObject* eventDispatcher = [NSObject new];
40+
BOOL conformsToProtocol = [OPTLYEventDispatcherUtility conformsToOPTLYEventDispatcherProtocol:[eventDispatcher class]];
41+
XCTAssert(conformsToProtocol == FALSE, @"Object does not conform to protocol.");
42+
}
43+
{
44+
id<OPTLYEventDispatcher> eventDispatcher = [OPTLYEventDispatcherNoOp new];
45+
BOOL conformsToProtocol = [OPTLYEventDispatcherUtility conformsToOPTLYEventDispatcherProtocol:[eventDispatcher class]];
46+
XCTAssert(conformsToProtocol == TRUE, @"Object should conform to protocol.");
47+
}
4548
}
4649

4750
@end

OptimizelySDKCore/OptimizelySDKCoreTests/OPTLYLoggerTest.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ - (void)tearDown {
3535

3636
- (void)testConformsToOPTLYLoggerProtocol
3737
{
38-
id<OPTLYLogger> logger = [NSObject new];
39-
BOOL conformsToProtocol = [OPTLYLoggerUtility conformsToOPTLYLoggerProtocol:[logger class]];
40-
NSAssert(conformsToProtocol == FALSE, @"Object does not conform to protocol.");
41-
42-
logger = [OPTLYLoggerDefault new];
43-
conformsToProtocol = [OPTLYLoggerUtility conformsToOPTLYLoggerProtocol:[logger class]];
44-
NSAssert(conformsToProtocol == TRUE, @"Object should conform to protocol.");
38+
{
39+
NSObject* logger = [NSObject new];
40+
BOOL conformsToProtocol = [OPTLYLoggerUtility conformsToOPTLYLoggerProtocol:[logger class]];
41+
XCTAssert(conformsToProtocol == FALSE, @"Object does not conform to protocol.");
42+
}
43+
{
44+
id<OPTLYLogger> logger = [OPTLYLoggerDefault new];
45+
BOOL conformsToProtocol = [OPTLYLoggerUtility conformsToOPTLYLoggerProtocol:[logger class]];
46+
XCTAssert(conformsToProtocol == TRUE, @"Object should conform to protocol.");
47+
}
4548
}
4649

4750

OptimizelySDKCore/OptimizelySDKCoreTests/OPTLYProjectConfigTest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ - (void)testInitWithBuilderBlockNoDatafile
127127
- (void)testInitWithBuilderBlockInvalidModulesFails {
128128
NSData *datafile = [OPTLYTestHelper loadJSONDatafileIntoDataObject:kDataModelDatafileName];
129129

130-
id<OPTLYLogger> logger = [NSObject new];
131-
id<OPTLYErrorHandler> errorHandler = [NSObject new];
130+
id<OPTLYLogger> logger = (id<OPTLYLogger>)[NSObject new];
131+
id<OPTLYErrorHandler> errorHandler = (id<OPTLYErrorHandler>)[NSObject new];
132132

133133
OPTLYProjectConfig *projectConfig = [OPTLYProjectConfig init:^(OPTLYProjectConfigBuilder * _Nullable builder){
134134
builder.datafile = datafile;

OptimizelySDKEventDispatcher/OptimizelySDKEventDispatcherTests/OPTLYEventDispatcherTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ - (void)testFlushEventAttempts {
339339
typedef void (^FlushEventsBlock)(void);
340340
__block __weak FlushEventsBlock weakFlushEvents = nil;
341341
__weak typeof(self) weakSelf = self;
342-
__block void (^flushEvents)() = ^(){
342+
__block void (^flushEvents)(void) = ^(){
343343
FlushEventsBlock strongFlushEvents = weakFlushEvents;
344344
attempts++;
345345
[eventDispatcher flushEvents:^{

OptimizelySDKShared/OptimizelySDKSharedTests/OPTLYManagerTest.m

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ - (void)testInitializeCachedDatafileBadLoad
114114
id partialMockManager = OCMPartialMock(manager);
115115

116116
// mock a failed cached datafile load
117-
id partialDatafileManagerMock = OCMPartialMock(manager.datafileManager);
117+
id partialDatafileManagerMock = OCMPartialMock((NSObject*)manager.datafileManager);
118118
OCMStub([partialDatafileManagerMock getSavedDatafile:nil]).andReturn(nil);
119119

120120
OPTLYClient *client = [partialMockManager initialize];
@@ -371,7 +371,10 @@ - (void)testInitializeWithCallbackDownloadErrorNoDatafile
371371
builder.projectId = kProjectId;
372372
}];
373373

374-
id partialMockManager = OCMPartialMock(manager);
374+
#pragma clang diagnostic push
375+
#pragma clang diagnostic ignored "-Wunused-value"
376+
OCMPartialMock(manager);
377+
#pragma clang diagnostic pop
375378

376379
// setup async expectation
377380
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"testInitializeWithCallbackDownloadErrorNoDatafile"];
@@ -390,13 +393,15 @@ - (void)testInitializeWithCallbackDownloadErrorNoDatafile
390393
- (void)isClientValid:(OPTLYClient *)client
391394
datafile:(NSData *)datafile
392395
{
393-
Optimizely *optly = [Optimizely init:^(OPTLYBuilder * _Nullable builder) {
396+
#pragma clang diagnostic push
397+
#pragma clang diagnostic ignored "-Wunused-value"
398+
[Optimizely init:^(OPTLYBuilder * _Nullable builder) {
394399
builder.datafile = datafile;
395400
builder.clientEngine = kClientEngine;
396401
builder.clientVersion = kClientVersion;
397402
}];
398-
OPTLYProjectConfig *projectConfig = optly.config;
399-
403+
#pragma clang diagnostic pop
404+
400405
XCTAssertNotNil(client, @"Client should not be nil.");
401406
// TODO (Alda): Need to write equality methods for the data models to properly make this assertion
402407
//XCTAssert([projectConfig isEqual:client.optimizely.config], @"Optimizely config is invalid.");

OptimizelySDKUserProfileService/OptimizelySDKUserProfileServiceTests/OptimizelySDKUserProfileServiceTests.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ - (void)testClearUserExperimentRecordsForUser
179179
NSDictionary *userProfile1 = [self.userProfileService lookup:kUserId1];
180180
XCTAssertNil(userProfile1, @"User profile for userId 1 should have been removed.");
181181

182-
NSString *userProfile2 = [self.userProfileService lookup:kUserId2];
182+
NSDictionary *userProfile2 = [self.userProfileService lookup:kUserId2];
183183
XCTAssertNotNil(userProfile2, @"User profile for userId 2 should not be removed.");
184184

185-
NSString *userProfile3 = [self.userProfileService lookup:kUserId3];
185+
NSDictionary *userProfile3 = [self.userProfileService lookup:kUserId3];
186186
XCTAssertNotNil(userProfile3, @"User profile for userId 3a should not be removed.");
187187

188188
NSDictionary *userData = [self.userProfileService.dataStore getUserDataForType:OPTLYDataStoreDataTypeUserProfileService];
@@ -196,10 +196,10 @@ - (void)testCleanUserExperimentRecords
196196
NSDictionary *userProfile1 = [self.userProfileService lookup:kUserId1];
197197
XCTAssertNil(userProfile1, @"User profile for userId 1 should have been removed.");
198198

199-
NSString *userProfile2 = [self.userProfileService lookup:kUserId2];
199+
NSDictionary *userProfile2 = [self.userProfileService lookup:kUserId2];
200200
XCTAssertNil(userProfile2, @"User profile for userId 2 should have been removed.");
201201

202-
NSString *userProfile3 = [self.userProfileService lookup:kUserId3];
202+
NSDictionary *userProfile3 = [self.userProfileService lookup:kUserId3];
203203
XCTAssertNil(userProfile3, @"User profile for userId 3 should have been removed.");
204204

205205
NSDictionary *userData = [self.userProfileService.dataStore getUserDataForType:OPTLYDataStoreDataTypeUserProfileService];
@@ -279,7 +279,10 @@ - (void)testLoggerDoesntCrashWhenAskedToSaveNilvalues {
279279
OPTLYUserProfileServiceDefault *userProfileService = [[OPTLYUserProfileServiceDefault alloc] init];
280280
[userProfileService removeAllUserExperimentRecords];
281281
XCTAssertNotNil(userProfileService);
282+
#pragma clang diagnostic push
283+
#pragma clang diagnostic ignored "-Wnonnull"
282284
[userProfileService save:nil];
285+
#pragma clang diagnostic pop
283286
XCTAssertEqual(0, [[userProfileService.dataStore getUserDataForType:OPTLYDataStoreDataTypeUserProfileService] count]);
284287
}
285288

@@ -319,7 +322,7 @@ - (void)testLegacyUserProfileMigration
319322
[self saveUserId:kUserId3 experimentId:kExperimentId3c variationId:kVariationId3c];
320323

321324
NSDictionary *legacyUserProfileData = [self.userProfileService.dataStore getUserDataForType:OPTLYDataStoreDataTypeUserProfile];
322-
XCTAssert([legacyUserProfileData count] == 3, @"Invalid number of legacy user profile entities saved: %@.", [legacyUserProfileData count]);
325+
XCTAssert([legacyUserProfileData count] == 3, @"Invalid number of legacy user profile entities saved: %@.", @([legacyUserProfileData count]));
323326
[self.userProfileService migrateLegacyUserProfileIfNeeded];
324327

325328
NSDictionary *newUserProfileDict1 = [self.userProfileService lookup:kUserId1];

0 commit comments

Comments
 (0)