Skip to content

Commit a367b09

Browse files
committed
Replaced OCMockito by OCMock for unit testing.
1 parent 545994e commit a367b09

File tree

10 files changed

+103
-85
lines changed

10 files changed

+103
-85
lines changed

ios/RCTAzureNotificationHubManager/RCTAzureNotificationHubManager.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
@interface RCTAzureNotificationHubManager : RCTEventEmitter
1313

1414
// Required to register for notifications, invoked from AppDelegate
15-
+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
15+
+ (void)didRegisterUserNotificationSettings:(nonnull UIUserNotificationSettings *)notificationSettings;
1616

1717
// Required for the register event, invoked from AppDelegate
18-
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
18+
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(nonnull NSData *)deviceToken;
1919

2020
// Required for the notification event, invoked from AppDelegate
21-
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification;
21+
+ (void)didReceiveRemoteNotification:(nonnull NSDictionary *)notification;
2222

2323
// Required for the localNotification event, invoked from AppDelegate
24-
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification;
24+
+ (void)didReceiveLocalNotification:(nonnull UILocalNotification *)notification;
2525

2626
// Required for the registrationError event, invoked from AppDelegate
27-
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
27+
+ (void)didFailToRegisterForRemoteNotificationsWithError:(nonnull NSError *)error;
2828

2929
// Register with Azure Notification Hub
3030
- (void)register:(nonnull NSString *)deviceToken

ios/RCTAzureNotificationHubManager/RCTAzureNotificationHubManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ - (bool)assertArguments:(RCTPromiseRejectBlock)reject
119119
return true;
120120
}
121121

