Skip to content

Commit

Permalink
Merge pull request #333 from JetBrains-Research/arksap2002/bugs/cance…
Browse files Browse the repository at this point in the history
…l-tests-applying

Add return type to applyTests function
  • Loading branch information
arksap2002 authored Sep 27, 2024
2 parents 3f0a1b3 + 2740240 commit 09ad147
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import java.util.Locale
import javax.swing.JOptionPane

class JavaDisplayUtils : DisplayUtils {
override fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List<String>) {
override fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List<String>): Boolean {
// Descriptor for choosing folders and java files
val descriptor = FileChooserDescriptor(true, true, false, false, false, false)

Expand Down Expand Up @@ -61,7 +61,7 @@ class JavaDisplayUtils : DisplayUtils {
/**
* Cancel button pressed
*/
if (fileChooser.isEmpty()) return
if (fileChooser.isEmpty()) return false

/**
* Chosen files by user
Expand Down Expand Up @@ -102,7 +102,7 @@ class JavaDisplayUtils : DisplayUtils {
)

// Cancel button pressed
jOptionPane ?: return
jOptionPane ?: return false

// Get class name from user
className = jOptionPane as String
Expand Down Expand Up @@ -158,6 +158,8 @@ class JavaDisplayUtils : DisplayUtils {
OpenFileDescriptor(project, virtualFile!!),
true,
)

return true
}

override fun appendTestsToClass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import java.util.Locale
import javax.swing.JOptionPane

class KotlinDisplayUtils : DisplayUtils {
override fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List<String>) {
override fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List<String>): Boolean {
val descriptor = FileChooserDescriptor(true, true, false, false, false, false)

// Apply filter with folders and java files with main class
Expand Down Expand Up @@ -62,7 +62,7 @@ class KotlinDisplayUtils : DisplayUtils {
/**
* Cancel button pressed
*/
if (fileChooser.isEmpty()) return
if (fileChooser.isEmpty()) return false

/**
* Chosen files by user
Expand Down Expand Up @@ -103,7 +103,7 @@ class KotlinDisplayUtils : DisplayUtils {
)

// Cancel button pressed
jOptionPane ?: return
jOptionPane ?: return false

// Get class name from user
className = jOptionPane as String
Expand Down Expand Up @@ -167,6 +167,8 @@ class KotlinDisplayUtils : DisplayUtils {
OpenFileDescriptor(project, virtualFile!!),
true,
)

return true
}

override fun appendTestsToClass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ 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<String>)
fun applyTests(project: Project, uiContext: UIContext?, testCaseComponents: List<String>): Boolean

/**
* Appends specified tests to a class within the given project.
Expand Down

0 comments on commit 09ad147

Please sign in to comment.