FIRBundleUtilTest.m 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2017 Google
  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 "FIRBundleUtil.h"
  15. #import "FIRTestCase.h"
  16. static NSString *const kResultPath = @"resultPath";
  17. static NSString *const kResourceName = @"resourceName";
  18. static NSString *const kFileType = @"fileType";
  19. @interface FIRBundleUtilTest : FIRTestCase
  20. @property(nonatomic, strong) id mockBundle;
  21. @end
  22. @implementation FIRBundleUtilTest
  23. - (void)setUp {
  24. [super setUp];
  25. self.mockBundle = OCMClassMock([NSBundle class]);
  26. }
  27. - (void)testRelevantBundles_mainIsFirst {
  28. // Pointer compare to same instance of main bundle.
  29. XCTAssertEqual([NSBundle mainBundle], [FIRBundleUtil relevantBundles][0]);
  30. }
  31. // TODO: test that adding a bundle appears in "all bundles"
  32. // once the use-case is understood.
  33. - (void)testFindOptionsDictionaryPath {
  34. [OCMStub([self.mockBundle pathForResource:kResourceName ofType:kFileType]) andReturn:kResultPath];
  35. XCTAssertEqualObjects(
  36. [FIRBundleUtil optionsDictionaryPathWithResourceName:kResourceName
  37. andFileType:kFileType
  38. inBundles:@[ self.mockBundle ]],
  39. kResultPath);
  40. }
  41. - (void)testFindOptionsDictionaryPath_notFound {
  42. XCTAssertNil([FIRBundleUtil optionsDictionaryPathWithResourceName:kResourceName
  43. andFileType:kFileType
  44. inBundles:@[ self.mockBundle ]]);
  45. }
  46. - (void)testFindOptionsDictionaryPath_secondBundle {
  47. NSBundle *mockBundleEmpty = OCMClassMock([NSBundle class]);
  48. [OCMStub([self.mockBundle pathForResource:kResourceName ofType:kFileType]) andReturn:kResultPath];
  49. NSArray *bundles = @[ mockBundleEmpty, self.mockBundle ];
  50. XCTAssertEqualObjects(
  51. [FIRBundleUtil optionsDictionaryPathWithResourceName:kResourceName
  52. andFileType:kFileType
  53. inBundles:bundles],
  54. kResultPath);
  55. }
  56. - (void)testBundleIdentifierExistsInBundles {
  57. NSString *bundleID = @"com.google.test";
  58. [OCMStub([self.mockBundle bundleIdentifier]) andReturn:bundleID];
  59. XCTAssertTrue([FIRBundleUtil hasBundleIdentifier:bundleID inBundles:@[ self.mockBundle ]]);
  60. }
  61. - (void)testBundleIdentifierExistsInBundles_notExist {
  62. [OCMStub([self.mockBundle bundleIdentifier]) andReturn:@"com.google.test"];
  63. XCTAssertFalse([FIRBundleUtil hasBundleIdentifier:@"not-exist" inBundles:@[ self.mockBundle ]]);
  64. }
  65. - (void)testBundleIdentifierExistsInBundles_emptyBundlesArray {
  66. XCTAssertFalse([FIRBundleUtil hasBundleIdentifier:@"com.google.test" inBundles:@[ ]]);
  67. }
  68. @end