Skip to content

Commit

Permalink
format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LTPhantom committed Aug 9, 2024
1 parent 612f8cb commit 64f1d6d
Show file tree
Hide file tree
Showing 11 changed files with 747 additions and 1,051 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,16 @@ - (void)testLoadShowGAMRequest {
OCMClassMock([FLTServerSideVerificationOptions class]);
GADServerSideVerificationOptions *gadOptions =
OCMClassMock([GADServerSideVerificationOptions class]);
OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions])
.andReturn(gadOptions);
OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions);

[self testLoadShowAppOpenAd:request gadOrGAMRequest:gamRequest];
}

// Helper method for testing with FLTAdRequest and FLTGAMAdRequest.
- (void)testLoadShowAppOpenAd:(FLTAdRequest *)request
gadOrGAMRequest:(GADRequest *)gadOrGAMRequest {
UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTAppOpenAd *ad =
[[FLTAppOpenAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
UIViewController *mockRootViewController = OCMClassMock([UIViewController class]);
FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request adId:@1];
ad.manager = mockManager;

// Stub the load call to invoke successful load callback.
Expand All @@ -86,8 +81,7 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request
[delegate adDidDismissFullScreenContent:appOpenClassMock];
[delegate adWillPresentFullScreenContent:appOpenClassMock];
[delegate adWillDismissFullScreenContent:appOpenClassMock];
[delegate ad:appOpenClassMock
didFailToPresentFullScreenContentWithError:error];
[delegate ad:appOpenClassMock didFailToPresentFullScreenContentWithError:error];
});
GADResponseInfo *responseInfo = OCMClassMock([GADResponseInfo class]);
OCMStub([appOpenClassMock responseInfo]).andReturn(responseInfo);
Expand All @@ -97,50 +91,45 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request
OCMStub([adValue value]).andReturn(NSDecimalNumber.one);
OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated);
OCMStub([adValue currencyCode]).andReturn(@"currencyCode");
OCMStub([appOpenClassMock
setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) {
GADPaidEventHandler handler = obj;
handler(adValue);
return YES;
}]]);
OCMStub([appOpenClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) {
GADPaidEventHandler handler = obj;
handler(adValue);
return YES;
}]]);
// Call load and check expected interactions with mocks.
[ad load];

OCMVerify(ClassMethod([appOpenClassMock
loadWithAdUnitID:[OCMArg isEqual:@"testId"]
request:[OCMArg isEqual:gadOrGAMRequest]
completionHandler:[OCMArg any]]));
OCMVerify(ClassMethod([appOpenClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"]
request:[OCMArg isEqual:gadOrGAMRequest]
completionHandler:[OCMArg any]]));
OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad]
responseInfo:[OCMArg isEqual:responseInfo]]);
OCMVerify(
[appOpenClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]);
OCMVerify([appOpenClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]);
XCTAssertEqual(ad.appOpenAd, appOpenClassMock);
OCMVerify([mockManager
onPaidEvent:[OCMArg isEqual:ad]
value:[OCMArg checkWithBlock:^BOOL(id obj) {
FLTAdValue *adValue = obj;
XCTAssertEqualObjects(
adValue.valueMicros,
[[NSDecimalNumber alloc] initWithInt:1000000]);
XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated);
XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode");
return TRUE;
}]]);
OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad]
value:[OCMArg checkWithBlock:^BOOL(id obj) {
FLTAdValue *adValue = obj;
XCTAssertEqualObjects(
adValue.valueMicros,
[[NSDecimalNumber alloc] initWithInt:1000000]);
XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated);
XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode");
return TRUE;
}]]);

[ad showFromRootViewController:mockRootViewController];

OCMVerify([appOpenClassMock
presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]);
OCMVerify(
[appOpenClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]);

// Verify full screen callbacks.
OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]);
OCMVerify([mockManager adDidDismissFullScreenContent:[OCMArg isEqual:ad]]);
OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]);
OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]);
OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]);
OCMVerify([mockManager
didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad]
error:[OCMArg isEqual:error]]);
OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad]
error:[OCMArg isEqual:error]]);
}

- (void)testFailedToLoadGADRequest {
Expand All @@ -161,10 +150,7 @@ - (void)testFailedToLoadGAMRequest {

// Helper for testing failed to load.
- (void)testFailedToLoad:(FLTAdRequest *)request {
FLTAppOpenAd *ad =
[[FLTAppOpenAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request adId:@1];
ad.manager = mockManager;

id appOpenClassMock = OCMClassMock([GADAppOpenAd class]);
Expand All @@ -183,8 +169,7 @@ - (void)testFailedToLoad:(FLTAdRequest *)request {
OCMVerify(ClassMethod([appOpenClassMock loadWithAdUnitID:[OCMArg any]
request:[OCMArg any]
completionHandler:[OCMArg any]]));
OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad]
error:[OCMArg isEqual:error]]);
OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]);
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,16 @@ - (void)testLoadShowInterstitialAd {
GAMRequest *gadRequest = OCMClassMock([GAMRequest class]);
OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest);

UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTGAMInterstitialAd *ad =
[[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
UIViewController *mockRootViewController = OCMClassMock([UIViewController class]);
FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
ad.manager = mockManager;

id interstitialClassMock = OCMClassMock([GAMInterstitialAd class]);
OCMStub(ClassMethod([interstitialClassMock
loadWithAdManagerAdUnitID:[OCMArg any]
request:[OCMArg any]
completionHandler:[OCMArg any]]))
OCMStub(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg any]
request:[OCMArg any]
completionHandler:[OCMArg any]]))
.andDo(^(NSInvocation *invocation) {
void (^completionHandler)(GAMInterstitialAd *ad, NSError *error);
[invocation getArgument:&completionHandler atIndex:4];
Expand All @@ -64,8 +61,7 @@ - (void)testLoadShowInterstitialAd {
[delegate adDidDismissFullScreenContent:interstitialClassMock];
[delegate adWillPresentFullScreenContent:interstitialClassMock];
[delegate adWillDismissFullScreenContent:interstitialClassMock];
[delegate ad:interstitialClassMock
didFailToPresentFullScreenContentWithError:error];
[delegate ad:interstitialClassMock didFailToPresentFullScreenContentWithError:error];
});

OCMStub([interstitialClassMock setAppEventDelegate:[OCMArg any]])
Expand All @@ -86,35 +82,31 @@ - (void)testLoadShowInterstitialAd {
OCMStub([adValue value]).andReturn(NSDecimalNumber.one);
OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated);
OCMStub([adValue currencyCode]).andReturn(@"currencyCode");
OCMStub([interstitialClassMock
setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) {
GADPaidEventHandler handler = obj;
handler(adValue);
return YES;
}]]);
OCMStub([interstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) {
GADPaidEventHandler handler = obj;
handler(adValue);
return YES;
}]]);
// Call load and verify interactions with mocks.
[ad load];

OCMVerify(ClassMethod([interstitialClassMock
loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"]
request:[OCMArg isEqual:gadRequest]
completionHandler:[OCMArg any]]));
OCMVerify(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"]
request:[OCMArg isEqual:gadRequest]
completionHandler:[OCMArg any]]));
OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad]
responseInfo:[OCMArg isEqual:responseInfo]]);
OCMVerify(
[interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]);
OCMVerify([interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]);
XCTAssertEqual(ad.interstitial, interstitialClassMock);
OCMVerify([mockManager
onPaidEvent:[OCMArg isEqual:ad]
value:[OCMArg checkWithBlock:^BOOL(id obj) {
FLTAdValue *adValue = obj;
XCTAssertEqualObjects(
adValue.valueMicros,
[[NSDecimalNumber alloc] initWithInt:1000000]);
XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated);
XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode");
return TRUE;
}]]);
OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad]
value:[OCMArg checkWithBlock:^BOOL(id obj) {
FLTAdValue *adValue = obj;
XCTAssertEqualObjects(
adValue.valueMicros,
[[NSDecimalNumber alloc] initWithInt:1000000]);
XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated);
XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode");
return TRUE;
}]]);

// Show the ad
[ad showFromRootViewController:mockRootViewController];
Expand All @@ -128,9 +120,8 @@ - (void)testLoadShowInterstitialAd {
OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]);
OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]);
OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]);
OCMVerify([mockManager
didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad]
error:[OCMArg isEqual:error]]);
OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad]
error:[OCMArg isEqual:error]]);

// Verify app event
OCMVerify([mockManager onAppEvent:ad
Expand All @@ -144,18 +135,16 @@ - (void)testFailToLoad {
GAMRequest *gadRequest = OCMClassMock([GAMRequest class]);
OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest);

FLTGAMInterstitialAd *ad =
[[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
ad.manager = mockManager;

id interstitialClassMock = OCMClassMock([GAMInterstitialAd class]);
NSError *error = OCMClassMock([NSError class]);
OCMStub(ClassMethod([interstitialClassMock
loadWithAdManagerAdUnitID:[OCMArg any]
request:[OCMArg any]
completionHandler:[OCMArg any]]))
OCMStub(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg any]
request:[OCMArg any]
completionHandler:[OCMArg any]]))
.andDo(^(NSInvocation *invocation) {
void (^completionHandler)(GAMInterstitialAd *ad, NSError *error);
[invocation getArgument:&completionHandler atIndex:4];
Expand All @@ -164,12 +153,10 @@ - (void)testFailToLoad {

[ad load];

OCMVerify(ClassMethod([interstitialClassMock
loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"]
request:[OCMArg isEqual:gadRequest]
completionHandler:[OCMArg any]]));
OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad]
error:[OCMArg isEqual:error]]);
OCMVerify(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"]
request:[OCMArg isEqual:gadRequest]
completionHandler:[OCMArg any]]));
OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]);
}

@end
Loading

0 comments on commit 64f1d6d

Please sign in to comment.