From bf81fafdcfa200537b4c6a8883c0c01f8dcea865 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 11 Apr 2017 14:30:58 +0200 Subject: [PATCH] convert RunConfigurableTest to kotlin --- .../execution/impl/RunConfigurableTest.java | 1296 ++++++++--------- 1 file changed, 639 insertions(+), 657 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java b/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java index 3a7065e091d2..f41ec09326d2 100644 --- a/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java +++ b/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java @@ -13,210 +13,192 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.execution.impl; +package com.intellij.execution.impl -import com.intellij.execution.application.ApplicationConfigurationType; -import com.intellij.execution.configurations.ConfigurationType; -import com.intellij.execution.junit.JUnitConfigurationType; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Trinity; -import com.intellij.testFramework.LightIdeaTestCase; -import com.intellij.ui.RowsDnDSupport; -import com.intellij.ui.treeStructure.Tree; -import com.intellij.util.JdomKt; -import org.jdom.Element; +import com.intellij.execution.application.ApplicationConfigurationType +import com.intellij.execution.configurations.ConfigurationType +import com.intellij.execution.junit.JUnitConfigurationType +import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Trinity +import com.intellij.testFramework.LightIdeaTestCase +import com.intellij.ui.RowsDnDSupport +import com.intellij.ui.treeStructure.Tree +import com.intellij.util.* +import org.jdom.Element -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreePath; -import java.util.ArrayList; -import java.util.List; +import javax.swing.tree.DefaultMutableTreeNode +import javax.swing.tree.TreePath +import java.util.ArrayList -import static com.intellij.execution.impl.RunConfigurable.NodeKind.*; -import static com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position.*; +import com.intellij.execution.impl.RunConfigurable.NodeKind.* +import com.intellij.testFramework.assertions.Assertions.assertThat +import com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position.* -/** - * User: Vassiliy.Kudryashov - */ -public class RunConfigurableTest extends LightIdeaTestCase { - private static final RunConfigurable.NodeKind[] ORDER = { - CONFIGURATION_TYPE,//Application - FOLDER,//1 - CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, - TEMPORARY_CONFIGURATION, TEMPORARY_CONFIGURATION, - FOLDER,//2 - TEMPORARY_CONFIGURATION, - FOLDER,//3 - CONFIGURATION, - TEMPORARY_CONFIGURATION, - CONFIGURATION_TYPE,//JUnit - FOLDER,//4 - CONFIGURATION, CONFIGURATION, - FOLDER,//5 - CONFIGURATION, CONFIGURATION, - TEMPORARY_CONFIGURATION, - UNKNOWN//Defaults - }; - private MockRunConfigurable myConfigurable; - private Tree myTree; - private DefaultMutableTreeNode myRoot; - private RunConfigurable.MyTreeModel myModel; +private val ORDER = arrayOf(CONFIGURATION_TYPE, //Application + FOLDER, //1 + CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, TEMPORARY_CONFIGURATION, TEMPORARY_CONFIGURATION, FOLDER, //2 + TEMPORARY_CONFIGURATION, FOLDER, //3 + CONFIGURATION, TEMPORARY_CONFIGURATION, CONFIGURATION_TYPE, //JUnit + FOLDER, //4 + CONFIGURATION, CONFIGURATION, FOLDER, //5 + CONFIGURATION, CONFIGURATION, TEMPORARY_CONFIGURATION, UNKNOWN//Defaults +) - @Override - protected void setUp() throws Exception { - super.setUp(); - myConfigurable = new MockRunConfigurable(createRunManager(JdomKt.loadElement(FOLDERS_CONFIGURATION))); - myTree = myConfigurable.myTree; - myRoot = myConfigurable.myRoot; - myModel = myConfigurable.myTreeModel; +private fun createRunManager(element: Element): RunManagerImpl { + val project = LightPlatformTestCase.getProject() + val runManager = RunManagerImpl(project) + runManager.initializeConfigurationTypes(arrayOf(ApplicationConfigurationType.getInstance(), JUnitConfigurationType.getInstance())) + runManager.loadState(element) + return runManager +} + +class RunConfigurableTest : LightIdeaTestCase() { + private var myConfigurable: MockRunConfigurable? = null + private var myTree: Tree? = null + private var myRoot: DefaultMutableTreeNode? = null + private var myModel: RunConfigurable.MyTreeModel? = null + + protected override fun setUp() { + super.setUp() + myConfigurable = MockRunConfigurable(createRunManager(loadElement(FOLDERS_CONFIGURATION))) + myTree = myConfigurable!!.myTree + myRoot = myConfigurable!!.myRoot + myModel = myConfigurable!!.myTreeModel } - @Override - protected void tearDown() throws Exception { + protected override fun tearDown() { try { - if (myConfigurable != null) myConfigurable.disposeUIResources(); - myConfigurable = null; - myTree = null; - myRoot = null; - myModel = null; + if (myConfigurable != null) { + myConfigurable!!.disposeUIResources() + } + myConfigurable = null + myTree = null + myRoot = null + myModel = null } finally { - super.tearDown(); + super.tearDown() } } - public void testDND() throws Exception { - doExpand(); - int[] never = {-1, 0, 14, 22, 23, 999}; - for (int i = -1; i < 17; i++) { - for (int j : never) { + fun testDND() { + doExpand() + val never = intArrayOf(-1, 0, 14, 22, 23, 999) + for (i in -1..16) { + for (j in never) { if ((j == 14 || j == 21) && i == j) { - continue; + continue } - assertCannot(j,i,ABOVE); - assertCannot(j,i,INTO); - assertCannot(j,i,BELOW); + assertCannot(j, i, ABOVE) + assertCannot(j, i, INTO) + assertCannot(j, i, BELOW) } } - assertCan(3, 3, BELOW); - assertCan(3, 3, ABOVE); - assertCannot(3, 2, BELOW); - assertCan(3, 2, ABOVE); - assertCannot(3, 1, BELOW); - assertCannot(3, 0, BELOW); - assertCan(2, 14, ABOVE); - assertCan(1, 14, ABOVE); - assertCan(1, 11, ABOVE); - assertCannot(1, 10, ABOVE); - assertCannot(1, 10, BELOW); - assertCannot(8, 6, ABOVE); - assertCan(8, 6, BELOW); - assertCannot(5, 7, BELOW); - assertCan(5, 7, ABOVE); - assertCannot(15, 11, INTO); - assertCannot(18, 21, ABOVE); - assertCan(15, 21, ABOVE); + assertCan(3, 3, BELOW) + assertCan(3, 3, ABOVE) + assertCannot(3, 2, BELOW) + assertCan(3, 2, ABOVE) + assertCannot(3, 1, BELOW) + assertCannot(3, 0, BELOW) + assertCan(2, 14, ABOVE) + assertCan(1, 14, ABOVE) + assertCan(1, 11, ABOVE) + assertCannot(1, 10, ABOVE) + assertCannot(1, 10, BELOW) + assertCannot(8, 6, ABOVE) + assertCan(8, 6, BELOW) + assertCannot(5, 7, BELOW) + assertCan(5, 7, ABOVE) + assertCannot(15, 11, INTO) + assertCannot(18, 21, ABOVE) + assertCan(15, 21, ABOVE) - assertTrue(myModel.isDropInto(myTree, 2, 9)); - assertTrue(myModel.isDropInto(myTree, 2, 1)); - assertTrue(myModel.isDropInto(myTree, 12, 9)); - assertTrue(myModel.isDropInto(myTree, 12, 1)); - assertFalse(myModel.isDropInto(myTree, 999, 9)); - assertFalse(myModel.isDropInto(myTree, 999, 1)); - assertFalse(myModel.isDropInto(myTree, 2, 999)); - assertFalse(myModel.isDropInto(myTree, 2, -1)); + assertThat(myModel!!.isDropInto(myTree, 2, 9)).isTrue() + assertThat(myModel!!.isDropInto(myTree, 2, 1)).isTrue() + assertThat(myModel!!.isDropInto(myTree, 12, 9)).isTrue() + assertThat(myModel!!.isDropInto(myTree, 12, 1)).isTrue() + TestCase.assertFalse(myModel!!.isDropInto(myTree, 999, 9)) + TestCase.assertFalse(myModel!!.isDropInto(myTree, 999, 1)) + TestCase.assertFalse(myModel!!.isDropInto(myTree, 2, 999)) + TestCase.assertFalse(myModel!!.isDropInto(myTree, 2, -1)) } - private void doExpand() { - List toExpand = new ArrayList<>(); - RunConfigurable.collectNodesRecursively(myRoot, toExpand, FOLDER); - assertEquals(5, toExpand.size()); - List toExpand2 = new ArrayList<>(); - RunConfigurable.collectNodesRecursively(myRoot, toExpand2, CONFIGURATION_TYPE); - toExpand.addAll(toExpand2); - for (DefaultMutableTreeNode node : toExpand) { - myTree.expandPath(new TreePath(node.getPath())); + private fun doExpand() { + val toExpand = ArrayList() + RunConfigurable.collectNodesRecursively(myRoot, toExpand, FOLDER) + assertThat(toExpand).hasSize(5) + val toExpand2 = ArrayList() + RunConfigurable.collectNodesRecursively(myRoot, toExpand2, CONFIGURATION_TYPE) + toExpand.addAll(toExpand2) + for (node in toExpand) { + myTree!!.expandPath(TreePath(node.getPath())) } - for (int i = 0; i < ORDER.length; i++) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode)myTree.getPathForRow(i).getLastPathComponent(); - assertEquals("Row #" + i, RunConfigurable.getKind(node), ORDER[i]); + + for (i in ORDER.indices) { + val node = myTree!!.getPathForRow(i).getLastPathComponent() as DefaultMutableTreeNode + TestCase.assertEquals("Row #" + i, RunConfigurable.getKind(node), ORDER[i]) } } - private void assertCan(int oldIndex, int newIndex, RowsDnDSupport.RefinedDropSupport.Position position) { - assertDrop(oldIndex, newIndex, position, true); + private fun assertCan(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { + assertDrop(oldIndex, newIndex, position, true) } - private void assertCannot(int oldIndex, int newIndex, RowsDnDSupport.RefinedDropSupport.Position position) { - assertDrop(oldIndex, newIndex, position, false); + private fun assertCannot(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { + assertDrop(oldIndex, newIndex, position, false) } - private void assertDrop(int oldIndex, int newIndex, RowsDnDSupport.RefinedDropSupport.Position position, boolean canDrop) { - StringBuilder message = new StringBuilder(); - message.append("(").append(oldIndex).append(")").append(myTree.getPathForRow(oldIndex)).append("->"); - message.append("(").append(newIndex).append(")").append(myTree.getPathForRow(newIndex)).append(position); + private fun assertDrop(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position, canDrop: Boolean) { + val message = StringBuilder() + message.append("(").append(oldIndex).append(")").append(myTree!!.getPathForRow(oldIndex)).append("->") + message.append("(").append(newIndex).append(")").append(myTree!!.getPathForRow(newIndex)).append(position) if (canDrop) { - assertTrue(message.toString(), myModel.canDrop(oldIndex, newIndex, position)); + TestCase.assertTrue(message.toString(), myModel!!.canDrop(oldIndex, newIndex, position)) } else { - assertFalse(message.toString(), myModel.canDrop(oldIndex, newIndex, position)); + TestCase.assertFalse(message.toString(), myModel!!.canDrop(oldIndex, newIndex, position)) } } - public void testMoveUpDown() { - doExpand(); - checkPositionToMove(0, 1, null); - checkPositionToMove(2, 1, Trinity.create(2, 3, BELOW)); - checkPositionToMove(2, -1, null); - checkPositionToMove(14, 1, null); - checkPositionToMove(14, -1, null); - checkPositionToMove(15, -1, null); - checkPositionToMove(16, -1, null); - checkPositionToMove(3, -1, Trinity.create(3, 2, ABOVE)); - checkPositionToMove(6, 1, Trinity.create(6, 9, BELOW)); - checkPositionToMove(7, 1, Trinity.create(7, 8, BELOW)); - checkPositionToMove(10, -1, Trinity.create(10, 8, BELOW)); - checkPositionToMove(8, 1, Trinity.create(8, 9, BELOW)); - checkPositionToMove(21, -1, Trinity.create(21, 20, BELOW)); - checkPositionToMove(21, 1, null); - checkPositionToMove(20, 1, Trinity.create(20, 21, ABOVE)); - checkPositionToMove(20, -1, Trinity.create(20, 19, ABOVE)); - checkPositionToMove(19, 1, Trinity.create(19, 20, BELOW)); - checkPositionToMove(19, -1, Trinity.create(19, 17, BELOW)); - checkPositionToMove(17, -1, Trinity.create(17, 16, ABOVE)); - checkPositionToMove(17, 1, Trinity.create(17, 18, BELOW)); + fun testMoveUpDown() { + doExpand() + checkPositionToMove(0, 1, null) + checkPositionToMove(2, 1, Trinity.create(2, 3, BELOW)) + checkPositionToMove(2, -1, null) + checkPositionToMove(14, 1, null) + checkPositionToMove(14, -1, null) + checkPositionToMove(15, -1, null) + checkPositionToMove(16, -1, null) + checkPositionToMove(3, -1, Trinity.create(3, 2, ABOVE)) + checkPositionToMove(6, 1, Trinity.create(6, 9, BELOW)) + checkPositionToMove(7, 1, Trinity.create(7, 8, BELOW)) + checkPositionToMove(10, -1, Trinity.create(10, 8, BELOW)) + checkPositionToMove(8, 1, Trinity.create(8, 9, BELOW)) + checkPositionToMove(21, -1, Trinity.create(21, 20, BELOW)) + checkPositionToMove(21, 1, null) + checkPositionToMove(20, 1, Trinity.create(20, 21, ABOVE)) + checkPositionToMove(20, -1, Trinity.create(20, 19, ABOVE)) + checkPositionToMove(19, 1, Trinity.create(19, 20, BELOW)) + checkPositionToMove(19, -1, Trinity.create(19, 17, BELOW)) + checkPositionToMove(17, -1, Trinity.create(17, 16, ABOVE)) + checkPositionToMove(17, 1, Trinity.create(17, 18, BELOW)) } - private void checkPositionToMove(int selectedRow, - int direction, - Trinity expected) { - myTree.setSelectionRow(selectedRow); - assertEquals(expected, myConfigurable.getAvailableDropPosition(direction)); + private fun checkPositionToMove(selectedRow: Int, direction: Int, expected: Trinity?) { + myTree!!.setSelectionRow(selectedRow) + TestCase.assertEquals(expected, myConfigurable!!.getAvailableDropPosition(direction)) + } +} + +private class MockRunConfigurable(private val testManager: RunManagerImpl) : RunConfigurable(LightPlatformTestCase.getProject()) { + init { + createComponent() } - private static RunManagerImpl createRunManager(Element element) { - Project project = getProject(); - RunManagerImpl runManager = new RunManagerImpl(project); - runManager.initializeConfigurationTypes(new ConfigurationType[]{ApplicationConfigurationType.getInstance(), JUnitConfigurationType.getInstance()}); - runManager.loadState(element); - return runManager; - } + internal override fun getRunManager() = testManager +} - private static class MockRunConfigurable extends RunConfigurable { - private final RunManagerImpl myTestManager; - - private MockRunConfigurable(RunManagerImpl runManager) { - super(getProject()); - myTestManager = runManager; - createComponent(); - } - - @Override - RunManagerImpl getRunManager() { - return myTestManager; - } - } - - /* +/* 00 Application 01 1 02 CodeGenerator @@ -240,495 +222,495 @@ public class RunConfigurableTest extends LightIdeaTestCase { 20 All in titled4 21 All in titled5 16 Defaults - ... - */ - private static final String FOLDERS_CONFIGURATION = " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " localhost\n" + - " 5050\n" + - " \n" + - " \n"; -} + ... + */ +private val FOLDERS_CONFIGURATION = " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " localhost\n" + + " 5050\n" + + " \n" + + " \n" +