FIRMessagingReceiverTest.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. @interface FIRMessaging ()
  22. + (FIRMessaging *)messagingForTests;
  23. @end
  24. @interface FIRMessagingReceiverTest : XCTestCase
  25. @property(nonatomic, readonly, strong) FIRMessaging *messaging;
  26. @end
  27. @implementation FIRMessagingReceiverTest
  28. - (void)setUp {
  29. [super setUp];
  30. _messaging = [FIRMessaging messagingForTests];
  31. [[NSUserDefaults standardUserDefaults]
  32. removePersistentDomainForName:[NSBundle mainBundle].bundleIdentifier];
  33. }
  34. - (void)testUseMessagingDelegate {
  35. XCTAssertFalse(_messaging.useMessagingDelegateForDirectChannel);
  36. _messaging.useMessagingDelegateForDirectChannel = YES;
  37. XCTAssertTrue(_messaging.useMessagingDelegateForDirectChannel);
  38. }
  39. - (void)testUseMessagingDelegateFlagOverridedByPlistWithFalseValue {
  40. id bundleMock = OCMPartialMock([NSBundle mainBundle]);
  41. OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistUseMessagingDelegate])
  42. .andReturn(nil);
  43. XCTAssertFalse(_messaging.useMessagingDelegateForDirectChannel);
  44. [bundleMock stopMocking];
  45. }
  46. - (void)testUseMessagingDelegateFlagOverridedByPlistWithTrueValue {
  47. id bundleMock = OCMPartialMock([NSBundle mainBundle]);
  48. OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistUseMessagingDelegate])
  49. .andReturn(@YES);
  50. XCTAssertTrue(_messaging.useMessagingDelegateForDirectChannel);
  51. [bundleMock stopMocking];
  52. }
  53. @end