FIRMessagingTestUtilities.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2019 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 "FIRMessagingTestUtilities.h"
  17. #import <FirebaseAnalyticsInterop/FIRAnalyticsInterop.h>
  18. #import <FirebaseInstanceID/FirebaseInstanceID.h>
  19. NS_ASSUME_NONNULL_BEGIN
  20. @interface FIRInstanceID (ExposedForTest)
  21. /// Private initializer to avoid singleton usage.
  22. - (FIRInstanceID *)initPrivately;
  23. /// Starts fetching and configuration of InstanceID. This is necessary after the `initPrivately`
  24. /// call.
  25. - (void)start;
  26. @end
  27. @interface FIRMessaging (ExposedForTest)
  28. /// Surface internal initializer to avoid singleton usage during tests.
  29. - (instancetype)initWithAnalytics:(nullable id<FIRAnalyticsInterop>)analytics
  30. withInstanceID:(FIRInstanceID *)instanceID
  31. withUserDefaults:(NSUserDefaults *)defaults;
  32. /// Kicks off required calls for some messaging tests.
  33. - (void)start;
  34. @end
  35. @implementation FIRMessagingTestUtilities
  36. + (FIRMessaging *)messagingForTestsWithUserDefaults:(NSUserDefaults *)userDefaults {
  37. // Create the messaging instance with all the necessary dependencies.
  38. FIRInstanceID *instanceID = [[FIRInstanceID alloc] initPrivately];
  39. [instanceID start];
  40. // Create the messaging instance and call `start`.
  41. FIRMessaging *messaging = [[FIRMessaging alloc] initWithAnalytics:nil
  42. withInstanceID:instanceID
  43. withUserDefaults:userDefaults];
  44. [messaging start];
  45. return messaging;
  46. }
  47. @end
  48. NS_ASSUME_NONNULL_END