mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Recents tests: added navigation
This commit is contained in:
+32
-3
@@ -16,24 +16,39 @@
|
||||
package com.intellij.testIntegration;
|
||||
|
||||
import com.intellij.execution.Location;
|
||||
import com.intellij.execution.testframework.JavaTestLocator;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface LocationTestRunner {
|
||||
import java.util.List;
|
||||
|
||||
public interface RecentTestRunner {
|
||||
enum Mode { RUN, DEBUG }
|
||||
|
||||
void setMode(Mode mode);
|
||||
|
||||
void run(Location location);
|
||||
|
||||
Location getLocation(String url);
|
||||
}
|
||||
|
||||
class LocationTestRunnerImpl implements LocationTestRunner {
|
||||
class RecentTestRunnerImpl implements RecentTestRunner {
|
||||
private static AnAction RUN = ActionManager.getInstance().getAction("RunClass");
|
||||
private static AnAction DEBUG = ActionManager.getInstance().getAction("DebugClass");
|
||||
|
||||
|
||||
protected AnAction myCurrentAction = DEBUG;
|
||||
private final Project myProject;
|
||||
|
||||
public RecentTestRunnerImpl(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
public void setMode(Mode mode) {
|
||||
switch (mode) {
|
||||
@@ -45,6 +60,20 @@ class LocationTestRunnerImpl implements LocationTestRunner {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Location getLocation(String url) {
|
||||
String protocol = VirtualFileManager.extractProtocol(url);
|
||||
String path = VirtualFileManager.extractPath(url);
|
||||
|
||||
if (protocol != null) {
|
||||
List<Location> locations = JavaTestLocator.INSTANCE.getLocation(protocol, path, myProject, GlobalSearchScope.allScope(myProject));
|
||||
if (!locations.isEmpty()) {
|
||||
return locations.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void run(final Location location) {
|
||||
DataContext data = new DataContext() {
|
||||
@@ -17,14 +17,12 @@ package com.intellij.testIntegration;
|
||||
|
||||
import com.intellij.execution.Location;
|
||||
import com.intellij.execution.TestStateStorage;
|
||||
import com.intellij.execution.testframework.JavaTestLocator;
|
||||
import com.intellij.execution.testframework.TestIconMapper;
|
||||
import com.intellij.execution.testframework.sm.runner.states.TestStateInfo;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.PopupStep;
|
||||
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -36,13 +34,11 @@ import java.util.Map;
|
||||
|
||||
public class SelectTestStep extends BaseListPopupStep<String> {
|
||||
private final Map<String, TestStateStorage.Record> myRecords;
|
||||
private final LocationTestRunner myRunner;
|
||||
private final Project myProject;
|
||||
|
||||
public SelectTestStep(Project project, Map<String, TestStateStorage.Record> records, LocationTestRunner runner) {
|
||||
private final RecentTestRunner myRunner;
|
||||
|
||||
public SelectTestStep(Map<String, TestStateStorage.Record> records, RecentTestRunner runner) {
|
||||
super("Debug Recent Tests", getUrls(records));
|
||||
myRunner = runner;
|
||||
myProject = project;
|
||||
myRecords = records;
|
||||
}
|
||||
|
||||
@@ -76,24 +72,10 @@ public class SelectTestStep extends BaseListPopupStep<String> {
|
||||
TestStateInfo.Magnitude magnitude = TestIconMapper.getMagnitude(record.magnitude);
|
||||
return TestIconMapper.getIcon(magnitude);
|
||||
}
|
||||
|
||||
private Location getLocation(String url) {
|
||||
String protocol = VirtualFileManager.extractProtocol(url);
|
||||
String path = VirtualFileManager.extractPath(url);
|
||||
|
||||
if (protocol != null) {
|
||||
List<Location> locations = JavaTestLocator.INSTANCE.getLocation(protocol, path, myProject, GlobalSearchScope.allScope(myProject));
|
||||
if (!locations.isEmpty()) {
|
||||
return locations.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PopupStep onChosen(String url, boolean finalChoice) {
|
||||
Location location = getLocation(url);
|
||||
Location location = myRunner.getLocation(url);
|
||||
myRunner.run(location);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.testIntegration;
|
||||
|
||||
import com.intellij.execution.Location;
|
||||
import com.intellij.execution.TestStateStorage;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
@@ -22,10 +23,12 @@ import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.ListPopupStep;
|
||||
import com.intellij.ui.popup.list.ListPopupImpl;
|
||||
import com.intellij.util.PsiNavigateUtil;
|
||||
import com.intellij.util.Time;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -42,18 +45,18 @@ public class ShowRecentTests extends AnAction {
|
||||
if (project == null) return;
|
||||
|
||||
Map<String, TestStateStorage.Record> records = TestStateStorage.getInstance(project).getRecentTests(TEST_LIMIT, getSinceDate());
|
||||
LocationTestRunner testRunner = new LocationTestRunnerImpl();
|
||||
RecentTestRunner testRunner = new RecentTestRunnerImpl(project);
|
||||
|
||||
SelectTestStep selectStepTest = new SelectTestStep(project, records, testRunner);
|
||||
SelectTestStep selectStepTest = new SelectTestStep(records, testRunner);
|
||||
RecentTestsListPopup popup = new RecentTestsListPopup(selectStepTest, testRunner);
|
||||
popup.showCenteredInCurrentWindow(project);
|
||||
}
|
||||
}
|
||||
|
||||
class RecentTestsListPopup extends ListPopupImpl {
|
||||
private final LocationTestRunner myTestRunner;
|
||||
private final RecentTestRunner myTestRunner;
|
||||
|
||||
public RecentTestsListPopup(ListPopupStep<String> popupStep, LocationTestRunner testRunner) {
|
||||
public RecentTestsListPopup(ListPopupStep<String> popupStep, RecentTestRunner testRunner) {
|
||||
super(popupStep);
|
||||
myTestRunner = testRunner;
|
||||
shiftReleased();
|
||||
@@ -79,16 +82,29 @@ class RecentTestsListPopup extends ListPopupImpl {
|
||||
handleSelect(true);
|
||||
}
|
||||
});
|
||||
popup.registerAction("navigate", KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0), new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object[] values = getSelectedValues();
|
||||
if (values.length == 1) {
|
||||
Location location = myTestRunner.getLocation(values[0].toString());
|
||||
if (location != null) {
|
||||
cancel();
|
||||
PsiNavigateUtil.navigate(location.getPsiElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void shiftPressed() {
|
||||
setCaption("Run Recent Tests");
|
||||
myTestRunner.setMode(LocationTestRunner.Mode.RUN);
|
||||
myTestRunner.setMode(RecentTestRunner.Mode.RUN);
|
||||
}
|
||||
|
||||
private void shiftReleased() {
|
||||
setCaption("Debug Recent Tests");
|
||||
myTestRunner.setMode(LocationTestRunner.Mode.DEBUG);
|
||||
myTestRunner.setMode(RecentTestRunner.Mode.DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,17 +16,15 @@
|
||||
package com.intellij.testIntergration
|
||||
|
||||
import com.intellij.execution.TestStateStorage
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.testFramework.UsefulTestCase.*
|
||||
import com.intellij.testIntegration.LocationTestRunner
|
||||
import com.intellij.testIntegration.RecentTestRunner
|
||||
import com.intellij.testIntegration.SelectTestStep
|
||||
import org.junit.Test
|
||||
import org.mockito.Mockito.mock
|
||||
import java.util.*
|
||||
|
||||
class RecentTestsStepTest {
|
||||
val project = mock(Project::class.java)
|
||||
val runner = mock(LocationTestRunner::class.java)
|
||||
val runner = mock(RecentTestRunner::class.java)
|
||||
|
||||
@Test
|
||||
fun `suites comes before their children tests`() {
|
||||
@@ -41,7 +39,7 @@ class RecentTestsStepTest {
|
||||
map.put("java:test://Test.textQQQ", TestStateStorage.Record(1, now))
|
||||
map.put("java:test://JavaFormatterSuperDuperTest.testUnconditionalAlignmentErrorneous", TestStateStorage.Record(1, now))
|
||||
|
||||
val step = SelectTestStep(project, map, runner)
|
||||
val step = SelectTestStep(map, runner)
|
||||
|
||||
val expected = listOf(
|
||||
"java:suite://JavaFormatterSuperDuperTest",
|
||||
@@ -60,7 +58,7 @@ class RecentTestsStepTest {
|
||||
|
||||
@Test
|
||||
fun `shown value without protocol`() {
|
||||
val step = SelectTestStep(project, emptyMap(), runner)
|
||||
val step = SelectTestStep(emptyMap(), runner)
|
||||
var shownValue = step.getTextFor("java:suite://JavaFormatterSuperDuperTest")
|
||||
assertEquals(shownValue, "JavaFormatterSuperDuperTest")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user