Flutter Engine
The Flutter Engine
GeneratedPluginRegistrant.java
Go to the documentation of this file.
1package io.flutter.plugins;
2
3import androidx.annotation.NonNull;
4import androidx.annotation.Nullable;
5import androidx.annotation.VisibleForTesting;
6import io.flutter.embedding.engine.FlutterEngine;
7import java.util.ArrayList;
8import java.util.List;
9
10/**
11 * A fake of the {@code GeneratedPluginRegistrant} normally built by the tool into Flutter apps.
12 *
13 * <p>Used to test engine logic which interacts with the generated class.
14 */
15@VisibleForTesting
17 private static final List<FlutterEngine> registeredEngines = new ArrayList<>();
18 public static @Nullable RuntimeException pluginRegistrationException;
19
20 /**
21 * The one and only method currently generated by the tool.
22 *
23 * <p>Normally it registers all plugins in an app with the given {@code engine}. This fake tracks
24 * all registered engines instead.
25 */
26 public static void registerWith(@NonNull FlutterEngine engine) {
27 if (pluginRegistrationException != null) {
29 }
30 registeredEngines.add(engine);
31 }
32
33 /**
34 * Clears the mutable static state regrettably stored in this class.
35 *
36 * <p>{@link #registerWith} is a static call with no visible side effects. In order to verify when
37 * it's been called we also unfortunately need to store the state statically. This should be
38 * called before and after each test run accessing this class to make sure the state is clear both
39 * before and after the run.
40 */
41 public static void clearRegisteredEngines() {
42 registeredEngines.clear();
43 }
44
45 /**
46 * Returns a list of all the engines registered so far.
47 *
48 * <p>CAUTION: This list is static and must be manually wiped in between test runs. See {@link
49 * #clearRegisteredEngines()}.
50 */
51 @NonNull
53 return new ArrayList<>(registeredEngines);
54 }
55}
static void registerWith(@NonNull FlutterEngine engine)
FlutterEngine engine
Definition: main.cc:68