Skip to content

Commit 8bd3bf3

Browse files
committed
Updated GIDFakeJSONSerializerImpl to accept a seeded error instead of a BOOL.
1 parent 7c12f3f commit 8bd3bf3

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

GoogleSignIn/Sources/GIDJSONSerializer/Fake/GIDFakeJSONSerializerImpl.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ NS_ASSUME_NONNULL_BEGIN
2222
@interface GIDFakeJSONSerializerImpl : NSObject <GIDJSONSerializer>
2323

2424
/**
25-
* A flag to control whether the serialization method should fail.
25+
* An error to be returned by `stringWithJSONObject:error:`.
2626
*
27-
* If set to `YES`, `stringWithJSONObject:error:` will return `nil` and
28-
* populate the error parameter with a serialization failure error.
29-
* If `NO` (the default), it will attempt a real serialization.
27+
* If this property is set, `stringWithJSONObject:error:` will return `nil` and
28+
* populate the error parameter with this error.
3029
*/
31-
@property(nonatomic, assign) BOOL shouldFailJSONSerialization;
30+
@property(nonatomic, nullable) NSError *serializationError;
3231

3332
/** The dictionary passed to the serialization method. */
3433
@property(nonatomic, readonly, nullable) NSDictionary<NSString *, id> *capturedJSONObject;

GoogleSignIn/Sources/GIDJSONSerializer/Fake/GIDFakeJSONSerializerImpl.m

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ - (nullable NSString *)stringWithJSONObject:(NSDictionary<NSString *, id> *)json
2525
error:(NSError *_Nullable *_Nullable)error {
2626
_capturedJSONObject = [jsonObject copy];
2727

28-
// Check the boolean flag to see if we should simulate a failure.
29-
if (self.shouldFailJSONSerialization) {
28+
// Check if a serialization error should be simulated.
29+
if (self.serializationError) {
3030
if (error) {
31-
*error = [NSError errorWithDomain:kGIDSignInErrorDomain
32-
code:kGIDSignInErrorCodeJSONSerializationFailure
33-
userInfo:@{
34-
NSLocalizedDescriptionKey:kGIDJSONSerializationErrorDescription,
35-
}];
31+
*error = self.serializationError;
3632
}
3733
return nil;
3834
}

GoogleSignIn/Tests/Unit/GIDTokenClaimsInternalOptionsTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ - (void)testValidatedJSONStringForClaims_WhenSerializationFails_ReturnsNilAndErr
9797
userInfo:@{
9898
NSLocalizedDescriptionKey: kGIDJSONSerializationErrorDescription,
9999
}];
100-
_jsonSerializerFake.shouldFailJSONSerialization = YES;
100+
_jsonSerializerFake.serializationError = expectedJSONError;
101101
NSError *actualError;
102102
NSString *result = [_tokenClaimsInternalOptions validatedJSONStringForClaims:claims
103103
error:&actualError];

0 commit comments

Comments
 (0)