Migrate to Mockito 4.1.0 (flutter/engine#30257)

This commit is contained in:
Emmanuel Garcia 2021-12-10 10:19:10 -08:00 committed by GitHub
parent 76633447f0
commit dceed9cd73
26 changed files with 132 additions and 116 deletions

View File

@ -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 class FlutterJNI {
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 class FlutterJNI {
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 class FlutterJNI {
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 @@ public class FlutterJNI {
private native boolean nativeGetIsSoftwareRenderingEnabled();
@UiThread
/**
* Checks launch settings for whether software rendering is requested.
*
* <p>The value is the same per program.
*/
@UiThread
public boolean getIsSoftwareRenderingEnabled() {
return nativeGetIsSoftwareRenderingEnabled();
}
@Nullable
/**
* Observatory URI for the VM instance.
*
* <p>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 class FlutterJNI {
* 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 @@ public class FlutterJNI {
}
}
private native void nativeOnVsync(long frameDelayNanos, long refreshPeriodNanos, long cookie);
/**
* Notifies the engine that the Choreographer has signaled a vsync.
*
@ -272,23 +292,44 @@ public class FlutterJNI {
* @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);
}
public native boolean nativeFlutterTextUtilsIsEmojiModifier(int codePoint);
private native boolean nativeFlutterTextUtilsIsEmojiModifier(int codePoint);
public native boolean nativeFlutterTextUtilsIsEmojiModifierBase(int codePoint);
public boolean isCodePointEmojiModifier(int codePoint) {
return nativeFlutterTextUtilsIsEmojiModifier(codePoint);
}
public native boolean nativeFlutterTextUtilsIsVariationSelector(int codePoint);
private native boolean nativeFlutterTextUtilsIsEmojiModifierBase(int codePoint);
public native boolean nativeFlutterTextUtilsIsRegionalIndicator(int codePoint);
public boolean isCodePointEmojiModifierBase(int codePoint) {
return nativeFlutterTextUtilsIsEmojiModifierBase(codePoint);
}
private native boolean nativeFlutterTextUtilsIsVariationSelector(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 @@ public class FlutterJNI {
@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 @@ public class FlutterJNI {
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();
}
}
}

View File

@ -19,23 +19,23 @@ class FlutterTextUtils {
}
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) {

View File

@ -97,7 +97,7 @@ public class VsyncWaiter {
if (delay < 0) {
delay = 0;
}
flutterJNI.nativeOnVsync(delay, refreshPeriodNanos, cookie);
flutterJNI.onVsync(delay, refreshPeriodNanos, cookie);
}
});
}

View File

@ -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

View File

@ -5,10 +5,10 @@ import static org.junit.Assert.assertEquals;
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 class FlutterActivityAndFragmentDelegateTest {
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 class FlutterActivityAndFragmentDelegateTest {
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

View File

@ -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;

View File

@ -3,8 +3,8 @@ package io.flutter.embedding.android;
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);
}

View File

@ -30,7 +30,7 @@ public class KeyChannelResponderTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
channelResponder = new KeyChannelResponder(keyEventChannel);
}

View File

@ -69,7 +69,7 @@ public class KeyboardManagerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
when(mockFlutterJni.isAttached()).thenReturn(true);
mockEngine = mockFlutterEngine();
mockKeyEventChannel = mockEngine.getKeyEventChannel();

View File

@ -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 class FlutterEngineGroupComponentTest {
.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 class FlutterEngineGroupComponentTest {
.runBundleAndSnapshotFromLibrary(
nullable(String.class),
nullable(String.class),
isNull(String.class),
isNull(),
any(AssetManager.class),
eq(firstDartEntrypointArgs));

View File

@ -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(

View File

@ -3,8 +3,8 @@ package io.flutter.embedding.engine.dart;
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

View File

@ -5,9 +5,9 @@ import static junit.framework.TestCase.assertEquals;
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;

View File

@ -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);

View File

@ -2,9 +2,9 @@ package io.flutter.embedding.engine.renderer;
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;

View File

@ -55,7 +55,7 @@ public class KeyEventChannelTest {
@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);

View File

@ -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.JSONException;
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 class PlatformChannelTest {
expected.put("value", returnValue);
} catch (JSONException e) {
}
verify(mockResult).success(Matchers.refEq(expected));
verify(mockResult).success(refEq(expected));
}
}

View File

@ -6,7 +6,7 @@ import static org.mockito.Mockito.eq;
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 class RestorationChannelTest {
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());

View File

@ -4,9 +4,9 @@ import static org.junit.Assert.assertEquals;
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 @@ public class InputConnectionAdaptorTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
}
@Test
@ -1192,15 +1192,15 @@ public class InputConnectionAdaptorTest {
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 class InputConnectionAdaptorTest {
@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 class InputConnectionAdaptorTest {
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;

View File

@ -39,7 +39,7 @@ public class ListenableEditingStateTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
}
// -------- Start: Test BatchEditing -------

View File

@ -14,7 +14,7 @@ import org.robolectric.annotation.Config;
public class TextEditingDeltaTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
}
@Test

View File

@ -5,13 +5,13 @@ import static org.junit.Assert.assertThrows;
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);
}
@ -1145,11 +1145,9 @@ public class TextInputPluginTest {
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

View File

@ -2,7 +2,7 @@ package io.flutter.plugin.platform;
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;

View File

@ -9,7 +9,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
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;

View File

@ -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 class VsyncWaiterTest {
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 class VsyncWaiterTest {
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 class VsyncWaiterTest {
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)

View File

@ -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"