1package io.flutter.embedding.engine.plugins.shim;
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNull;
5import static org.mockito.Mockito.times;
6import static org.mockito.Mockito.verify;
7import static org.mockito.Mockito.when;
11import androidx.test.ext.junit.runners.AndroidJUnit4;
12import io.flutter.embedding.engine.FlutterEngine;
13import io.flutter.embedding.engine.plugins.FlutterPlugin;
14import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding;
15import io.flutter.embedding.engine.plugins.PluginRegistry;
16import io.flutter.embedding.engine.plugins.activity.ActivityAware;
17import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
18import org.junit.Before;
20import org.junit.runner.RunWith;
21import org.mockito.ArgumentCaptor;
22import org.mockito.Mock;
23import org.mockito.MockitoAnnotations;
24import org.robolectric.annotation.Config;
27@RunWith(AndroidJUnit4.class)
34 @Mock
private Context mockApplicationContext;
35 @Mock
private Activity mockActivity;
39 MockitoAnnotations.openMocks(
this);
40 when(mockFlutterEngine.getPlugins()).thenReturn(mockPluginRegistry);
41 when(mockFlutterPluginBinding.getApplicationContext()).thenReturn(mockApplicationContext);
42 when(mockActivityPluginBinding.getActivity()).thenReturn(mockActivity);
45 @SuppressWarnings(
"deprecation")
55 ArgumentCaptor<FlutterPlugin> shimAggregateCaptor =
58 verify(mockPluginRegistry).add(shimAggregateCaptor.capture());
61 FlutterPlugin shimAggregateUnderTest = shimAggregateCaptor.getValue();
66 assertEquals(mockApplicationContext, registrarUnderTest.
context());
68 verify(mockFlutterPluginBinding).getApplicationContext();
71 @SuppressWarnings(
"deprecation")
82 ArgumentCaptor<FlutterPlugin> shimAggregateCaptor =
84 verify(mockPluginRegistry).add(shimAggregateCaptor.capture());
86 FlutterPlugin shimAggregateUnderTest = shimAggregateCaptor.getValue();
93 assertEquals(registrarUnderTest1.
context(), registrarUnderTest2.
context());
94 verify(mockFlutterPluginBinding,
times(2)).getApplicationContext();
97 @SuppressWarnings(
"deprecation")
105 ArgumentCaptor<FlutterPlugin> shimAggregateCaptor =
107 verify(mockPluginRegistry).add(shimAggregateCaptor.capture());
108 FlutterPlugin shimAggregateAsPlugin = shimAggregateCaptor.getValue();
112 assertNull(registrarUnderTest.
context());
113 assertNull(registrarUnderTest.
activity());
117 assertEquals(mockApplicationContext, registrarUnderTest.
context());
118 assertNull(registrarUnderTest.
activity());
123 assertEquals(mockActivity, registrarUnderTest.
activeContext());
124 assertEquals(mockActivity, registrarUnderTest.
activity());
128 assertEquals(mockApplicationContext, registrarUnderTest.
activeContext());
129 assertNull(registrarUnderTest.
activity());
132 assertEquals(mockActivity, registrarUnderTest.
activeContext());
133 assertEquals(mockActivity, registrarUnderTest.
activity());
137 assertEquals(mockApplicationContext, registrarUnderTest.
activeContext());
138 assertNull(registrarUnderTest.
activity());
143 assertEquals(mockActivity, registrarUnderTest.
activeContext());
144 assertEquals(mockActivity, registrarUnderTest.
activity());
151 assertNull(registrarUnderTest.
activity());
static SkISize times(const SkISize &size, float factor)
void itSuppliesOldAPIsViaTheNewFlutterPluginBinding()
void itSuppliesMultipleOldPlugins()
void itCanOnlySupplyActivityBindingWhenUpstreamActivityIsAttached()
Registrar registrarFor(@NonNull String pluginKey)
void onAttachedToEngine(@NonNull FlutterPluginBinding binding)
void onDetachedFromEngine(@NonNull FlutterPluginBinding binding)
void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding)
void onDetachedFromActivity()
void onDetachedFromActivityForConfigChanges()
void onAttachedToActivity(@NonNull ActivityPluginBinding binding)