Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
69dfefb
Remove usages of deprecated junit.framework and replace with org.juni…
reidbaker Aug 22, 2023
5925883
Annotate deprecated usages of Registrar
reidbaker Aug 22, 2023
b3ada37
Suppress warnings for getSystemWindowInsets and ensure roboletric con…
reidbaker Aug 22, 2023
1f2bc15
Suppress warnings for DartExecutor.send
reidbaker Aug 22, 2023
0d3b2b0
Suppress warnings for ClipboardManager.set/hasText
reidbaker Aug 22, 2023
9f2b588
Suppress warnings for getWindowSystemUiVisibility, setMessageHandler,…
reidbaker Aug 22, 2023
86eb955
Suppress deprecation warnings, set minsdk on tests that were checking…
reidbaker Aug 22, 2023
8a482fc
Suppress deprecation warnings in SpellCheckPluginTest
reidbaker Aug 22, 2023
fb7272d
Suppress deprecation warnings in MouseCursorPluginTest, set minsdk co…
reidbaker Aug 22, 2023
90f6ce0
Stop calling RuntimeEnvrionment.application and insted a call Applica…
reidbaker Aug 22, 2023
d32d874
Start calling FlutterView(Context, FlutterSurfaceView)
reidbaker Aug 22, 2023
7c65622
Suppress deprecation warnings in PlatformPluginTest, getText, Robolec…
reidbaker Aug 22, 2023
3ba9a98
Suppress deprecation warnings in PlayStoreDeferredComponentManagerTest
reidbaker Aug 22, 2023
488c707
Suppress deprecation warnings in KeyboardChannelTest
reidbaker Aug 22, 2023
78d6b79
Suppress deprecation warnings in SettingsChannelTest
reidbaker Aug 22, 2023
0c14a63
Suppress deprecation warnings in ApplicationInfoLoaderTest
reidbaker Aug 22, 2023
7eb6b01
Stop calling RuntimeEnvrionment.application and insted a call Applica…
reidbaker Aug 22, 2023
e58f957
Suppress deprecation warnings in FlutterAndroidComponentTest
reidbaker Aug 22, 2023
fb86f96
Suppress deprecation warnings in FlutterFragmentTest, more robolectri…
reidbaker Aug 22, 2023
e987bc2
Suppress deprecation warnings in FlutterActivityAndFragmentDelegateTest
reidbaker Aug 22, 2023
86d08f5
Shadow.directlyOn is incompatible with java 17+,
reidbaker Aug 22, 2023
81cd095
Enable warnings as errors
reidbaker Aug 22, 2023
6142bf2
Formatting
reidbaker Aug 22, 2023
1ea2739
Add todo for roboletric setupActivity method and remove supression fr…
reidbaker Aug 23, 2023
e281c25
Add todo for expanding linter coverage and refactor method to reduce …
reidbaker Aug 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public class FlutterActivityAndFragmentDelegateTest {
private FlutterEngine mockFlutterEngine;
private FlutterActivityAndFragmentDelegate.Host mockHost;

@SuppressWarnings("deprecation")
// Robolectric.setupActivity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting a Activity GetMockActivity() or similar that returns Robolectric.setupActivity(Activity.class) so you aren't suppressing the entire method.

// TODO(reidbaker): https://github.com/flutter/flutter/issues/133151
@Before
public void setup() {
FlutterInjector.reset();
Expand Down Expand Up @@ -402,6 +405,9 @@ public void itGivesHostAnOpportunityToConfigureFlutterSurfaceView() {
verify(mockHost, times(1)).onFlutterSurfaceViewCreated(isNotNull());
}

@SuppressWarnings("deprecation")
// Robolectric.setupActivity
// TODO(reidbaker): https://github.com/flutter/flutter/issues/133151
@Test
public void itGivesHostAnOpportunityToConfigureFlutterTextureView() {
// ---- Test setup ----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ public Context getContext() {
return ApplicationProvider.getApplicationContext();
}

@SuppressWarnings("deprecation")
// Robolectric.setupActivity
// TODO(reidbaker): https://github.com/flutter/flutter/issues/133151
@Nullable
@Override
public Activity getActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ public void itReturnsExclusiveAppComponent() {
assertEquals(fragment.getExclusiveAppComponent(), delegate);
}

@SuppressWarnings("deprecation")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

// Robolectric.setupActivity
// TODO(reidbaker): https://github.com/flutter/flutter/issues/133151
@Test
public void itDelegatesOnBackPressedAutomaticallyWhenEnabled() {
// We need to mock FlutterJNI to avoid triggering native code.
Expand Down Expand Up @@ -317,6 +320,9 @@ public void itDelegatesOnBackPressedAutomaticallyWhenEnabled() {
verify(mockDelegate, times(1)).onBackPressed();
}

@SuppressWarnings("deprecation")
// Robolectric.setupActivity
// TODO(reidbaker): https://github.com/flutter/flutter/issues/133151
@Test
public void itHandlesPopSystemNavigationAutomaticallyWhenEnabled() {
// We need to mock FlutterJNI to avoid triggering native code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import junit.framework.Assert;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
Expand Down Expand Up @@ -489,25 +488,25 @@ public void serializeAndDeserializeKeyData() {
@Test
public void basicCombingCharactersTest() {
final KeyboardManager.CharacterCombiner combiner = new KeyboardManager.CharacterCombiner();
Assert.assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0));
Assert.assertEquals('A', (int) combiner.applyCombiningCharacterToBaseCharacter('A'));
Assert.assertEquals('B', (int) combiner.applyCombiningCharacterToBaseCharacter('B'));
Assert.assertEquals('B', (int) combiner.applyCombiningCharacterToBaseCharacter('B'));
Assert.assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0));
Assert.assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0));