122-
+ (void)didRegisterUserNotificationSettings:(__unused UIUserNotificationSettings *)notificationSettings
122+
+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
123123
{
124124
if ([UIApplication instancesRespondToSelector:@selector(registerForRemoteNotifications)])
125125
{

ios/RCTAzureNotificationHubManager/RCTAzureNotificationHubUtil.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
@interface RCTAzureNotificationHubUtil : NSObject
1414

1515
// Format local notification
16-
+ (NSDictionary *)formatLocalNotification:(nonnull UILocalNotification *)notification;
16+
+ (nonnull NSDictionary *)formatLocalNotification:(nonnull UILocalNotification *)notification;
1717

1818
// Create Azure Notification Hub
19-
+ (SBNotificationHub *)createAzureNotificationHub:(nonnull NSString *)connectionString
20-
hubName:(nonnull NSString *)hubName;
19+
+ (nonnull SBNotificationHub *)createAzureNotificationHub:(nonnull NSString *)connectionString
20+
hubName:(nonnull NSString *)hubName;
2121

2222
// Convert device token to string
23-
+ (NSString *)convertDeviceTokenToString:(nonnull NSData *)deviceToken;
23+
+ (nonnull NSString *)convertDeviceTokenToString:(nonnull NSData *)deviceToken;
2424

2525
// Get notification types with permissions
2626
+ (UIUserNotificationType)getNotificationTypesWithPermissions:(nullable NSDictionary *)permissions;

ios/RCTAzureNotificationHubManager/RCTAzureNotificationHubUtil.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@implementation RCTAzureNotificationHubUtil
1717

1818
// Format local notification
19-
+ (NSDictionary *)formatLocalNotification:(nonnull UILocalNotification *)notification
19+
+ (nonnull NSDictionary *)formatLocalNotification:(nonnull UILocalNotification *)notification
2020
{
2121
NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];
2222
if (notification.fireDate)
@@ -38,8 +38,8 @@ + (NSDictionary *)formatLocalNotification:(nonnull UILocalNotification *)notific
3838
}
3939

4040
// Create Azure Notification Hub
41-
+ (SBNotificationHub *)createAzureNotificationHub:(nonnull NSString *)connectionString
42-
hubName:(nonnull NSString *)hubName
41+
+ (nonnull SBNotificationHub *)createAzureNotificationHub:(nonnull NSString *)connectionString
42+
hubName:(nonnull NSString *)hubName
4343
{
4444
SBNotificationHub *hub = [[SBNotificationHub alloc] initWithConnectionString:connectionString
4545
notificationHubPath:hubName];
@@ -48,7 +48,7 @@ + (SBNotificationHub *)createAzureNotificationHub:(nonnull NSString *)connection
4848
}
4949

5050
// Convert device token to string
51-
+ (NSString *)convertDeviceTokenToString:(nonnull NSData *)deviceToken
51+
+ (nonnull NSString *)convertDeviceTokenToString:(nonnull NSData *)deviceToken
5252
{
5353
NSMutableString *hexString = [NSMutableString string];
5454
NSUInteger deviceTokenLength = deviceToken.length;

sample/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ target 'ReactNativeAzureNotificationHubSample' do
3838
target 'ReactNativeAzureNotificationHubSampleTests' do
3939
inherit! :search_paths
4040
use_frameworks!
41-
pod 'OCMockito', '~> 5.0'
41+
pod 'OCMock', '~> 3.6'
4242
end
4343

4444
use_native_modules!

sample/ios/Podfile.lock

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ PODS:
1919
- DoubleConversion
2020
- glog
2121
- glog (0.3.5)
22-
- OCHamcrest (7.1.2)
23-
- OCMockito (5.1.3):
24-
- OCHamcrest (~> 7.0)
22+
- OCMock (3.6)
2523
- RCTRequired (0.61.5)
2624
- RCTTypeSafety (0.61.5):
2725
- FBLazyVector (= 0.61.5)
@@ -232,7 +230,7 @@ DEPENDENCIES:
232230
- FBReactNativeSpec (from `../node_modules/react-native/Libraries/FBReactNativeSpec`)
233231
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
234232
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
235-
- OCMockito (~> 5.0)
233+
- OCMock (~> 3.6)
236234
- RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`)
237235
- RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`)
238236
- React (from `../node_modules/react-native/`)
@@ -261,8 +259,7 @@ DEPENDENCIES:
261259
SPEC REPOS:
262260
trunk:
263261
- boost-for-react-native
264-
- OCHamcrest
265-
- OCMockito
262+
- OCMock
266263
- WindowsAzureMessaging
267264

268265
EXTERNAL SOURCES:
@@ -326,8 +323,7 @@ SPEC CHECKSUMS:
326323
FBReactNativeSpec: 118d0d177724c2d67f08a59136eb29ef5943ec75
327324
Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51
328325
glog: 1f3da668190260b06b429bb211bfbee5cd790c28
329-
OCHamcrest: b284c9592c28c1e4025a8542e67ea41a635d0d73
330-
OCMockito: 677cbb4a18fd492b5a4fb10144dada4de5ddb877
326+
OCMock: 5ea90566be239f179ba766fd9fbae5885040b992
331327
RCTRequired: b153add4da6e7dbc44aebf93f3cf4fcae392ddf1
332328
RCTTypeSafety: 9aa1b91d7f9310fc6eadc3cf95126ffe818af320
333329
React: b6a59ef847b2b40bb6e0180a97d0ca716969ac78
@@ -351,6 +347,6 @@ SPEC CHECKSUMS:
351347
WindowsAzureMessaging: 3ec1c2ca507508e9595c34f6cf977e0c447fdd87
352348
Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b
353349

354-
PODFILE CHECKSUM: 3bd107b800d9b730589c7cb3495c1b265771f49f
350+
PODFILE CHECKSUM: 7bea7f3c6021bc946076bfddd71ac33f227e9bf2
355351

356-
COCOAPODS: 1.8.3
352+
COCOAPODS: 1.8.4

sample/ios/ReactNativeAzureNotificationHubSample.xcodeproj/project.pbxproj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
2D02E4901E0B4A5D006451C7 /* ReactNativeAzureNotificationHubSample-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ReactNativeAzureNotificationHubSample-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
5656
3AAB39D4BDBE7F53EC74C4C4 /* libPods-ReactNativeAzureNotificationHubSample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNativeAzureNotificationHubSample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
5757
3B18387DF86E68D789995173 /* Pods-ReactNativeAzureNotificationHubSample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeAzureNotificationHubSample.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeAzureNotificationHubSample/Pods-ReactNativeAzureNotificationHubSample.release.xcconfig"; sourceTree = "<group>"; };
58-
45E30B45240821F000A339F1 /* RCTAzureNotificationHubManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAzureNotificationHubManagerTests.m; sourceTree = "<group>"; };
59-
45E30B46240821F000A339F1 /* RCTAzureNotificationHubUtilTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAzureNotificationHubUtilTests.m; sourceTree = "<group>"; };
60-
45E30B47240821F100A339F1 /* RCTAzureNotificationHandlerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAzureNotificationHandlerTests.m; sourceTree = "<group>"; };
58+
45E30B45240821F000A339F1 /* RCTAzureNotificationHubManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAzureNotificationHubManagerTests.m; sourceTree = "<group>"; tabWidth = 4; };
59+
45E30B46240821F000A339F1 /* RCTAzureNotificationHubUtilTests.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAzureNotificationHubUtilTests.m; sourceTree = "<group>"; tabWidth = 4; };
60+
45E30B47240821F100A339F1 /* RCTAzureNotificationHandlerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAzureNotificationHandlerTests.m; sourceTree = "<group>"; tabWidth = 4; };
6161
C492EEB6FD7BE2BA8DC1EA48 /* Pods-ReactNativeAzureNotificationHubSampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeAzureNotificationHubSampleTests.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeAzureNotificationHubSampleTests/Pods-ReactNativeAzureNotificationHubSampleTests.debug.xcconfig"; sourceTree = "<group>"; };
6262
D66D2E73969F49ECF06FE6B3 /* Pods_ReactNativeAzureNotificationHubSampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ReactNativeAzureNotificationHubSampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6363
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
@@ -426,13 +426,11 @@
426426
);
427427
inputPaths = (
428428
"${PODS_ROOT}/Target Support Files/Pods-ReactNativeAzureNotificationHubSampleTests/Pods-ReactNativeAzureNotificationHubSampleTests-frameworks.sh",
429-
"${BUILT_PRODUCTS_DIR}/OCHamcrest/OCHamcrest.framework",
430-
"${BUILT_PRODUCTS_DIR}/OCMockito/OCMockito.framework",
429+
"${BUILT_PRODUCTS_DIR}/OCMock/OCMock.framework",
431430
);
432431
name = "[CP] Embed Pods Frameworks";
433432
outputPaths = (
434-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OCHamcrest.framework",
435-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OCMockito.framework",
433+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OCMock.framework",
436434
);
437435
runOnlyForDeploymentPostprocessing = 0;
438436
shellPath = /bin/sh;

sample/ios/ReactNativeAzureNotificationHubSampleTests/RCTAzureNotificationHandlerTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <RNAzureNotificationHub/RCTAzureNotificationHub.h>
1010
#import <RNAzureNotificationHub/RCTAzureNotificationHubManager.h>
1111

12-
@import OCMockito;
12+
@import OCMock;
1313

1414
@interface RCTAzureNotificationHandlerTests : XCTestCase
1515
@end
@@ -18,7 +18,7 @@ @implementation RCTAzureNotificationHandlerTests
1818

1919
- (void)setUp
2020
{
21-
[super setUp];
21+
[super setUp];
2222
}
2323

2424
@end

sample/ios/ReactNativeAzureNotificationHubSampleTests/RCTAzureNotificationHubManagerTests.m

Lines changed: 73 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,80 +6,104 @@
66
*/
77

88
#import <XCTest/XCTest.h>
9+
#import <WindowsAzureMessaging/WindowsAzureMessaging.h>
10+
911
#import <RNAzureNotificationHub/RCTAzureNotificationHub.h>
1012
#import <RNAzureNotificationHub/RCTAzureNotificationHubManager.h>
13+
#import <RNAzureNotificationHub/RCTAzureNotificationHubUtil.h>
1114

12-
@import OCMockito;
15+
@import OCMock;
1316

1417
@interface RCTAzureNotificationHubManagerTests : XCTestCase
1518
@end
1619

1720
@implementation RCTAzureNotificationHubManagerTests
1821
{
19-
RCTAzureNotificationHubManager *hubManager;
20-
NSMutableDictionary *config;
21-
RCTPromiseResolveBlock resolver;
22-
RCTPromiseRejectBlock rejecter;
22+
@private
23+
RCTAzureNotificationHubManager *_hubManager;
24+
NSMutableDictionary *_config;
25+
RCTPromiseResolveBlock _resolver;
26+
RCTPromiseRejectBlock _rejecter;
27+
id _hub;
28+
id _hubUtilClass;
2329
}
2430

2531
- (void)setUp
2632
{
27-
[super setUp];
28-
hubManager = [[RCTAzureNotificationHubManager alloc] init];
29-
config = [[NSMutableDictionary alloc] init];
30-
resolver = ^(id result) {};
31-
rejecter = ^(NSString *code, NSString *message, NSError *error) {};
33+
[super setUp];
34+
_hubManager = [[RCTAzureNotificationHubManager alloc] init];
35+
_config = [[NSMutableDictionary alloc] init];
36+
_resolver = ^(id result) {};
37+
_rejecter = ^(NSString *code, NSString *message, NSError *error) {};
38+
39+
_hub = OCMClassMock([SBNotificationHub class]);
40+
_hubUtilClass = OCMClassMock([RCTAzureNotificationHubUtil class]);
41+
OCMStub([_hubUtilClass createAzureNotificationHub:OCMOCK_ANY
42+
hubName:OCMOCK_ANY]).andReturn(_hub);
3243
}
3344

3445
- (void)testRegisterNoConnectionString
3546
{
36-
__block NSString *errorMsg;
37-
rejecter = ^(NSString *code, NSString *message, NSError *error)
38-
{
39-
errorMsg = message;
40-
};
41-
42-
[hubManager register:@""
43-
config:config
44-
resolver:resolver
45-
rejecter:rejecter];
46-
47-
XCTAssertEqualObjects(errorMsg, RCTErrorMissingConnectionString);
47+
__block NSString *errorMsg;
48+
_rejecter = ^(NSString *code, NSString *message, NSError *error)
49+
{
50+
errorMsg = message;
51+
};
52+
53+
[_hubManager register:@""
54+
config:_config
55+
resolver:_resolver
56+
rejecter:_rejecter];
57+
58+
XCTAssertEqualObjects(errorMsg, RCTErrorMissingConnectionString);
4859
}
4960

5061
- (void)testRegisterNoHubName
5162
{
52-
__block NSString *errorMsg;
53-
rejecter = ^(NSString *code, NSString *message, NSError *error)
54-
{
55-
errorMsg = message;
56-
};
57-
58-
[config setObject:@"Connection String" forKey:@"connectionString"];
59-
[hubManager register:@""
60-
config:config
61-
resolver:resolver
62-
rejecter:rejecter];
63-
64-
XCTAssertEqualObjects(errorMsg, RCTErrorMissingHubName);
63+
__block NSString *errorMsg;
64+
_rejecter = ^(NSString *code, NSString *message, NSError *error)
65+
{
66+
errorMsg = message;
67+
};
68+
69+
[_config setObject:@"Connection String"
70+
forKey:@"connectionString"];
71+
72+
[_hubManager register:@""
73+
config:_config
74+
resolver:_resolver
75+
rejecter:_rejecter];
76+
77+
XCTAssertEqualObjects(errorMsg, RCTErrorMissingHubName);
6578
}
6679

6780
- (void)testRegisterSuccessfully
6881
{
69-
__block bool hasError = false;
70-
rejecter = ^(NSString *code, NSString *message, NSError *error)
71-
{
72-
hasError = true;
73-
};
74-
75-
[config setObject:@"Connection String" forKey:@"connectionString"];
76-
[config setObject:@"Hub Name" forKey:@"hubName"];
77-
[hubManager register:@""
78-
config:config
79-
resolver:resolver
80-
rejecter:rejecter];
81-
82-
XCTAssertEqual(hasError, false);
82+
__block bool hasError = false;
83+
_rejecter = ^(NSString *code, NSString *message, NSError *error)
84+
{
85+
hasError = true;
86+
};
87+
88+
[_config setObject:@"Connection String" forKey:@"connectionString"];
89+
[_config setObject:@"Hub Name" forKey:@"hubName"];
90+
91+
OCMExpect([_hubUtilClass createAzureNotificationHub:OCMOCK_ANY
92+
hubName:OCMOCK_ANY]);
93+
94+
OCMExpect([_hub registerNativeWithDeviceToken:OCMOCK_ANY
95+
tags:OCMOCK_ANY
96+
completion:OCMOCK_ANY]);
97+
98+
[_hubManager register:@""
99+
config:_config
100+
resolver:_resolver
101+
rejecter:_rejecter];
102+
103+
XCTAssertEqual(hasError, false);
104+
OCMVerify([_hubUtilClass createAzureNotificationHub:OCMOCK_ANY
105+
hubName:OCMOCK_ANY]);
106+
OCMVerifyAllWithDelay(_hub, 0.5);
83107
}
84108

85109
@end

sample/ios/ReactNativeAzureNotificationHubSampleTests/RCTAzureNotificationHubUtilTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <RNAzureNotificationHub/RCTAzureNotificationHub.h>
1010
#import <RNAzureNotificationHub/RCTAzureNotificationHubManager.h>
1111

12-
@import OCMockito;
12+
@import OCMock;
1313

1414
@interface RCTAzureNotificationHubUtilTests : XCTestCase
1515
@end
@@ -18,7 +18,7 @@ @implementation RCTAzureNotificationHubUtilTests
1818

1919
- (void)setUp
2020
{
21-
[super setUp];
21+
[super setUp];
2222
}
2323

2424
@end

0 commit comments

Comments
 (0)