summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2020-07-07 09:03:54 -0400
committerNicoleYarroch <nicole@livio.io>2020-07-07 09:03:54 -0400
commita998d19896baef76b488cd558551e40378df5e86 (patch)
treeeda1ba978d5529ae7978e73b8c3b589e968dde97
parent50917b55960baaadda408ff6ea6947b3e1dd6631 (diff)
downloadsdl_ios-a998d19896baef76b488cd558551e40378df5e86.tar.gz
Added additional tests
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r--SmartDeviceLinkTests/SDLSubscribeButtonManagerSpec.m28
1 files changed, 26 insertions, 2 deletions
diff --git a/SmartDeviceLinkTests/SDLSubscribeButtonManagerSpec.m b/SmartDeviceLinkTests/SDLSubscribeButtonManagerSpec.m
index ccf8dd33d..dd66c82d3 100644
--- a/SmartDeviceLinkTests/SDLSubscribeButtonManagerSpec.m
+++ b/SmartDeviceLinkTests/SDLSubscribeButtonManagerSpec.m
@@ -68,14 +68,24 @@ describe(@"subscribe button manager", ^{
it(@"should instantiate correctly with initWithConnectionManager:", ^{
expect(testManager.connectionManager).to(equal(testConnectionManager));
expect(testManager.subscribeButtonObservers).toNot(beNil());
+ expect(testManager.subscribeButtonObservers.count).to(equal(0));
});
it(@"should do nothing when Start is called", ^{
[testManager start];
+
+ expect(testManager.subscribeButtonObservers).toNot(beNil());
+ expect(testManager.subscribeButtonObservers.count).to(equal(0));
});
- it(@"should clear the list of observers when Stop is called", ^{
+ it(@"should clear (but not destroy) the list of observers when Stop is called", ^{
+ SDLSubscribeButtonUpdateHandler testUpdateBlock = ^(SDLOnButtonPress *_Nullable buttonPress, SDLOnButtonEvent *_Nullable buttonEvent, NSError *_Nullable error) {};
+ testManager.subscribeButtonObservers[SDLButtonNameTuneUp] = [NSMutableArray arrayWithObject:[[SDLSubscribeButtonObserver alloc] initWithObserver:[[NSObject alloc] init] updateHandler:testUpdateBlock]];
+ expect(testManager.subscribeButtonObservers.count).to(equal(1));
+
[testManager stop];
+
+ expect(testManager.subscribeButtonObservers).toNot(beNil());
expect(testManager.subscribeButtonObservers.count).to(equal(0));
});
});
@@ -134,7 +144,7 @@ describe(@"subscribe button manager", ^{
expect(testConnectionManager.receivedRequests[0]).toEventually(beAKindOf(SDLSubscribeButton.class));
});
- it(@"should send two subscription request for the same button name to the module if the second request is sent before the module responsed to the first request and it should add both observers even though the second request will fail", ^{
+ it(@"should send two subscription request for the same button name to the module if the second request is sent before the module responds to the first request and it should add both observers if the second request fails with a result code of IGNORED", ^{
id subscriptionID1 = [testManager subscribeButton:testButtonName withUpdateHandler:testUpdateHandler1];
id subscriptionID2 = [testManager subscribeButton:testButtonName withUpdateHandler:testUpdateHandler2];
expect(subscriptionID1).toNot(beNil());
@@ -253,6 +263,20 @@ describe(@"subscribe button manager", ^{
expect(testConnectionManager.receivedRequests.count).to(equal(0));
});
+
+ it(@"should ignore a subscription attempt with an nil observer", ^{
+ SEL testValidSelector = @selector(buttonPressEventWithButtonName:error:);
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wnonnull"
+ [testManager subscribeButton:testButtonName withObserver:nil selector:testValidSelector];
+#pragma GCC diagnostic pop
+
+ NSArray<SDLSubscribeButtonObserver *> *observers = testManager.subscribeButtonObservers[testButtonName];
+ expect(observers).to(beNil());
+
+ expect(testConnectionManager.receivedRequests.count).to(equal(0));
+ });
});
describe(@"notifing subscribers of button events", ^{