Assert.assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY));
Assert.assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY));
Assert.assertEquals('À', (int) combiner.applyCombiningCharacterToBaseCharacter('A'));

Assert.assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY));
Assert.assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0));
assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0));
assertEquals('B', (int) combiner.applyCombiningCharacterToBaseCharacter('B'));
assertEquals('B', (int) combiner.applyCombiningCharacterToBaseCharacter('B'));
assertEquals('A', (int) combiner.applyCombiningCharacterToBaseCharacter('A'));
assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0));
assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0));

assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY));
assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY));
assertEquals('À', (int) combiner.applyCombiningCharacterToBaseCharacter('A'));

assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY));
assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0));
// The 0 input should remove the combining state.
Assert.assertEquals('A', (int) combiner.applyCombiningCharacterToBaseCharacter('A'));
assertEquals('A', (int) combiner.applyCombiningCharacterToBaseCharacter('A'));

Assert.assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0));
Assert.assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY));
Assert.assertEquals('À', (int) combiner.applyCombiningCharacterToBaseCharacter('A'));
assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0));
assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY));
assertEquals('À', (int) combiner.applyCombiningCharacterToBaseCharacter('A'));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.flutter.embedding.android;

import static org.robolectric.util.reflector.Reflector.reflector;

import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
Expand All @@ -8,22 +10,34 @@
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowResources;
import org.robolectric.util.reflector.Direct;
import org.robolectric.util.reflector.ForType;

@SuppressWarnings("deprecation")
// getDrawableInt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean getDrawable(int)? There's no getDrawableInt in this code.

@Implements(Resources.class)
public class SplashShadowResources extends ShadowResources {
@RealObject private Resources resources;

public static final int SPLASH_DRAWABLE_ID = 191919;
public static final int THEMED_SPLASH_DRAWABLE_ID = 212121;

@ForType(Resources.class)
interface ResourcesReflector {
@Direct
Drawable getDrawable(int id, Resources.Theme theme);

@Direct
Drawable getDrawable(int id);
}

@Implementation
protected Drawable getDrawable(int id) {
if (id == SPLASH_DRAWABLE_ID) {
return new ColorDrawable(Color.BLUE);
}
return Shadow.directlyOn(resources, Resources.class).getDrawable(id);
return reflector(Resources.class, resources).getDrawable(id);
}

@Implementation
Expand All @@ -37,6 +51,6 @@ protected Drawable getDrawable(int id, @Nullable Resources.Theme theme) {
}
return new ColorDrawable(Color.GRAY);
}
return Shadow.directlyOn(resources, Resources.class).getDrawable(id, theme);
return reflector(Resources.class, resources).getDrawable(id, theme);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import androidx.test.core.app.ApplicationProvider;
import io.flutter.FlutterInjector;
import io.flutter.embedding.engine.loader.FlutterLoader;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

@Config(manifest = Config.NONE)
Expand Down Expand Up @@ -75,8 +75,10 @@ public void itRemovesFlutterEngineGroups() {
@Test
public void itRemovesAllFlutterEngineGroups() {
// --- Test Setup ---
FlutterEngineGroup flutterEngineGroup1 = new FlutterEngineGroup(RuntimeEnvironment.application);
FlutterEngineGroup flutterEngineGroup2 = new FlutterEngineGroup(RuntimeEnvironment.application);
FlutterEngineGroup flutterEngineGroup1 =
new FlutterEngineGroup(ApplicationProvider.getApplicationContext());
FlutterEngineGroup flutterEngineGroup2 =
new FlutterEngineGroup(ApplicationProvider.getApplicationContext());
FlutterEngineGroupCache cache = new FlutterEngineGroupCache();

// --- Execute Test ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public void installDeferredComponent(int loadingUnitId, String componentName) {
}
}

