Skip to content

Commit 8542457

Browse files
authored
[perf] ensure mock auto-closeable is closed (#8133)
`MockitoAnnotations.openMocks` returns an auto-closeable that a `try`-with-resources statement ensures will get closed. Follow-up from #8111 and related to #8110. (Also some opportunistic unused import cleanup.) --- - [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR. <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide]([https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Dart contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Java and Kotlin contributions should strive to follow Java and Kotlin best practices ([discussion](#8098)). </details>
1 parent e8b50f9 commit 8542457

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

flutter-idea/src/io/flutter/survey/FlutterSurveyNotifications.java

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.jetbrains.annotations.NotNull;
2525

2626
import java.util.concurrent.Executors;
27-
import java.util.concurrent.ScheduledExecutorService;
2827
import java.util.concurrent.TimeUnit;
2928

3029
public class FlutterSurveyNotifications {

flutter-idea/src/io/flutter/view/FlutterView.java

-3
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@
1515
import com.intellij.openapi.progress.EmptyProgressIndicator;
1616
import com.intellij.openapi.progress.ProgressManager;
1717
import com.intellij.openapi.project.Project;
18-
import com.intellij.openapi.ui.VerticalFlowLayout;
1918
import com.intellij.openapi.util.Disposer;
2019
import com.intellij.openapi.wm.ToolWindow;
2120
import com.intellij.openapi.wm.ToolWindowManager;
2221
import com.intellij.openapi.wm.ex.ToolWindowManagerEx;
2322
import com.intellij.serviceContainer.NonInjectable;
2423
import com.intellij.ui.components.JBLabel;
25-
import com.intellij.ui.components.labels.LinkLabel;
2624
import com.intellij.ui.content.Content;
2725
import com.intellij.ui.content.ContentManager;
28-
import com.intellij.util.ui.JBUI;
2926
import com.intellij.util.ui.UIUtil;
3027
import io.flutter.FlutterBundle;
3128
import io.flutter.FlutterUtils;

flutter-idea/testSrc/unit/io/flutter/view/FlutterViewTest.java

+22-21
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,28 @@ public class FlutterViewTest {
4848
ViewUtils viewUtilsSpy;
4949

5050
@Before
51-
public void setUp() {
52-
MockitoAnnotations.openMocks(this);
53-
54-
// Static mocking for ApplicationManager.
55-
mockedStaticApplicationManager = Mockito.mockStatic(ApplicationManager.class);
56-
mockedStaticApplicationManager.when(ApplicationManager::getApplication).thenReturn(mockApplication);
57-
doAnswer(invocation -> {
58-
Runnable runnable = invocation.getArgument(0);
59-
if (runnable != null) {
60-
runnable.run();
61-
}
62-
return null;
63-
}).when(mockApplication).invokeLater(any(Runnable.class));
64-
65-
// Mocking for ContentManager.
66-
when(mockToolWindow.getContentManager()).thenReturn(mockContentManager);
67-
when(mockContentManager.getFactory()).thenReturn(mockContentFactory);
68-
69-
// Spy on the ViewUtils class.
70-
final ViewUtils viewUtils = new ViewUtils();
71-
viewUtilsSpy = spy(viewUtils);
51+
public void setUp() throws Exception {
52+
try (var mocks = MockitoAnnotations.openMocks(this)) {
53+
54+
// Static mocking for ApplicationManager.
55+
mockedStaticApplicationManager = Mockito.mockStatic(ApplicationManager.class);
56+
mockedStaticApplicationManager.when(ApplicationManager::getApplication).thenReturn(mockApplication);
57+
doAnswer(invocation -> {
58+
Runnable runnable = invocation.getArgument(0);
59+
if (runnable != null) {
60+
runnable.run();
61+
}
62+
return null;
63+
}).when(mockApplication).invokeLater(any(Runnable.class));
64+
65+
// Mocking for ContentManager.
66+
when(mockToolWindow.getContentManager()).thenReturn(mockContentManager);
67+
when(mockContentManager.getFactory()).thenReturn(mockContentFactory);
68+
69+
// Spy on the ViewUtils class.
70+
final ViewUtils viewUtils = new ViewUtils();
71+
viewUtilsSpy = spy(viewUtils);
72+
}
7273
}
7374

7475
@After

0 commit comments

Comments
 (0)