Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
io.flutter.embedding.engine.plugins.shim.ShimPluginRegistryTest Class Reference

Public Member Functions

void setup ()
 
void itSuppliesOldAPIsViaTheNewFlutterPluginBinding ()
 
void itSuppliesMultipleOldPlugins ()
 
void itCanOnlySupplyActivityBindingWhenUpstreamActivityIsAttached ()
 

Detailed Description

Definition at line 28 of file ShimPluginRegistryTest.java.

Member Function Documentation

◆ itCanOnlySupplyActivityBindingWhenUpstreamActivityIsAttached()

void io.flutter.embedding.engine.plugins.shim.ShimPluginRegistryTest.itCanOnlySupplyActivityBindingWhenUpstreamActivityIsAttached ( )
inline

Definition at line 100 of file ShimPluginRegistryTest.java.

100 {
101 ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine);
103 registryUnderTest.registrarFor("test");
104
105 ArgumentCaptor<FlutterPlugin> shimAggregateCaptor =
106 ArgumentCaptor.forClass(FlutterPlugin.class);
107 verify(mockPluginRegistry).add(shimAggregateCaptor.capture());
108 FlutterPlugin shimAggregateAsPlugin = shimAggregateCaptor.getValue();
109 ActivityAware shimAggregateAsActivityAware = (ActivityAware) shimAggregateCaptor.getValue();
110
111 // Nothing is retrievable when nothing is attached.
112 assertNull(registrarUnderTest.context());
113 assertNull(registrarUnderTest.activity());
114
115 shimAggregateAsPlugin.onAttachedToEngine(mockFlutterPluginBinding);
116
117 assertEquals(mockApplicationContext, registrarUnderTest.context());
118 assertNull(registrarUnderTest.activity());
119
120 shimAggregateAsActivityAware.onAttachedToActivity(mockActivityPluginBinding);
121
122 // Now context is the activity context.
123 assertEquals(mockActivity, registrarUnderTest.activeContext());
124 assertEquals(mockActivity, registrarUnderTest.activity());
125
126 shimAggregateAsActivityAware.onDetachedFromActivityForConfigChanges();
127
128 assertEquals(mockApplicationContext, registrarUnderTest.activeContext());
129 assertNull(registrarUnderTest.activity());
130
131 shimAggregateAsActivityAware.onReattachedToActivityForConfigChanges(mockActivityPluginBinding);
132 assertEquals(mockActivity, registrarUnderTest.activeContext());
133 assertEquals(mockActivity, registrarUnderTest.activity());
134
135 shimAggregateAsActivityAware.onDetachedFromActivity();
136
137 assertEquals(mockApplicationContext, registrarUnderTest.activeContext());
138 assertNull(registrarUnderTest.activity());
139
140 // Attach an activity again.
141 shimAggregateAsActivityAware.onAttachedToActivity(mockActivityPluginBinding);
142
143 assertEquals(mockActivity, registrarUnderTest.activeContext());
144 assertEquals(mockActivity, registrarUnderTest.activity());
145
146 // Now rip out the whole engine.
147 shimAggregateAsPlugin.onDetachedFromEngine(mockFlutterPluginBinding);
148
149 // And everything should have been made unavailable.
150 assertNull(registrarUnderTest.activeContext());
151 assertNull(registrarUnderTest.activity());
152 }

◆ itSuppliesMultipleOldPlugins()

void io.flutter.embedding.engine.plugins.shim.ShimPluginRegistryTest.itSuppliesMultipleOldPlugins ( )
inline

Definition at line 74 of file ShimPluginRegistryTest.java.

74 {
75 ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine);
76 // Fully qualifed name because imports can not have deprecation supression.
78 registryUnderTest.registrarFor("test1");
80 registryUnderTest.registrarFor("test2");
81
82 ArgumentCaptor<FlutterPlugin> shimAggregateCaptor =
83 ArgumentCaptor.forClass(FlutterPlugin.class);
84 verify(mockPluginRegistry).add(shimAggregateCaptor.capture());
85 // There's only one aggregate for many old plugins.
86 FlutterPlugin shimAggregateUnderTest = shimAggregateCaptor.getValue();
87
88 // The FlutterPluginBinding is the supply side of the new plugin.
89 shimAggregateUnderTest.onAttachedToEngine(mockFlutterPluginBinding);
90
91 // Since the 2 old plugins are supplied by the same intermediate FlutterPlugin, they should
92 // get the same value.
93 assertEquals(registrarUnderTest1.context(), registrarUnderTest2.context());
94 verify(mockFlutterPluginBinding, times(2)).getApplicationContext();
95 }
static SkISize times(const SkISize &size, float factor)

◆ itSuppliesOldAPIsViaTheNewFlutterPluginBinding()

void io.flutter.embedding.engine.plugins.shim.ShimPluginRegistryTest.itSuppliesOldAPIsViaTheNewFlutterPluginBinding ( )
inline

Definition at line 48 of file ShimPluginRegistryTest.java.

48 {
49 ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine);
50 // Fully qualifed name because imports can not have deprecation supression.
51 // This is the consumption side of the old plugins.
53 registryUnderTest.registrarFor("test");
54
55 ArgumentCaptor<FlutterPlugin> shimAggregateCaptor =
56 ArgumentCaptor.forClass(FlutterPlugin.class);
57 // A single shim aggregate was added as a new plugin to the FlutterEngine's PluginRegistry.
58 verify(mockPluginRegistry).add(shimAggregateCaptor.capture());
59 // This is really a ShimRegistrarAggregate acting as a FlutterPlugin which is the
60 // intermediate consumption side of the new plugin inside the shim.
61 FlutterPlugin shimAggregateUnderTest = shimAggregateCaptor.getValue();
62 // The FlutterPluginBinding is the supply side of the new plugin.
63 shimAggregateUnderTest.onAttachedToEngine(mockFlutterPluginBinding);
64
65 // Consume something from the old plugin API.
66 assertEquals(mockApplicationContext, registrarUnderTest.context());
67 // Check that the value comes from the supply side of the new plugin.
68 verify(mockFlutterPluginBinding).getApplicationContext();
69 }

◆ setup()

void io.flutter.embedding.engine.plugins.shim.ShimPluginRegistryTest.setup ( )
inline

Definition at line 38 of file ShimPluginRegistryTest.java.

38 {
39 MockitoAnnotations.openMocks(this);
40 when(mockFlutterEngine.getPlugins()).thenReturn(mockPluginRegistry);
41 when(mockFlutterPluginBinding.getApplicationContext()).thenReturn(mockApplicationContext);
42 when(mockActivityPluginBinding.getActivity()).thenReturn(mockActivity);
43 }

The documentation for this class was generated from the following file: