Skip to content

Commit c40ea1f

Browse files
committed
review feedback and test adjustment
1 parent 6065003 commit c40ea1f

File tree

3 files changed

+45
-40
lines changed

3 files changed

+45
-40
lines changed

Example/Core/Tests/FIRComponentContainerTest.m

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,26 @@ @interface FIRComponentContainer (TestInternal)
2727
@property(nonatomic, strong) NSMutableDictionary<NSString *, id> *cachedInstances;
2828

2929
+ (void)registerAsComponentRegistrant:(Class)klass inSet:(NSMutableSet<Class> *)allRegistrants;
30-
3130
- (instancetype)initWithApp:(FIRApp *)app registrants:(NSMutableSet<Class> *)allRegistrants;
31+
+ (void)setRegistrantSet:(NSMutableSet<Class> *)testInput;
32+
+ (NSMutableSet<Class> *)registrantSet;
33+
@end
34+
35+
@interface FIRComponentContainer (TestInternalImplementations)
36+
- (instancetype)initWithApp:(FIRApp *)app
37+
components:(NSDictionary<NSString *, FIRComponentCreationBlock> *)components;
38+
@end
39+
40+
@implementation FIRComponentContainer (TestInternalImplementations)
41+
42+
- (instancetype)initWithApp:(FIRApp *)app
43+
components:(NSDictionary<NSString *, FIRComponentCreationBlock> *)components {
44+
self = [self initWithApp:app registrants:[[NSMutableSet alloc] init]];
45+
if (self) {
46+
components = [components mutableCopy];
47+
}
48+
return self;
49+
}
3250

3351
@end
3452

@@ -41,10 +59,10 @@ @implementation FIRComponentContainerTest
4159
#pragma mark - Registration Tests
4260

4361
- (void)testRegisteringConformingClass {
44-
NSMutableSet<Class> *allRegistrants = [NSMutableSet<Class> set];
62+
[FIRComponentContainer setRegistrantSet:[NSMutableSet<Class> set]];
4563
Class testClass = [FIRTestClass class];
46-
[FIRComponentContainer registerAsComponentRegistrant:testClass inSet:allRegistrants];
47-
XCTAssertTrue([allRegistrants containsObject:testClass]);
64+
[FIRComponentContainer registerAsComponentRegistrant:testClass];
65+
XCTAssertTrue([[FIRComponentContainer registrantSet] containsObject:testClass]);
4866
}
4967

5068
- (void)testRegisteringNonConformingClass {
@@ -143,14 +161,15 @@ - (void)testProtocolAlreadyRegistered {
143161
/// Create a container that has registered the test class.
144162
- (FIRComponentContainer *)containerWithRegistrants:(NSArray<Class> *)registrants {
145163
id appMock = OCMClassMock([FIRApp class]);
146-
NSMutableSet<Class> *allRegistrants = [NSMutableSet<Class> set];
164+
[FIRComponentContainer setRegistrantSet:[NSMutableSet<Class> set]];
147165

148166
// Initialize the container with the test classes.
149167
for (Class c in registrants) {
150-
[FIRComponentContainer registerAsComponentRegistrant:c inSet:allRegistrants];
168+
[FIRComponentContainer registerAsComponentRegistrant:c];
151169
}
152170

153-
return [[FIRComponentContainer alloc] initWithApp:appMock registrants:allRegistrants];
171+
return [[FIRComponentContainer alloc] initWithApp:appMock
172+
registrants:[FIRComponentContainer registrantSet]];
154173
}
155174

156175
@end

Firebase/Core/FIRApp.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,17 @@ + (void)registerInternalLibrary:(nonnull Class<FIRLibrary>)library
500500
withName:(nonnull NSString *)name
501501
withVersion:(nonnull NSString *)version {
502502
// This is called at +load time, keep the work to a minimum.
503+
504+
// Ensure the class given conforms to the proper protocol.
505+
if (![(Class)library conformsToProtocol:@protocol(FIRLibrary)] ||
506+
![(Class)library respondsToSelector:@selector(componentsToRegister)]) {
507+
[NSException raise:NSInvalidArgumentException
508+
format:
509+
@"Class %@ attempted to register components, but it does not conform to "
510+
@"`FIRLibrary or provide a `componentsToRegister:` method.",
511+
library];
512+
}
513+
503514
[FIRComponentContainer registerAsComponentRegistrant:library];
504515
if ([(Class)library respondsToSelector:@selector(configureWithApp:)]) {
505516
static dispatch_once_t onceToken;

Firebase/Core/FIRComponentContainer.m

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,7 @@ + (void)registerAsComponentRegistrant:(Class<FIRLibrary>)klass {
4747
sFIRComponentRegistrants = [[NSMutableSet<Class> alloc] init];
4848
});
4949

50-
[self registerAsComponentRegistrant:klass inSet:sFIRComponentRegistrants];
51-
}
52-
53-
+ (void)registerAsComponentRegistrant:(Class)klass inSet:(NSMutableSet<Class> *)allRegistrants {
54-
// Validate the array to store the components is initialized.
55-
if (!allRegistrants) {
56-
FIRLogWarning(kFIRLoggerCore, @"I-COR000025",
57-
@"Attempted to store registered components in an empty set.");
58-
return;
59-
}
60-
61-
// Ensure the class given conforms to the proper protocol.
62-
// TODO restore protocol check after new code propagates internally
63-
if ( //![klass conformsToProtocol:@protocol(FIRLibrary)] ||
64-
![klass respondsToSelector:@selector(componentsToRegister)]) {
65-
[NSException raise:NSInvalidArgumentException
66-
format:
67-
@"Class %@ attempted to register components, but it does not conform to "
68-
@"`FIRComponentRegistrant` or provide a `componentsToRegister:` method.",
69-
klass];
70-
}
71-
72-
[allRegistrants addObject:klass];
50+
[sFIRComponentRegistrants addObject:klass];
7351
}
7452

7553
#pragma mark - Internal Initialization
@@ -188,17 +166,14 @@ - (void)removeAllCachedInstances {
188166
[self.cachedInstances removeAllObjects];
189167
}
190168

191-
#pragma mark - Testing Initializers
169+
#pragma mark - Testing Accessors
192170

193-
// TODO(wilsonryan): Set up a testing flag so this only is compiled in with unit tests.
194-
/// Initialize an instance with an app and existing components.
195-
- (instancetype)initWithApp:(FIRApp *)app
196-
components:(NSDictionary<NSString *, FIRComponentCreationBlock> *)components {
197-
self = [self initWithApp:app registrants:[[NSMutableSet alloc] init]];
198-
if (self) {
199-
_components = [components mutableCopy];
200-
}
201-
return self;
171+
+ (void)setRegistrantSet:(NSMutableSet<Class> *)testInput {
172+
sFIRComponentRegistrants = testInput;
173+
}
174+
175+
+ (NSMutableSet<Class> *)registrantSet {
176+
return sFIRComponentRegistrants;
202177
}
203178

204179
@end

0 commit comments

Comments
 (0)