FIRMockInstallations.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "Crashlytics/UnitTests/Mocks/FIRMockInstallations.h"
  15. #import <Foundation/Foundation.h>
  16. @interface FIRMockInstallationsImpl : NSObject
  17. @property(nonatomic, copy) NSString *installationID;
  18. @property(nonatomic, strong) NSError *error;
  19. // the init function is not public for the token result, use as a placeholder to mock the token
  20. // completion block
  21. @property(nonatomic, strong) FIRInstallationsAuthTokenResult *tokenResult;
  22. @property(nonatomic) BOOL authTokenFinished;
  23. @property(nonatomic) BOOL installationIDFinished;
  24. @end
  25. @implementation FIRMockInstallationsImpl
  26. - (void)authTokenWithCompletion:(FIRInstallationsTokenHandler)completion {
  27. self.authTokenFinished = true;
  28. completion(self.tokenResult, self.error);
  29. }
  30. - (void)installationIDWithCompletion:(FIRInstallationsIDHandler)completion {
  31. self.installationIDFinished = true;
  32. completion(self.installationID, self.error);
  33. }
  34. @end
  35. @interface FIRMockInstallations ()
  36. @end
  37. @implementation FIRMockInstallations
  38. - (instancetype)initWithFID:(NSString *)installationID {
  39. FIRMockInstallationsImpl *mock = [[FIRMockInstallationsImpl alloc] init];
  40. mock.installationID = [installationID copy];
  41. mock.error = nil;
  42. mock.authTokenFinished = false;
  43. mock.installationIDFinished = false;
  44. self = (id)mock;
  45. return self;
  46. }
  47. - (instancetype)initWithError:(NSError *)error {
  48. FIRMockInstallationsImpl *mock = [[FIRMockInstallationsImpl alloc] init];
  49. mock.installationID = nil;
  50. mock.error = error;
  51. mock.authTokenFinished = false;
  52. mock.installationIDFinished = false;
  53. self = (id)mock;
  54. return self;
  55. }
  56. @end