FIRMessagingReceiverTest.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. #import <OCMock/OCMock.h>
  18. #import <FirebaseInstanceID/FirebaseInstanceID.h>
  19. #import "FIRMessaging.h"
  20. #import "FIRMessaging_Private.h"
  21. #import "FIRMessagingTestUtilities.h"
  22. NSString *const kFIRMessagingTestsReceiverSuiteName = @"com.messaging.test_receiverTest";
  23. @interface FIRMessagingReceiverTest : XCTestCase
  24. @property(nonatomic, readonly, strong) FIRMessaging *messaging;
  25. @end
  26. @implementation FIRMessagingReceiverTest
  27. - (void)setUp {
  28. [super setUp];
  29. NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:kFIRMessagingTestsReceiverSuiteName];
  30. _messaging = [FIRMessagingTestUtilities messagingForTestsWithUserDefaults:defaults];
  31. }
  32. - (void)tearDown {
  33. [self.messaging.messagingUserDefaults removePersistentDomainForName:kFIRMessagingTestsReceiverSuiteName];
  34. _messaging = nil;
  35. [super tearDown];
  36. }
  37. - (void)testUseMessagingDelegate {
  38. XCTAssertFalse(_messaging.useMessagingDelegateForDirectChannel);
  39. _messaging.useMessagingDelegateForDirectChannel = YES;
  40. XCTAssertTrue(_messaging.useMessagingDelegateForDirectChannel);
  41. }
  42. - (void)testUseMessagingDelegateFlagOverridedByPlistWithFalseValue {
  43. id bundleMock = OCMPartialMock([NSBundle mainBundle]);
  44. OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistUseMessagingDelegate])
  45. .andReturn(nil);
  46. XCTAssertFalse(_messaging.useMessagingDelegateForDirectChannel);
  47. [bundleMock stopMocking];
  48. }
  49. - (void)testUseMessagingDelegateFlagOverridedByPlistWithTrueValue {
  50. id bundleMock = OCMPartialMock([NSBundle mainBundle]);
  51. OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistUseMessagingDelegate])
  52. .andReturn(@YES);
  53. XCTAssertTrue(_messaging.useMessagingDelegateForDirectChannel);
  54. [bundleMock stopMocking];
  55. }
  56. @end