Skip to content

Commit 3d5c582

Browse files
assertArrayEquals overload is not found, tests doesn't compile #135
resolving merge conflict with main branch, use the very last (just added to the list) library with matching name
1 parent 80dcff4 commit 3d5c582

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ import com.intellij.openapi.application.runWriteAction
3838
import com.intellij.openapi.command.WriteCommandAction
3939
import com.intellij.openapi.components.service
4040
import com.intellij.openapi.editor.colors.EditorColorsManager
41+
import com.intellij.openapi.module.Module
4142
import com.intellij.openapi.options.ShowSettingsUtil
4243
import com.intellij.openapi.projectRoots.JavaSdkVersion
4344
import com.intellij.openapi.roots.ContentEntry
4445
import com.intellij.openapi.roots.DependencyScope
4546
import com.intellij.openapi.roots.ExternalLibraryDescriptor
4647
import com.intellij.openapi.roots.JavaProjectModelModificationService
48+
import com.intellij.openapi.roots.LibraryOrderEntry
49+
import com.intellij.openapi.roots.ModifiableRootModel
4750
import com.intellij.openapi.roots.ModuleRootManager
51+
import com.intellij.openapi.roots.ModuleRootModificationUtil
52+
import com.intellij.openapi.roots.ModuleSourceOrderEntry
4853
import com.intellij.openapi.roots.ui.configuration.ClasspathEditor
4954
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable
5055
import com.intellij.openapi.ui.ComboBox
@@ -111,6 +116,8 @@ import javax.swing.JComponent
111116
import javax.swing.JList
112117
import javax.swing.JPanel
113118
import kotlin.streams.toList
119+
import org.jetbrains.concurrency.thenRun
120+
import org.utbot.intellij.plugin.ui.utils.allLibraries
114121

115122
private const val RECENTS_KEY = "org.utbot.recents"
116123

@@ -642,7 +649,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
642649
}
643650

644651
selectedTestFramework.isInstalled = true
645-
addDependency(libraryDescriptor)
652+
addDependency(model.testModule, libraryDescriptor)
646653
.onError { selectedTestFramework.isInstalled = false }
647654
}
648655

@@ -663,7 +670,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
663670
val versionInProject = libraryInProject?.libraryName?.parseVersion()
664671

665672
selectedMockFramework.isInstalled = true
666-
addDependency(mockitoCoreLibraryDescriptor(versionInProject))
673+
addDependency(model.testModule, mockitoCoreLibraryDescriptor(versionInProject))
667674
.onError { selectedMockFramework.isInstalled = false }
668675
}
669676

@@ -701,11 +708,34 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
701708
* Note that version restrictions will be applied only if they are present on target machine
702709
* Otherwise latest release version will be installed.
703710
*/
704-
private fun addDependency(libraryDescriptor: ExternalLibraryDescriptor): Promise<Void> {
705-
return JavaProjectModelModificationService
711+
private fun addDependency(module: Module, libraryDescriptor: ExternalLibraryDescriptor): Promise<Void> {
712+
val promise = JavaProjectModelModificationService
706713
.getInstance(model.project)
707714
//this method returns JetBrains internal Promise that is difficult to deal with, but it is our way
708715
.addDependency(model.testModule, libraryDescriptor, DependencyScope.TEST)
716+
promise.thenRun {
717+
module.allLibraries()
718+
.lastOrNull { library -> library.libraryName == libraryDescriptor.presentableName }?.let {
719+
ModuleRootModificationUtil.updateModel(module) { model -> placeEntryToCorrectPlace(model, it) }
720+
}
721+
}
722+
return promise
723+
}
724+
725+
/**
726+
* Reorders library list to unsure that just added library with proper version is listed prior to old-versioned one
727+
*/
728+
private fun placeEntryToCorrectPlace(model: ModifiableRootModel, addedEntry: LibraryOrderEntry) {
729+
val order = model.orderEntries
730+
val lastEntry = order.last()
731+
if (lastEntry is LibraryOrderEntry && lastEntry.library == addedEntry.library) {
732+
val insertionPoint = order.indexOfFirst { it is ModuleSourceOrderEntry } + 1
733+
if (insertionPoint > 0) {
734+
System.arraycopy(order, insertionPoint, order, insertionPoint + 1, order.size - 1 - insertionPoint)
735+
order[insertionPoint] = lastEntry
736+
model.rearrangeOrderEntries(order)
737+
}
738+
}
709739
}
710740

711741
private fun createMockFrameworkNotificationDialog() = Messages.showYesNoDialog(

0 commit comments

Comments
 (0)