diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 183df1837b35b..128eb5c6a8e8d 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -106,6 +106,24 @@ public class FlutterJNI { // platform thread and doesn't require locking. private ReentrantReadWriteLock shellHolderLock = new ReentrantReadWriteLock(); + // Prefer using the FlutterJNI.Factory so it's easier to test. + public FlutterJNI() { + // We cache the main looper so that we can ensure calls are made on the main thread + // without consistently paying the synchronization cost of getMainLooper(). + mainLooper = Looper.getMainLooper(); + } + + /** + * A factory for creating {@code FlutterJNI} instances. Useful for FlutterJNI injections during + * tests. + */ + public static class Factory { + /** @return a {@link FlutterJNI} instance. */ + public FlutterJNI provideFlutterJNI() { + return new FlutterJNI(); + } + } + // BEGIN Methods related to loading for FlutterLoader. /** * Loads the libflutter.so C++ library. @@ -126,6 +144,8 @@ public void loadLibrary() { private static boolean loadLibraryCalled = false; + private static native void nativePrefetchDefaultFontManager(); + /** * Prefetch the default font manager provided by SkFontMgr::RefDefault() which is a process-wide * singleton owned by Skia. Note that, the first call to SkFontMgr::RefDefault() will take @@ -142,10 +162,16 @@ public void prefetchDefaultFontManager() { FlutterJNI.prefetchDefaultFontManagerCalled = true; } - private static native void nativePrefetchDefaultFontManager(); - private static boolean prefetchDefaultFontManagerCalled = false; + private static native void nativeInit( + @NonNull Context context, + @NonNull String[] args, + @Nullable String bundlePath, + @NonNull String appStoragePath, + @NonNull String engineCachesPath, + long initTimeMillis); + /** * Perform one time initialization of the Dart VM and Flutter engine. * @@ -174,14 +200,6 @@ public void init( FlutterJNI.initCalled = true; } - private static native void nativeInit( - @NonNull Context context, - @NonNull String[] args, - @Nullable String bundlePath, - @NonNull String appStoragePath, - @NonNull String engineCachesPath, - long initTimeMillis); - private static boolean initCalled = false; // END methods related to FlutterLoader @@ -201,23 +219,23 @@ private static native void nativeInit( private native boolean nativeGetIsSoftwareRenderingEnabled(); - @UiThread /** * Checks launch settings for whether software rendering is requested. * *

The value is the same per program. */ + @UiThread public boolean getIsSoftwareRenderingEnabled() { return nativeGetIsSoftwareRenderingEnabled(); } - @Nullable /** * Observatory URI for the VM instance. * *

Its value is set by the native engine once {@link #init(Context, String[], String, String, * String, long)} is run. */ + @Nullable public static String getObservatoryUri() { return observatoryUri; } @@ -245,7 +263,7 @@ public void setRefreshRateFPS(float refreshRateFPS) { * The Android vsync waiter implementation in C++ needs to know when a vsync signal arrives, which * is obtained via Java API. The delegate set here is called on the C++ side when the engine is * ready to wait for the next vsync signal. The delegate is expected to add a postFrameCallback to - * the {@link android.view.Choreographer}, and call {@link nativeOnVsync} to notify the engine. + * the {@link android.view.Choreographer}, and call {@link onVsync} to notify the engine. * * @param delegate The delegate that will call the engine back on the next vsync signal. */ @@ -264,6 +282,8 @@ private static void asyncWaitForVsync(final long cookie) { } } + private native void nativeOnVsync(long frameDelayNanos, long refreshPeriodNanos, long cookie); + /** * Notifies the engine that the Choreographer has signaled a vsync. * @@ -272,23 +292,44 @@ private static void asyncWaitForVsync(final long cookie) { * @param refreshPeriodNanos The display refresh period in nanoseconds. * @param cookie An opaque handle to the C++ VSyncWaiter object. */ - public native void nativeOnVsync(long frameDelayNanos, long refreshPeriodNanos, long cookie); + public void onVsync(long frameDelayNanos, long refreshPeriodNanos, long cookie) { + nativeOnVsync(frameDelayNanos, refreshPeriodNanos, cookie); + } - // TODO(mattcarroll): add javadocs @NonNull + @Deprecated public static native FlutterCallbackInformation nativeLookupCallbackInformation(long handle); // ----- Start FlutterTextUtils Methods ---- + private native boolean nativeFlutterTextUtilsIsEmoji(int codePoint); - public native boolean nativeFlutterTextUtilsIsEmoji(int codePoint); + public boolean isCodePointEmoji(int codePoint) { + return nativeFlutterTextUtilsIsEmoji(codePoint); + } + + private native boolean nativeFlutterTextUtilsIsEmojiModifier(int codePoint); - public native boolean nativeFlutterTextUtilsIsEmojiModifier(int codePoint); + public boolean isCodePointEmojiModifier(int codePoint) { + return nativeFlutterTextUtilsIsEmojiModifier(codePoint); + } - public native boolean nativeFlutterTextUtilsIsEmojiModifierBase(int codePoint); + private native boolean nativeFlutterTextUtilsIsEmojiModifierBase(int codePoint); + + public boolean isCodePointEmojiModifierBase(int codePoint) { + return nativeFlutterTextUtilsIsEmojiModifierBase(codePoint); + } - public native boolean nativeFlutterTextUtilsIsVariationSelector(int codePoint); + private native boolean nativeFlutterTextUtilsIsVariationSelector(int codePoint); - public native boolean nativeFlutterTextUtilsIsRegionalIndicator(int codePoint); + public boolean isCodePointVariantSelector(int codePoint) { + return nativeFlutterTextUtilsIsVariationSelector(codePoint); + } + + private native boolean nativeFlutterTextUtilsIsRegionalIndicator(int codePoint); + + public boolean isCodePointRegionalIndicator(int codePoint) { + return nativeFlutterTextUtilsIsRegionalIndicator(codePoint); + } // ----- End Engine FlutterTextUtils Methods ---- @@ -312,13 +353,6 @@ private static void asyncWaitForVsync(final long cookie) { @NonNull private final Looper mainLooper; // cached to avoid synchronization on repeat access. - // Prefer using the FlutterJNI.Factory so it's easier to test. - public FlutterJNI() { - // We cache the main looper so that we can ensure calls are made on the main thread - // without consistently paying the synchronization cost of getMainLooper(). - mainLooper = Looper.getMainLooper(); - } - // ------ Start Native Attach/Detach Support ---- /** * Returns true if this instance of {@code FlutterJNI} is connected to Flutter's native engine via @@ -1402,15 +1436,4 @@ void updateSemantics( public interface AsyncWaitForVsyncDelegate { void asyncWaitForVsync(final long cookie); } - - /** - * A factory for creating {@code FlutterJNI} instances. Useful for FlutterJNI injections during - * tests. - */ - public static class Factory { - /** @return a {@link FlutterJNI} instance. */ - public FlutterJNI provideFlutterJNI() { - return new FlutterJNI(); - } - } } diff --git a/shell/platform/android/io/flutter/plugin/editing/FlutterTextUtils.java b/shell/platform/android/io/flutter/plugin/editing/FlutterTextUtils.java index fd1e430841427..ea0dc96b913de 100644 --- a/shell/platform/android/io/flutter/plugin/editing/FlutterTextUtils.java +++ b/shell/platform/android/io/flutter/plugin/editing/FlutterTextUtils.java @@ -19,23 +19,23 @@ public FlutterTextUtils(FlutterJNI flutterJNI) { } public boolean isEmoji(int codePoint) { - return flutterJNI.nativeFlutterTextUtilsIsEmoji(codePoint); + return flutterJNI.isCodePointEmoji(codePoint); } public boolean isEmojiModifier(int codePoint) { - return flutterJNI.nativeFlutterTextUtilsIsEmojiModifier(codePoint); + return flutterJNI.isCodePointEmojiModifier(codePoint); } public boolean isEmojiModifierBase(int codePoint) { - return flutterJNI.nativeFlutterTextUtilsIsEmojiModifierBase(codePoint); + return flutterJNI.isCodePointEmojiModifierBase(codePoint); } public boolean isVariationSelector(int codePoint) { - return flutterJNI.nativeFlutterTextUtilsIsVariationSelector(codePoint); + return flutterJNI.isCodePointVariantSelector(codePoint); } public boolean isRegionalIndicatorSymbol(int codePoint) { - return flutterJNI.nativeFlutterTextUtilsIsRegionalIndicator(codePoint); + return flutterJNI.isCodePointRegionalIndicator(codePoint); } public boolean isTagSpecChar(int codePoint) { diff --git a/shell/platform/android/io/flutter/view/VsyncWaiter.java b/shell/platform/android/io/flutter/view/VsyncWaiter.java index 200eb784675a0..f65d6d569b088 100644 --- a/shell/platform/android/io/flutter/view/VsyncWaiter.java +++ b/shell/platform/android/io/flutter/view/VsyncWaiter.java @@ -97,7 +97,7 @@ public void doFrame(long frameTimeNanos) { if (delay < 0) { delay = 0; } - flutterJNI.nativeOnVsync(delay, refreshPeriodNanos, cookie); + flutterJNI.onVsync(delay, refreshPeriodNanos, cookie); } }); } diff --git a/shell/platform/android/test/io/flutter/FlutterInjectorTest.java b/shell/platform/android/test/io/flutter/FlutterInjectorTest.java index e041dc36d226f..4899c2051f97b 100644 --- a/shell/platform/android/test/io/flutter/FlutterInjectorTest.java +++ b/shell/platform/android/test/io/flutter/FlutterInjectorTest.java @@ -37,7 +37,7 @@ public class FlutterInjectorTest { public void setUp() { // Since the intent is to have a convenient static class to use for production. FlutterInjector.reset(); - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } @After diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java index a50de5a38ba2d..92871724142d4 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java @@ -5,10 +5,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isNull; -import static org.mockito.Matchers.notNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNotNull; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -230,7 +230,7 @@ public void itGivesHostAnOpportunityToConfigureFlutterSurfaceView() { delegate.onCreateView(null, null, null, 0, true); // Verify that the host was asked to configure a FlutterSurfaceView. - verify(mockHost, times(1)).onFlutterSurfaceViewCreated(notNull(FlutterSurfaceView.class)); + verify(mockHost, times(1)).onFlutterSurfaceViewCreated(isNotNull()); } @Test @@ -259,7 +259,7 @@ public void itGivesHostAnOpportunityToConfigureFlutterTextureView() { delegate.onCreateView(null, null, null, 0, false); // Verify that the host was asked to configure a FlutterTextureView. - verify(customMockHost, times(1)).onFlutterTextureViewCreated(notNull(FlutterTextureView.class)); + verify(customMockHost, times(1)).onFlutterTextureViewCreated(isNotNull()); } @Test diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java index 3f483bf6e9582..331906e473f43 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java @@ -1,8 +1,8 @@ package io.flutter.embedding.android; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java index 8e42664ec81c5..7a99f5fe04cdf 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java @@ -3,8 +3,8 @@ import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertFalse; import static junit.framework.TestCase.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -76,7 +76,7 @@ public class FlutterViewTest { @Before public void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); when(mockFlutterJni.isAttached()).thenReturn(true); } diff --git a/shell/platform/android/test/io/flutter/embedding/android/KeyChannelResponderTest.java b/shell/platform/android/test/io/flutter/embedding/android/KeyChannelResponderTest.java index 4fe7b52c4f91e..cc7beb339d9d7 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/KeyChannelResponderTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/KeyChannelResponderTest.java @@ -30,7 +30,7 @@ public class KeyChannelResponderTest { @Before public void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); channelResponder = new KeyChannelResponder(keyEventChannel); } diff --git a/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java b/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java index 11f07569077b3..7e2b8ee1d839f 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java @@ -69,7 +69,7 @@ private FlutterEngine mockFlutterEngine() { @Before public void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); when(mockFlutterJni.isAttached()).thenReturn(true); mockEngine = mockFlutterEngine(); mockKeyEventChannel = mockEngine.getKeyEventChannel(); diff --git a/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupComponentTest.java b/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupComponentTest.java index aa6ffb00ab75e..e49e95ac1533b 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupComponentTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupComponentTest.java @@ -51,7 +51,7 @@ public class FlutterEngineGroupComponentTest { public void setUp() { FlutterInjector.reset(); - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); jniAttached = false; when(mockflutterJNI.isAttached()).thenAnswer(invocation -> jniAttached); doAnswer(invocation -> jniAttached = true).when(mockflutterJNI).attachToNative(); @@ -165,7 +165,7 @@ public void canCreateAndRunCustomEntrypoints() { .runBundleAndSnapshotFromLibrary( eq("some/path/to/flutter_assets"), eq("other entrypoint"), - isNull(String.class), + isNull(), any(AssetManager.class), nullable(List.class)); } @@ -215,7 +215,7 @@ public void canCreateAndRunWithCustomEntrypointArgs() { .runBundleAndSnapshotFromLibrary( nullable(String.class), nullable(String.class), - isNull(String.class), + isNull(), any(AssetManager.class), eq(firstDartEntrypointArgs)); diff --git a/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineTest.java b/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineTest.java index 26b0ee9eaa90a..2337ddfcb0c5b 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineTest.java @@ -45,7 +45,7 @@ public class FlutterEngineTest { @Before public void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); jniAttached = false; when(flutterJNI.isAttached()).thenAnswer(invocation -> jniAttached); doAnswer( diff --git a/shell/platform/android/test/io/flutter/embedding/engine/dart/DartExecutorTest.java b/shell/platform/android/test/io/flutter/embedding/engine/dart/DartExecutorTest.java index 6ef7b695a138d..38f03921dd687 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/dart/DartExecutorTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/dart/DartExecutorTest.java @@ -3,8 +3,8 @@ import static junit.framework.TestCase.assertNotNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -32,7 +32,7 @@ public class DartExecutorTest { @Before public void setUp() { FlutterInjector.reset(); - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } @Test diff --git a/shell/platform/android/test/io/flutter/embedding/engine/dart/DartMessengerTest.java b/shell/platform/android/test/io/flutter/embedding/engine/dart/DartMessengerTest.java index 1585aaa0b6d70..11e2b961ed07e 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/dart/DartMessengerTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/dart/DartMessengerTest.java @@ -5,9 +5,9 @@ import static junit.framework.TestCase.assertNotNull; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertArrayEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; diff --git a/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java b/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java index a804633e42e29..40cd6e2fdfdfd 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java @@ -37,7 +37,7 @@ public class ShimPluginRegistryTest { @Before public void setup() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); when(mockFlutterEngine.getPlugins()).thenReturn(mockPluginRegistry); when(mockFlutterPluginBinding.getApplicationContext()).thenReturn(mockApplicationContext); when(mockActivityPluginBinding.getActivity()).thenReturn(mockActivity); diff --git a/shell/platform/android/test/io/flutter/embedding/engine/renderer/FlutterRendererTest.java b/shell/platform/android/test/io/flutter/embedding/engine/renderer/FlutterRendererTest.java index 23b0aaa9a1876..dfe4b407d93a9 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/renderer/FlutterRendererTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/renderer/FlutterRendererTest.java @@ -2,9 +2,9 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyFloat; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyFloat; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/KeyEventChannelTest.java b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/KeyEventChannelTest.java index e86f7c6cf2e9b..7c289ee848b47 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/KeyEventChannelTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/KeyEventChannelTest.java @@ -55,7 +55,7 @@ private void sendReply(boolean handled, BinaryMessenger.BinaryReply messengerRep @Before public void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); keyEvent = new FakeKeyEvent(KeyEvent.ACTION_DOWN, 65); handled = new boolean[] {false}; keyEventChannel = new KeyEventChannel(fakeMessenger); diff --git a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java index 3a215e3e5507d..77fc5377c7eeb 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java @@ -1,5 +1,6 @@ package io.flutter.embedding.engine.systemchannels; +import static org.mockito.ArgumentMatchers.refEq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -13,7 +14,6 @@ import org.json.JSONObject; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @@ -40,6 +40,6 @@ public void platformChannel_hasStringsMessage() { expected.put("value", returnValue); } catch (JSONException e) { } - verify(mockResult).success(Matchers.refEq(expected)); + verify(mockResult).success(refEq(expected)); } } diff --git a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/RestorationChannelTest.java b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/RestorationChannelTest.java index 5068b10a33f3f..19b9d80c379a3 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/RestorationChannelTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/RestorationChannelTest.java @@ -6,7 +6,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import android.annotation.TargetApi; import io.flutter.plugin.common.MethodCall; @@ -49,7 +49,7 @@ public void itSendsDataOverWhenRequestIsPending() throws JSONException { MethodChannel.Result result = mock(MethodChannel.Result.class); argumentCaptor.getValue().onMethodCall(new MethodCall("get", null), result); - verifyZeroInteractions(result); + verifyNoInteractions(result); restorationChannel.setRestorationData(data); verify(rawChannel, times(0)).invokeMethod(any(), any()); diff --git a/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java b/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java index 37a73cbf65978..475cd9be2483f 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java @@ -4,9 +4,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; @@ -81,7 +81,7 @@ private void verifyMethodCall(ByteBuffer buffer, String methodName, String[] exp @Before public void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } @Test @@ -1192,15 +1192,15 @@ private static InputConnectionAdaptor sampleInputConnectionAdaptor( int client = 0; TextInputChannel textInputChannel = mock(TextInputChannel.class); FlutterJNI mockFlutterJNI = mock(FlutterJNI.class); - when(mockFlutterJNI.nativeFlutterTextUtilsIsEmoji(anyInt())) + when(mockFlutterJNI.isCodePointEmoji(anyInt())) .thenAnswer((invocation) -> Emoji.isEmoji((int) invocation.getArguments()[0])); - when(mockFlutterJNI.nativeFlutterTextUtilsIsEmojiModifier(anyInt())) + when(mockFlutterJNI.isCodePointEmojiModifier(anyInt())) .thenAnswer((invocation) -> Emoji.isEmojiModifier((int) invocation.getArguments()[0])); - when(mockFlutterJNI.nativeFlutterTextUtilsIsEmojiModifierBase(anyInt())) + when(mockFlutterJNI.isCodePointEmojiModifierBase(anyInt())) .thenAnswer((invocation) -> Emoji.isEmojiModifierBase((int) invocation.getArguments()[0])); - when(mockFlutterJNI.nativeFlutterTextUtilsIsVariationSelector(anyInt())) + when(mockFlutterJNI.isCodePointVariantSelector(anyInt())) .thenAnswer((invocation) -> Emoji.isVariationSelector((int) invocation.getArguments()[0])); - when(mockFlutterJNI.nativeFlutterTextUtilsIsRegionalIndicator(anyInt())) + when(mockFlutterJNI.isCodePointRegionalIndicator(anyInt())) .thenAnswer( (invocation) -> Emoji.isRegionalIndicatorSymbol((int) invocation.getArguments()[0])); return new InputConnectionAdaptor( @@ -1263,7 +1263,6 @@ public void updateEditingState( @Implements(InputMethodManager.class) public static class TestImm extends ShadowInputMethodManager { public static int empty = -999; - // private InputMethodSubtype currentInputMethodSubtype; CursorAnchorInfo lastCursorAnchorInfo; int lastExtractedTextToken = empty; ExtractedText lastExtractedText; @@ -1275,15 +1274,6 @@ public static class TestImm extends ShadowInputMethodManager { public TestImm() {} - // @Implementation - // public InputMethodSubtype getCurrentInputMethodSubtype() { - // return currentInputMethodSubtype; - // } - - // public void setCurrentInputMethodSubtype(InputMethodSubtype inputMethodSubtype) { - // this.currentInputMethodSubtype = inputMethodSubtype; - // } - @Implementation public void updateCursorAnchorInfo(View view, CursorAnchorInfo cursorAnchorInfo) { lastCursorAnchorInfo = cursorAnchorInfo; diff --git a/shell/platform/android/test/io/flutter/plugin/editing/ListenableEditingStateTest.java b/shell/platform/android/test/io/flutter/plugin/editing/ListenableEditingStateTest.java index fd8135ee8c82c..11cd6a30d69cc 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/ListenableEditingStateTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/ListenableEditingStateTest.java @@ -39,7 +39,7 @@ public Editable getEditable() { @Before public void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } // -------- Start: Test BatchEditing ------- diff --git a/shell/platform/android/test/io/flutter/plugin/editing/TextEditingDeltaTest.java b/shell/platform/android/test/io/flutter/plugin/editing/TextEditingDeltaTest.java index 6e80f33694ce8..2f3964981ba84 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextEditingDeltaTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextEditingDeltaTest.java @@ -14,7 +14,7 @@ public class TextEditingDeltaTest { @Before public void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } @Test diff --git a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index 1f1cfbf47a64a..f89bff60300d8 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -5,13 +5,13 @@ import static org.junit.Assert.assertTrue; import static org.mockito.AdditionalMatchers.aryEq; import static org.mockito.AdditionalMatchers.gt; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.any; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.isNotNull; import static org.mockito.Mockito.isNull; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.notNull; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -89,7 +89,7 @@ public class TextInputPluginTest { @Before public void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); when(mockFlutterJni.isAttached()).thenReturn(true); } @@ -1126,11 +1126,9 @@ public void destroy_clearTextInputMethodHandler() { TextInputChannel textInputChannel = spy(new TextInputChannel(mock(DartExecutor.class))); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); - verify(textInputChannel, times(1)) - .setTextInputMethodHandler(notNull(TextInputChannel.TextInputMethodHandler.class)); + verify(textInputChannel, times(1)).setTextInputMethodHandler(isNotNull()); textInputPlugin.destroy(); - verify(textInputChannel, times(1)) - .setTextInputMethodHandler(isNull(TextInputChannel.TextInputMethodHandler.class)); + verify(textInputChannel, times(1)).setTextInputMethodHandler(isNull()); } @Test diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java index 16b83b04ca921..346807172073d 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java @@ -2,7 +2,7 @@ import static io.flutter.embedding.engine.systemchannels.PlatformViewsChannel.PlatformViewTouch; import static org.junit.Assert.*; -import static org.mockito.Matchers.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import android.content.Context; diff --git a/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java b/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java index 23490aadf0a04..52c3e7c9cbe68 100644 --- a/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java +++ b/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java @@ -8,7 +8,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.doAnswer; diff --git a/shell/platform/android/test/io/flutter/view/VsyncWaiterTest.java b/shell/platform/android/test/io/flutter/view/VsyncWaiterTest.java index 7b08967b31c9d..e3b9bbbc24575 100644 --- a/shell/platform/android/test/io/flutter/view/VsyncWaiterTest.java +++ b/shell/platform/android/test/io/flutter/view/VsyncWaiterTest.java @@ -4,10 +4,10 @@ package io.flutter.view; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -47,7 +47,7 @@ public void itSetsFpsBelowApi17() { verify(mockFlutterJNI, times(1)).setAsyncWaitForVsyncDelegate(delegateCaptor.capture()); delegateCaptor.getValue().asyncWaitForVsync(1); shadowOf(Looper.getMainLooper()).idle(); - verify(mockFlutterJNI, times(1)).nativeOnVsync(anyLong(), eq(1000000000l / 10l), eq(1l)); + verify(mockFlutterJNI, times(1)).onVsync(anyLong(), eq(1000000000l / 10l), eq(1l)); } @TargetApi(17) @@ -75,7 +75,7 @@ public void itSetsFpsWhenDisplayManagerUpdates() { verify(mockFlutterJNI, times(1)).setAsyncWaitForVsyncDelegate(delegateCaptor.capture()); delegateCaptor.getValue().asyncWaitForVsync(1); shadowOf(Looper.getMainLooper()).idle(); - verify(mockFlutterJNI, times(1)).nativeOnVsync(anyLong(), eq(1000000000l / 90l), eq(1l)); + verify(mockFlutterJNI, times(1)).onVsync(anyLong(), eq(1000000000l / 90l), eq(1l)); when(mockDisplay.getRefreshRate()).thenReturn(60.0f); displayListenerCaptor.getValue().onDisplayChanged(Display.DEFAULT_DISPLAY); @@ -83,7 +83,7 @@ public void itSetsFpsWhenDisplayManagerUpdates() { delegateCaptor.getValue().asyncWaitForVsync(1); shadowOf(Looper.getMainLooper()).idle(); - verify(mockFlutterJNI, times(1)).nativeOnVsync(anyLong(), eq(1000000000l / 60l), eq(1l)); + verify(mockFlutterJNI, times(1)).onVsync(anyLong(), eq(1000000000l / 60l), eq(1l)); } @TargetApi(17) diff --git a/shell/platform/android/test_runner/build.gradle b/shell/platform/android/test_runner/build.gradle index 10945a98a489d..4b5a9d4c08370 100644 --- a/shell/platform/android/test_runner/build.gradle +++ b/shell/platform/android/test_runner/build.gradle @@ -17,6 +17,7 @@ apply plugin: "com.android.library" rootProject.buildDir = project.property("build_dir") + android { compileSdkVersion 31 defaultConfig { @@ -46,9 +47,13 @@ android { testImplementation "androidx.window:window-java:1.0.0-beta04" testImplementation "com.google.android.play:core:1.8.0" testImplementation "com.ibm.icu:icu4j:69.1" - testImplementation "org.mockito:mockito-core:3.11.2" testImplementation "org.robolectric:robolectric:4.6.1" testImplementation "junit:junit:4.13" + + def mockitoVersion = "4.1.0" + testImplementation "org.mockito:mockito-core:$mockitoVersion" + testImplementation "org.mockito:mockito-inline:$mockitoVersion" + testImplementation "org.mockito:mockito-android:$mockitoVersion" } sourceSets { @@ -62,7 +67,7 @@ android { } testOptions.unitTests.all { - jvmArgs "-Xmx1g" + jvmArgs "-Xmx4g" // Max JVM heap size is 4G. testLogging { events "passed", "skipped", "failed", "standardOut", "standardError"