From ca1c3e9955a929ac2475703dcf1e486e2a9801e6 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 11 Apr 2017 14:31:20 +0200 Subject: [PATCH] convert RunConfigurableTest to kotlin --- .../execution/impl/RunConfigurableTest.java | 716 ------------------ .../execution/impl/RunConfigurableTest.kt | 194 +++++ .../com/intellij/execution/impl/folders.xml | 489 ++++++++++++ 3 files changed, 683 insertions(+), 716 deletions(-) delete mode 100644 java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java create mode 100644 java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.kt create mode 100644 java/java-tests/testSrc/com/intellij/execution/impl/folders.xml diff --git a/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java b/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java deleted file mode 100644 index f41ec09326d2..000000000000 --- a/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java +++ /dev/null @@ -1,716 +0,0 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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.* -import org.jdom.Element - -import javax.swing.tree.DefaultMutableTreeNode -import javax.swing.tree.TreePath -import java.util.ArrayList - -import com.intellij.execution.impl.RunConfigurable.NodeKind.* -import com.intellij.testFramework.assertions.Assertions.assertThat -import com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position.* - -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 -) - -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 - } - - protected override fun tearDown() { - try { - if (myConfigurable != null) { - myConfigurable!!.disposeUIResources() - } - myConfigurable = null - myTree = null - myRoot = null - myModel = null - } - finally { - super.tearDown() - } - } - - 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 - } - 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) - - 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 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 (i in ORDER.indices) { - val node = myTree!!.getPathForRow(i).getLastPathComponent() as DefaultMutableTreeNode - TestCase.assertEquals("Row #" + i, RunConfigurable.getKind(node), ORDER[i]) - } - } - - private fun assertCan(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { - assertDrop(oldIndex, newIndex, position, true) - } - - private fun assertCannot(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { - assertDrop(oldIndex, newIndex, position, false) - } - - 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) { - TestCase.assertTrue(message.toString(), myModel!!.canDrop(oldIndex, newIndex, position)) - } - else { - TestCase.assertFalse(message.toString(), myModel!!.canDrop(oldIndex, newIndex, position)) - } - } - - 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 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() - } - - internal override fun getRunManager() = testManager -} - -/* -00 Application -01 1 -02 CodeGenerator -03 Renamer -04 UI -05 AuTest -06 Simples -07 OutAndErr (tmp) -08 C148C_TersePrincess (tmp) -09 2 -10 Periods (tmp) -11 3 -12 C148E_Porcelain -13 ErrAndOut (tmp) -14 JUnit -15 4 -16 All in titled -17 All in titled2 -18 5 -19 All in titled3 -20 All in titled4 -21 All in titled5 -16 Defaults - ... - */ -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" - diff --git a/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.kt b/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.kt new file mode 100644 index 000000000000..a10c98304b95 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.kt @@ -0,0 +1,194 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.execution.impl + +import com.intellij.execution.application.ApplicationConfigurationType +import com.intellij.execution.impl.RunConfigurable.NodeKind.* +import com.intellij.execution.junit.JUnitConfigurationType +import com.intellij.openapi.util.Trinity +import com.intellij.testFramework.LightIdeaTestCase +import com.intellij.testFramework.LightPlatformTestCase +import com.intellij.testFramework.assertions.Assertions.assertThat +import com.intellij.ui.RowsDnDSupport +import com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position.* +import com.intellij.ui.treeStructure.Tree +import com.intellij.util.loadElement +import org.jdom.Element +import java.util.* +import javax.swing.tree.DefaultMutableTreeNode +import javax.swing.tree.TreePath +import kotlin.properties.Delegates + +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 +) + +private fun createRunManager(element: Element): RunManagerImpl { + val runManager = RunManagerImpl(LightPlatformTestCase.getProject()) + runManager.initializeConfigurationTypes(arrayOf(ApplicationConfigurationType.getInstance(), JUnitConfigurationType.getInstance())) + runManager.loadState(element) + return runManager +} + +class RunConfigurableTest : LightIdeaTestCase() { + private var configurable: MockRunConfigurable? = null + private var tree: Tree by Delegates.notNull() + private var root: DefaultMutableTreeNode? = null + private var model: RunConfigurable.MyTreeModel by Delegates.notNull() + + override fun setUp() { + super.setUp() + + configurable = MockRunConfigurable(createRunManager(loadElement(RunConfigurableTest::class.java.getResourceAsStream("folders.xml")))) + tree = configurable!!.myTree + root = configurable!!.myRoot + model = configurable!!.myTreeModel + } + + override fun tearDown() { + try { + if (configurable != null) { + configurable!!.disposeUIResources() + } + configurable = null + root = null + } + finally { + super.tearDown() + } + } + + 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 + } + 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) + + assertThat(model.isDropInto(tree, 2, 9)).isTrue() + assertThat(model.isDropInto(tree, 2, 1)).isTrue() + assertThat(model.isDropInto(tree, 12, 9)).isTrue() + assertThat(model.isDropInto(tree, 12, 1)).isTrue() + assertThat(model.isDropInto(tree, 999, 9)).isFalse() + assertThat(model.isDropInto(tree, 999, 1)).isFalse() + assertThat(model.isDropInto(tree, 2, 999)).isFalse() + assertThat(model.isDropInto(tree, 2, -1)).isFalse() + } + + private fun doExpand() { + val toExpand = ArrayList() + RunConfigurable.collectNodesRecursively(root, toExpand, FOLDER) + assertThat(toExpand).hasSize(5) + val toExpand2 = ArrayList() + RunConfigurable.collectNodesRecursively(root, toExpand2, CONFIGURATION_TYPE) + toExpand.addAll(toExpand2) + for (node in toExpand) { + tree.expandPath(TreePath(node.path)) + } + + assertThat(ORDER.mapIndexed { index, nodeKind -> RunConfigurable.getKind(tree.getPathForRow(index).lastPathComponent as DefaultMutableTreeNode) }).containsExactly(*ORDER) + } + + private fun assertCan(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { + assertDrop(oldIndex, newIndex, position, true) + } + + private fun assertCannot(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { + assertDrop(oldIndex, newIndex, position, false) + } + + private fun assertDrop(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position, canDrop: Boolean) { + val message = StringBuilder() + message.append("(").append(oldIndex).append(")").append(tree.getPathForRow(oldIndex)).append("->") + message.append("(").append(newIndex).append(")").append(tree.getPathForRow(newIndex)).append(position) + if (canDrop) { + // message.toString() + assertThat(model.canDrop(oldIndex, newIndex, position)).isTrue() + } + else { + // message.toString() + assertThat(model.canDrop(oldIndex, newIndex, position)).isFalse() + } + } + + 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 fun checkPositionToMove(selectedRow: Int, direction: Int, expected: Trinity?) { + tree.setSelectionRow(selectedRow) + assertThat(configurable!!.getAvailableDropPosition(direction)).isEqualTo(expected) + } +} + +private class MockRunConfigurable(private val testManager: RunManagerImpl) : RunConfigurable(LightPlatformTestCase.getProject()) { + init { + createComponent() + } + + internal override fun getRunManager() = testManager +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/execution/impl/folders.xml b/java/java-tests/testSrc/com/intellij/execution/impl/folders.xml new file mode 100644 index 000000000000..a32681bd5e72 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/execution/impl/folders.xml @@ -0,0 +1,489 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + \ No newline at end of file