|
17 | 17 | #import <FirebaseCore/FIRAppInternal.h>
|
18 | 18 | #import <FirebaseCore/FIRComponent.h>
|
19 | 19 | #import <FirebaseCore/FIRComponentContainerInternal.h>
|
| 20 | +#import <FirebaseCore/FIROptions.h> |
20 | 21 |
|
21 | 22 | #import "FIRTestComponents.h"
|
22 | 23 |
|
@@ -49,12 +50,19 @@ - (instancetype)initWithApp:(FIRApp *)app
|
49 | 50 |
|
50 | 51 | @end
|
51 | 52 |
|
52 |
| -@interface FIRComponentContainerTest : FIRTestCase |
| 53 | +@interface FIRComponentContainerTest : FIRTestCase { |
| 54 | + FIRApp *_hostApp; |
| 55 | +} |
53 | 56 |
|
54 | 57 | @end
|
55 | 58 |
|
56 | 59 | @implementation FIRComponentContainerTest
|
57 | 60 |
|
| 61 | +- (void)tearDown { |
| 62 | + _hostApp = nil; |
| 63 | + [super tearDown]; |
| 64 | +} |
| 65 | + |
58 | 66 | #pragma mark - Registration Tests
|
59 | 67 |
|
60 | 68 | - (void)testRegisteringConformingClass {
|
@@ -101,7 +109,8 @@ - (void)testInstanceNotCached {
|
101 | 109 | - (void)testRemoveAllCachedInstances {
|
102 | 110 | FIRComponentContainer *container =
|
103 | 111 | [self containerWithRegistrants:@ [[FIRTestClass class], [FIRTestClassCached class],
|
104 |
| - [FIRTestClassEagerCached class]]]; |
| 112 | + [FIRTestClassEagerCached class], |
| 113 | + [FIRTestClassCachedWithDep class]]]; |
105 | 114 |
|
106 | 115 | // Retrieve an instance of FIRTestClassCached to ensure it's cached.
|
107 | 116 | id<FIRTestProtocolCached> cachedInstance1 = FIR_COMPONENT(FIRTestProtocolCached, container);
|
@@ -148,18 +157,57 @@ - (void)testProtocolAlreadyRegistered {
|
148 | 157 | XCTAssert(container.components.count == 1);
|
149 | 158 | }
|
150 | 159 |
|
| 160 | +#pragma mark - Dependency Tests |
| 161 | + |
| 162 | +- (void)testDependencyDoesntBlock { |
| 163 | + /// Test a class that has a dependency, and fetching doesn't block the internal queue. |
| 164 | + FIRComponentContainer *container = [self |
| 165 | + containerWithRegistrants:@ [[FIRTestClassCached class], [FIRTestClassCachedWithDep class]]]; |
| 166 | + XCTAssert(container.components.count == 2); |
| 167 | + |
| 168 | + id<FIRTestProtocolCachedWithDep> instanceWithDep = |
| 169 | + FIR_COMPONENT(FIRTestProtocolCachedWithDep, container); |
| 170 | + XCTAssertNotNil(instanceWithDep); |
| 171 | +} |
| 172 | + |
| 173 | +- (void)testDependencyRemoveAllCachedInstancesDoesntBlock { |
| 174 | + /// Test a class that has a dependency, and fetching doesn't block the internal queue. |
| 175 | + FIRComponentContainer *container = [self |
| 176 | + containerWithRegistrants:@ [[FIRTestClassCached class], [FIRTestClassCachedWithDep class]]]; |
| 177 | + XCTAssert(container.components.count == 2); |
| 178 | + |
| 179 | + id<FIRTestProtocolCachedWithDep> instanceWithDep = |
| 180 | + FIR_COMPONENT(FIRTestProtocolCachedWithDep, container); |
| 181 | + XCTAssertNotNil(instanceWithDep); |
| 182 | + XCTAssertNotNil(instanceWithDep.testProperty); |
| 183 | + |
| 184 | + // Both `instanceWithDep` and `testProperty` should be cached now. |
| 185 | + XCTAssertTrue(container.cachedInstances.count == 2); |
| 186 | + |
| 187 | + // Remove the instances and verify cachedInstances is empty, and doesn't block the queue. |
| 188 | + [container removeAllCachedInstances]; |
| 189 | + XCTAssertTrue(container.cachedInstances.count == 0); |
| 190 | +} |
| 191 | + |
151 | 192 | #pragma mark - Convenience Methods
|
152 | 193 |
|
153 | 194 | /// Create a container that has registered the test class.
|
154 | 195 | - (FIRComponentContainer *)containerWithRegistrants:(NSArray<Class> *)registrants {
|
155 |
| - id appMock = OCMClassMock([FIRApp class]); |
| 196 | + FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:kGoogleAppID |
| 197 | + GCMSenderID:kGCMSenderID]; |
| 198 | + _hostApp = [[FIRApp alloc] initInstanceWithName:@"fake_app" options:options]; |
156 | 199 | NSMutableSet<Class> *allRegistrants = [NSMutableSet<Class> set];
|
157 | 200 |
|
158 | 201 | // Initialize the container with the test classes.
|
159 | 202 | for (Class c in registrants) {
|
160 | 203 | [FIRComponentContainer registerAsComponentRegistrant:c inSet:allRegistrants];
|
161 | 204 | }
|
162 |
| - return [[FIRComponentContainer alloc] initWithApp:appMock registrants:allRegistrants]; |
| 205 | + |
| 206 | + // Override the app's container with the newly instantiated container. |
| 207 | + FIRComponentContainer *container = [[FIRComponentContainer alloc] initWithApp:_hostApp |
| 208 | + registrants:allRegistrants]; |
| 209 | + _hostApp.container = container; |
| 210 | + return container; |
163 | 211 | }
|
164 | 212 |
|
165 | 213 | @end
|
0 commit comments