1package io.flutter.embedding.engine.systemchannels;
3import static io.flutter.Build.API_LEVELS;
4import static org.junit.Assert.assertEquals;
5import static org.mockito.Mockito.any;
6import static org.mockito.Mockito.eq;
7import static org.mockito.Mockito.mock;
8import static org.mockito.Mockito.times;
9import static org.mockito.Mockito.verify;
10import static org.mockito.Mockito.verifyNoInteractions;
12import android.annotation.TargetApi;
13import androidx.test.ext.junit.runners.AndroidJUnit4;
14import io.flutter.plugin.common.MethodCall;
15import io.flutter.plugin.common.MethodChannel;
16import java.util.HashMap;
18import org.json.JSONException;
20import org.junit.runner.RunWith;
21import org.mockito.ArgumentCaptor;
22import org.robolectric.annotation.Config;
27@RunWith(AndroidJUnit4.class)
28@TargetApi(API_LEVELS.API_24)
32 throws JSONException {
33 MethodChannel rawChannel = mock(MethodChannel.class);
37 verify(rawChannel,
times(0)).invokeMethod(any(), any());
42 byte[] data =
"Any String you want".getBytes();
44 MethodChannel rawChannel = mock(MethodChannel.class);
47 ArgumentCaptor<MethodChannel.MethodCallHandler> argumentCaptor =
48 ArgumentCaptor.forClass(MethodChannel.MethodCallHandler.class);
49 verify(rawChannel).setMethodCallHandler(argumentCaptor.capture());
51 MethodChannel.Result
result = mock(MethodChannel.Result.class);
53 verifyNoInteractions(
result);
56 verify(rawChannel,
times(0)).invokeMethod(any(), any());
57 Map<String, Object> expected =
new HashMap<>();
58 expected.put(
"enabled",
true);
59 expected.put(
"data", data);
60 verify(
result).success(expected);
63 MethodChannel.Result result2 = mock(MethodChannel.Result.class);
64 argumentCaptor.getValue().onMethodCall(
new MethodCall(
"get",
null), result2);
65 verify(result2).success(expected);
70 byte[] data =
"Any String you want".getBytes();
72 MethodChannel rawChannel = mock(MethodChannel.class);
75 ArgumentCaptor<MethodChannel.MethodCallHandler> argumentCaptor =
76 ArgumentCaptor.forClass(MethodChannel.MethodCallHandler.class);
77 verify(rawChannel).setMethodCallHandler(argumentCaptor.capture());
79 MethodChannel.Result
result = mock(MethodChannel.Result.class);
81 Map<String, Object> expected =
new HashMap<>();
82 expected.put(
"enabled",
true);
83 expected.put(
"data",
null);
84 verify(
result).success(expected);
89 ArgumentCaptor<MethodChannel.Result> resultCapture =
90 ArgumentCaptor.forClass(MethodChannel.Result.class);
91 Map<String, Object> expected2 =
new HashMap<>();
92 expected2.put(
"enabled",
true);
93 expected2.put(
"data", data);
94 verify(rawChannel).invokeMethod(
eq(
"push"),
eq(expected2), resultCapture.capture());
95 resultCapture.getValue().success(
null);
101 byte[] data =
"Any String you want".getBytes();
103 MethodChannel rawChannel = mock(MethodChannel.class);
106 ArgumentCaptor<MethodChannel.MethodCallHandler> argumentCaptor =
107 ArgumentCaptor.forClass(MethodChannel.MethodCallHandler.class);
108 verify(rawChannel).setMethodCallHandler(argumentCaptor.capture());
110 MethodChannel.Result
result = mock(MethodChannel.Result.class);
111 argumentCaptor.getValue().onMethodCall(
new MethodCall(
"put", data),
result);
static SkISize times(const SkISize &size, float factor)
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
void itDoesNotDoAnythingWhenRestorationDataIsSetBeforeFrameworkAsks()
void itSendsDataOverWhenRequestIsPending()
void itHoldsOnToDataFromFramework()
byte[] getRestorationData()
void setRestorationData(@NonNull byte[] data)