@SuppressWarnings("deprecation")
// getApplicationInfo
private Context createSpyContext(Bundle metadata) throws NameNotFoundException {
Context spyContext = spy(ApplicationProvider.getApplicationContext());
doReturn(spyContext).when(spyContext).createPackageContext(any(), anyInt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public void itGeneratesCorrectApplicationInfoWithDefaultManifest() {
assertNull(info.nativeLibraryDir);
}

@SuppressWarnings("deprecation")
// getApplicationInfo
private Context generateMockContext(Bundle metadata, String networkPolicyXml) throws Exception {
Context context = mock(Context.class);
PackageManager packageManager = mock(PackageManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.flutter.embedding.engine.plugins.PluginRegistry;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -43,11 +42,15 @@ public void setup() {
when(mockActivityPluginBinding.getActivity()).thenReturn(mockActivity);
}

@SuppressWarnings("deprecation")
// Test is intentionally verifying deprecated behavior.
@Test
public void itSuppliesOldAPIsViaTheNewFlutterPluginBinding() {
ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine);
// Fully qualifed name because imports can not have deprecation supression.
// This is the consumption side of the old plugins.
Registrar registrarUnderTest = registryUnderTest.registrarFor("test");
io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest =
registryUnderTest.registrarFor("test");

ArgumentCaptor<FlutterPlugin> shimAggregateCaptor =
ArgumentCaptor.forClass(FlutterPlugin.class);
Expand All @@ -65,11 +68,16 @@ public void itSuppliesOldAPIsViaTheNewFlutterPluginBinding() {
verify(mockFlutterPluginBinding).getApplicationContext();
}

@SuppressWarnings("deprecation")
// Test is intentionally verifying deprecated behavior.
@Test
public void itSuppliesMultipleOldPlugins() {
ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine);
Registrar registrarUnderTest1 = registryUnderTest.registrarFor("test1");
Registrar registrarUnderTest2 = registryUnderTest.registrarFor("test2");
// Fully qualifed name because imports can not have deprecation supression.
io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest1 =
registryUnderTest.registrarFor("test1");
io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest2 =
registryUnderTest.registrarFor("test2");

ArgumentCaptor<FlutterPlugin> shimAggregateCaptor =
ArgumentCaptor.forClass(FlutterPlugin.class);
Expand All @@ -86,10 +94,13 @@ public void itSuppliesMultipleOldPlugins() {
verify(mockFlutterPluginBinding, times(2)).getApplicationContext();
}

@SuppressWarnings("deprecation")
// Test is intentionally verifying deprecated behavior.
@Test
public void itCanOnlySupplyActivityBindingWhenUpstreamActivityIsAttached() {
ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine);
Registrar registrarUnderTest = registryUnderTest.registrarFor("test");
io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest =
registryUnderTest.registrarFor("test");

ArgumentCaptor<FlutterPlugin> shimAggregateCaptor =
ArgumentCaptor.forClass(FlutterPlugin.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ private static BinaryMessenger.BinaryReply sendToBinaryMessageHandler(
return reply;
}

@SuppressWarnings("deprecation")
// setMessageHandler is deprecated.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issue we can reference for this? If we have a test verifying that our own code is calling our own deprecated method, it seems like there's a problem somewhere.

@Test
public void respondsToGetKeyboardStateChannelMessage() {
ArgumentCaptor<BinaryMessenger.BinaryMessageHandler> binaryMessageHandlerCaptor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class SettingsChannelTest {
@Test
@TargetApi(33)
@Config(sdk = 33)
@SuppressWarnings("deprecation")
// DartExecutor.send is deprecated.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reference an issue for all of these deprecated send calls (here and in other files)?

public void setDisplayMetricsDoesNothingOnAPILevel33() {
final DartExecutor executor = mock(DartExecutor.class);
executor.onAttachedToJNI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public void testPerformContextMenuAction_selectAll() {
assertEquals(editable.length(), Selection.getSelectionEnd(editable));
}

@SuppressWarnings("deprecation")
// ClipboardManager.hasText is deprecated.
@Test
public void testPerformContextMenuAction_cut() {
ClipboardManager clipboardManager = ctx.getSystemService(ClipboardManager.class);
Expand All @@ -152,6 +154,8 @@ public void testPerformContextMenuAction_cut() {
assertFalse(editable.toString().contains(textToBeCut));
}

@SuppressWarnings("deprecation")
// ClipboardManager.hasText is deprecated.
@Test
public void testPerformContextMenuAction_copy() {
ClipboardManager clipboardManager = ctx.getSystemService(ClipboardManager.class);
Expand All @@ -171,6 +175,8 @@ public void testPerformContextMenuAction_copy() {
clipboardManager.getPrimaryClip().getItemAt(0).getText());
}

@SuppressWarnings("deprecation")
// ClipboardManager.setText is deprecated.
@Test
public void testPerformContextMenuAction_paste() {
ClipboardManager clipboardManager = ctx.getSystemService(ClipboardManager.class);
Expand All @@ -185,6 +191,8 @@ public void testPerformContextMenuAction_paste() {
assertTrue(editable.toString().startsWith(textToBePasted));
}

@SuppressWarnings("deprecation")
// DartExecutor.send is deprecated.
@Test
public void testCommitContent() throws JSONException {
View testView = new View(ctx);
Expand Down Expand Up @@ -244,6 +252,8 @@ public void testCommitContent() throws JSONException {
});
}

@SuppressWarnings("deprecation")
// DartExecutor.send is deprecated.
@Test
public void testPerformPrivateCommand_dataIsNull() throws JSONException {
View testView = new View(ctx);
Expand Down Expand Up @@ -273,6 +283,8 @@ public void testPerformPrivateCommand_dataIsNull() throws JSONException {
new String[] {"0", "{\"action\":\"actionCommand\"}"});
}

@SuppressWarnings("deprecation")
// DartExecutor.send is deprecated.
@Test
public void testPerformPrivateCommand_dataIsByteArray() throws JSONException {
View testView = new View(ctx);
Expand Down Expand Up @@ -308,6 +320,8 @@ public void testPerformPrivateCommand_dataIsByteArray() throws JSONException {
});
}

@SuppressWarnings("deprecation")
// DartExecutor.send is deprecated.
@Test
public void testPerformPrivateCommand_dataIsByte() throws JSONException {
View testView = new View(ctx);
Expand Down Expand Up @@ -341,6 +355,8 @@ public void testPerformPrivateCommand_dataIsByte() throws JSONException {
new String[] {"0", "{\"data\":{\"keyboard_layout\":3},\"action\":\"actionCommand\"}"});
}

@SuppressWarnings("deprecation")
// DartExecutor.send is deprecated.
@Test
public void testPerformPrivateCommand_dataIsCharArray() throws JSONException {
View testView = new View(ctx);
Expand Down Expand Up @@ -377,6 +393,8 @@ public void testPerformPrivateCommand_dataIsCharArray() throws JSONException {
});
}

@SuppressWarnings("deprecation")
// DartExecutor.send is deprecated.
@Test
public void testPerformPrivateCommand_dataIsChar() throws JSONException {
View testView = new View(ctx);
Expand Down Expand Up @@ -410,6 +428,8 @@ public void testPerformPrivateCommand_dataIsChar() throws JSONException {
new String[] {"0", "{\"data\":{\"keyboard_layout\":\"a\"},\"action\":\"actionCommand\"}"});
}

@SuppressWarnings("deprecation")
// DartExecutor.send is deprecated.
@Test
public void testPerformPrivateCommand_dataIsCharSequenceArray() throws JSONException {
View testView = new View(ctx);
Expand Down Expand Up @@ -447,6 +467,8 @@ public void testPerformPrivateCommand_dataIsCharSequenceArray() throws JSONExcep
});
}

@SuppressWarnings("deprecation")
// DartExecutor.send is deprecated.
@Test
public void testPerformPrivateCommand_dataIsCharSequence() throws JSONException {
View testView = new View(ctx);
Expand Down Expand Up @@ -482,6 +504,8 @@ public void testPerformPrivateCommand_dataIsCharSequence() throws JSONException
});
}

@SuppressWarnings("deprecation")
// DartExecutor.send is deprecated.
@Test
public void testPerformPrivateCommand_dataIsFloat() throws JSONException {
View testView = new View(ctx);
Expand Down Expand Up @@ -515,6 +539,8 @@ public void testPerformPrivateCommand_dataIsFloat() throws JSONException {
new String[] {"0", "{\"data\":{\"keyboard_layout\":0.5},\"action\":\"actionCommand\"}"});
}

@SuppressWarnings("deprecation")
// DartExecutor.send is deprecated.
@Test
public void testPerformPrivateCommand_dataIsFloatArray() throws JSONException {
View testView = new View(ctx);
Expand Down
Loading