From ff79c74da308325987c7c21115c2478fe96c58eb Mon Sep 17 00:00:00 2001 From: Arkadii Sapozhnikov Date: Fri, 30 Aug 2024 21:31:46 +0200 Subject: [PATCH 1/2] add return type to applyTests function --- .../display/generatedTests/GeneratedTestsTabBuilder.kt | 4 ++-- .../testspark/display/utils/java/JavaDisplayUtils.kt | 8 +++++--- .../testspark/display/utils/kotlin/KotlinDisplayUtils.kt | 8 +++++--- .../testspark/display/utils/template/DisplayUtils.kt | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GeneratedTestsTabBuilder.kt b/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GeneratedTestsTabBuilder.kt index 514430596..d3861f123 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GeneratedTestsTabBuilder.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GeneratedTestsTabBuilder.kt @@ -199,10 +199,10 @@ class GeneratedTestsTabBuilder( .map { generatedTestsTabData.testCaseNameToEditorTextField[it]!! } .map { it.document.text } - displayUtils!!.applyTests(project, uiContext, testCaseComponents) + val applyingResult = displayUtils!!.applyTests(project, uiContext, testCaseComponents) // Remove the selected test cases from the cache and the tool window UI - clear() + if (applyingResult) clear() } /** diff --git a/src/main/kotlin/org/jetbrains/research/testspark/display/utils/java/JavaDisplayUtils.kt b/src/main/kotlin/org/jetbrains/research/testspark/display/utils/java/JavaDisplayUtils.kt index 7d5043747..0320308d7 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/display/utils/java/JavaDisplayUtils.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/display/utils/java/JavaDisplayUtils.kt @@ -30,7 +30,7 @@ import java.util.Locale import javax.swing.JOptionPane class JavaDisplayUtils : DisplayUtils { - override fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List) { + override fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List): Boolean { // Descriptor for choosing folders and java files val descriptor = FileChooserDescriptor(true, true, false, false, false, false) @@ -61,7 +61,7 @@ class JavaDisplayUtils : DisplayUtils { /** * Cancel button pressed */ - if (fileChooser.isEmpty()) return + if (fileChooser.isEmpty()) return false /** * Chosen files by user @@ -102,7 +102,7 @@ class JavaDisplayUtils : DisplayUtils { ) // Cancel button pressed - jOptionPane ?: return + jOptionPane ?: return false // Get class name from user className = jOptionPane as String @@ -158,6 +158,8 @@ class JavaDisplayUtils : DisplayUtils { OpenFileDescriptor(project, virtualFile!!), true, ) + + return true } override fun appendTestsToClass( diff --git a/src/main/kotlin/org/jetbrains/research/testspark/display/utils/kotlin/KotlinDisplayUtils.kt b/src/main/kotlin/org/jetbrains/research/testspark/display/utils/kotlin/KotlinDisplayUtils.kt index 9847d5c4a..f2d61231a 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/display/utils/kotlin/KotlinDisplayUtils.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/display/utils/kotlin/KotlinDisplayUtils.kt @@ -32,7 +32,7 @@ import java.util.Locale import javax.swing.JOptionPane class KotlinDisplayUtils : DisplayUtils { - override fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List) { + override fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List): Boolean { val descriptor = FileChooserDescriptor(true, true, false, false, false, false) // Apply filter with folders and java files with main class @@ -62,7 +62,7 @@ class KotlinDisplayUtils : DisplayUtils { /** * Cancel button pressed */ - if (fileChooser.isEmpty()) return + if (fileChooser.isEmpty()) return false /** * Chosen files by user @@ -103,7 +103,7 @@ class KotlinDisplayUtils : DisplayUtils { ) // Cancel button pressed - jOptionPane ?: return + jOptionPane ?: return false // Get class name from user className = jOptionPane as String @@ -167,6 +167,8 @@ class KotlinDisplayUtils : DisplayUtils { OpenFileDescriptor(project, virtualFile!!), true, ) + + return true } override fun appendTestsToClass( diff --git a/src/main/kotlin/org/jetbrains/research/testspark/display/utils/template/DisplayUtils.kt b/src/main/kotlin/org/jetbrains/research/testspark/display/utils/template/DisplayUtils.kt index 89ea668b6..5c6d30403 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/display/utils/template/DisplayUtils.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/display/utils/template/DisplayUtils.kt @@ -13,7 +13,7 @@ interface DisplayUtils { /** * Applies specified tests to a given project. */ - fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List) + fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List): Boolean /** * Appends specified tests to a class within the given project. From 27402406c31af40eb39685ffe0746bdab602e50a Mon Sep 17 00:00:00 2001 From: Arkadii Sapozhnikov Date: Fri, 27 Sep 2024 14:19:10 +0200 Subject: [PATCH 2/2] update DisplayUtils.applyTests comment --- .../research/testspark/display/utils/template/DisplayUtils.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/org/jetbrains/research/testspark/display/utils/template/DisplayUtils.kt b/src/main/kotlin/org/jetbrains/research/testspark/display/utils/template/DisplayUtils.kt index 5c6d30403..5beb63a73 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/display/utils/template/DisplayUtils.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/display/utils/template/DisplayUtils.kt @@ -12,6 +12,8 @@ import org.jetbrains.research.testspark.langwrappers.PsiClassWrapper interface DisplayUtils { /** * Applies specified tests to a given project. + * + * @returns true, if tests applying is successful, otherwise false */ fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List): Boolean