FIRAnalyticsConfigurationTest.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "FirebaseCore/Tests/Unit/FIRTestCase.h"
  17. #import "FirebaseCore/Sources/FIRAnalyticsConfiguration.h"
  18. @interface FIRAnalyticsConfigurationTest : FIRTestCase
  19. @property(nonatomic, strong) NSNotificationCenter *notificationCenter;
  20. @end
  21. @implementation FIRAnalyticsConfigurationTest
  22. - (void)setUp {
  23. [super setUp];
  24. _notificationCenter = [NSNotificationCenter defaultCenter];
  25. }
  26. - (void)tearDown {
  27. _notificationCenter = nil;
  28. [super tearDown];
  29. }
  30. /// Test access to the shared instance.
  31. - (void)testSharedInstance {
  32. FIRAnalyticsConfiguration *analyticsConfig = [FIRAnalyticsConfiguration sharedInstance];
  33. XCTAssertNotNil(analyticsConfig);
  34. }
  35. - (void)testSettingAnalyticsCollectionPersistence {
  36. id userDefaultsMock = OCMPartialMock([NSUserDefaults standardUserDefaults]);
  37. FIRAnalyticsConfiguration *config = [FIRAnalyticsConfiguration sharedInstance];
  38. // Test that defaults are written to when persistence is enabled.
  39. [config setAnalyticsCollectionEnabled:YES persistSetting:YES];
  40. OCMVerify([userDefaultsMock setObject:[NSNumber numberWithInteger:kFIRAnalyticsEnabledStateSetYes]
  41. forKey:kFIRAPersistedConfigMeasurementEnabledStateKey]);
  42. [config setAnalyticsCollectionEnabled:NO persistSetting:YES];
  43. OCMVerify([userDefaultsMock setObject:[NSNumber numberWithInteger:kFIRAnalyticsEnabledStateSetNo]
  44. forKey:kFIRAPersistedConfigMeasurementEnabledStateKey]);
  45. // Test that defaults are not written to when persistence is disabled.
  46. [config setAnalyticsCollectionEnabled:YES persistSetting:NO];
  47. OCMReject([userDefaultsMock setObject:OCMOCK_ANY
  48. forKey:kFIRAPersistedConfigMeasurementEnabledStateKey]);
  49. [config setAnalyticsCollectionEnabled:NO persistSetting:NO];
  50. OCMReject([userDefaultsMock setObject:OCMOCK_ANY
  51. forKey:kFIRAPersistedConfigMeasurementEnabledStateKey]);
  52. [userDefaultsMock stopMocking];
  53. }
  54. @end