Skip to content

Commit 341f366

Browse files
committed
Android: Allow passing a FlutterAdLoader factory
Create a new `GoogleMobileAdsPlugin` constructor which takes an additional `Supplier<FlutterAdLoader>` argument. This is available solely for testing, and allows the provision of a mock `FlutterAdLoader` for those `FlutterAd`s that need it during their construction.
1 parent 3c91d84 commit 341f366

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/GoogleMobileAdsPlugin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.HashMap;
4444
import java.util.List;
4545
import java.util.Map;
46+
import java.util.function.Supplier;
4647

4748
/**
4849
* Flutter plugin accessing Google Mobile Ads API.
@@ -69,6 +70,7 @@ private static <T> T requireNonNull(T obj) {
6970
private final Map<String, NativeAdFactory> nativeAdFactories = new HashMap<>();
7071
@Nullable private MediationNetworkExtrasProvider mediationNetworkExtrasProvider;
7172
private final FlutterMobileAdsWrapper flutterMobileAds;
73+
@Nullable private Supplier<FlutterAdLoader> adLoaderSupplier;
7274
/**
7375
* Public constructor for the plugin. Dependency initialization is handled in lifecycle methods
7476
* below.
@@ -94,6 +96,17 @@ protected GoogleMobileAdsPlugin(@NonNull AppStateNotifier appStateNotifier) {
9496
this.flutterMobileAds = new FlutterMobileAdsWrapper();
9597
}
9698

99+
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
100+
protected GoogleMobileAdsPlugin(
101+
@Nullable FlutterPluginBinding pluginBinding,
102+
@Nullable AdInstanceManager instanceManager,
103+
@NonNull FlutterMobileAdsWrapper flutterMobileAds,
104+
@NonNull Supplier<FlutterAdLoader> adLoaderSupplier) {
105+
this(pluginBinding, instanceManager, flutterMobileAds);
106+
107+
this.adLoaderSupplier = adLoaderSupplier;
108+
}
109+
97110
/**
98111
* Interface used to display a {@link com.google.android.gms.ads.nativead.NativeAd}.
99112
*

0 commit comments

Comments
 (0)