Skip to content

Commit a75906a

Browse files
Merge branch 'main' into Vassiliy-Kudryashov/157-first-time-use-we-may-help-user-with-got-it-tooltip
2 parents 6395569 + 65e3f7e commit a75906a

File tree

4 files changed

+91
-52
lines changed

4 files changed

+91
-52
lines changed
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: Manual testing plan
2+
name: Manual testing checklist
33
about: Checklist of testing process
44
title: ''
55
labels: ''
@@ -9,47 +9,48 @@ assignees: ''
99

1010
**Initial set-up**
1111

12-
- [ ] Check that the IntelliJ Idea UTBot plugin can be successfully installed
12+
*Check that the IntelliJ Idea UTBot plugin can be successfully installed*
13+
1314
- [ ] Choose appropriate workflow from the next list (by default, use the latest one) https://github.com/UnitTestBot/UTBotJava/actions/workflows/publish-plugin-and-cli.yml
1415
- [ ] Open IntelliJ IDE
15-
- [ ] Remove the latest version of the UTBot plugin
16-
- [ ] Clone or reuse UTBot workspace (https://github.com/UnitTestBot/UTBotJava.git)
17-
- [ ] Open the workspace in the IDE with the installed plugin
18-
- [ ] Build workspace (Instruction is needed)
19-
- [ ] Go through manual scenarios
16+
- [ ] Remove previously installed UTBot plugin
17+
- [ ] Clone or reuse UTBot project (https://github.com/UnitTestBot/UTBotJava.git)
18+
- [ ] Open the project in the IDE
19+
- [ ] Install the downloaded plugin
2020

21+
*Go through manual scenarios*
2122

2223
**Manual scenario #1**
2324

2425
- [ ] Use default plugin settings
2526
- [ ] Open the utbot-sample/src/main/java/org/utbot/examples/algorithms/ArraysQuickSort.java file
26-
- [ ] Try to generate tests for the class
27+
- [ ] Generate tests for the class
2728
- [ ] Remove results
28-
- [ ] Try to generate tests for the methods
29+
- [ ] Generate tests for the methods
2930

3031

3132
**Manual scenario #2**
3233

3334
- [ ] Use default plugin settings
3435
- [ ] Open the utbot-sample/src/main/java/org/utbot/examples/mock/CommonMocksExample.java file
35-
- [ ] Try to generate tests with all available (mocking) options
36+
- [ ] Generate tests with all available (mocking) options
3637

3738

3839
**Manual scenario #3**
3940

4041
- [ ] Create a new Gradle project
4142
- [ ] Add a simple java file to test
42-
- [ ] Try to generate a test with a new test root
43+
- [ ] Generate a test with a new test root
4344

4445

4546
**Manual scenario #4**
4647

47-
- [ ] Create a new Idea project
48+
- [ ] Create a new Maven project
4849
- [ ] Add a simple java file to test
49-
- [ ] Try to generate a test with a new test root
50+
- [ ] Generate a test with a new test root
5051

51-
**Manual scenario #4**
52+
**Manual scenario #5**
5253

5354
- [ ] Create a new Idea project
5455
- [ ] Add a simple java file to test
55-
- [ ] Try to generate tests for several classes
56+
- [ ] Generate tests for several classes

DEVNOTE.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88

99
![image](https://user-images.githubusercontent.com/106974353/174806216-9d4969b4-51fb-4531-a6d0-94e3734a437a.png)
1010

11-
*don\`t forget to check your Project SDK and Gradle SDK are of 1.8 Java version.
11+
⚠️ Important don\`t forgets at this step:
12+
13+
✔️ check your Project SDK and Gradle SDK are of 1.8 Java version.
1214

1315
![image](https://user-images.githubusercontent.com/106974353/174812758-fcbabb5b-0411-48d7-aefe-6d69873185e3.png)
1416
![image](https://user-images.githubusercontent.com/106974353/174806632-ed796fb7-57dd-44b5-b499-e9eeb0436f15.png)
1517

18+
✔️ check your System environment variables: the KOTLIN_HOME variable path should be set up
19+
20+
![image](https://user-images.githubusercontent.com/106974353/175059333-4f3b0083-7964-4886-8fcd-48c475fc1fb3.png)
21+
22+
1623
3. Open Gradle tool window
1724
4. Launch Task utbot > Tasks > build > assemble
1825

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/CgJavaRenderer.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,19 @@ internal class CgJavaRenderer(context: CgContext, printer: CgPrinter = CgPrinter
105105
}
106106

107107
override fun visit(element: CgTypeCast) {
108-
// TODO: check cases when element.expression is CgLiteral of primitive wrapper type and element.targetType is primitive
109-
// TODO: example: (double) 1.0, (float) 1.0f, etc.
108+
val expr = element.expression
109+
val wrappedTargetType = wrapperByPrimitive.getOrDefault(element.targetType, element.targetType)
110+
val exprTypeIsSimilar = expr.type == element.targetType || expr.type == wrappedTargetType
111+
110112
// cast for null is mandatory in case of ambiguity - for example, readObject(Object) and readObject(Map)
111-
if (element.expression.type == element.targetType && element.expression != nullLiteral()) {
113+
if (exprTypeIsSimilar && expr != nullLiteral()) {
112114
element.expression.accept(this)
113115
return
114116
}
115117

116-
val elementTargetType = element.targetType
117-
val targetType = wrapperByPrimitive.getOrDefault(elementTargetType, elementTargetType)
118-
119118
print("(")
120119
print("(")
121-
print(targetType.asString())
120+
print(wrappedTargetType.asString())
122121
print(") ")
123122
element.expression.accept(this)
124123
print(")")

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

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import com.intellij.openapi.application.runWriteAction
3636
import com.intellij.openapi.command.WriteCommandAction
3737
import com.intellij.openapi.components.service
3838
import com.intellij.openapi.options.ShowSettingsUtil
39+
import com.intellij.openapi.projectRoots.JavaSdkVersion
40+
import com.intellij.openapi.roots.ContentEntry
3941
import com.intellij.openapi.roots.DependencyScope
4042
import com.intellij.openapi.roots.ExternalLibraryDescriptor
4143
import com.intellij.openapi.roots.JavaProjectModelModificationService
@@ -45,6 +47,8 @@ import com.intellij.openapi.ui.ComboBox
4547
import com.intellij.openapi.ui.DialogPanel
4648
import com.intellij.openapi.ui.DialogWrapper
4749
import com.intellij.openapi.ui.Messages
50+
import com.intellij.openapi.ui.ValidationInfo
51+
import com.intellij.openapi.ui.popup.IconButton
4852
import com.intellij.openapi.vfs.VfsUtil
4953
import com.intellij.openapi.vfs.VfsUtilCore.urlToPath
5054
import com.intellij.openapi.vfs.VirtualFile
@@ -70,16 +74,27 @@ import com.intellij.ui.layout.Row
7074
import com.intellij.ui.layout.panel
7175
import com.intellij.util.IncorrectOperationException
7276
import com.intellij.util.io.exists
77+
import com.intellij.util.lang.JavaVersion
78+
import com.intellij.util.ui.JBUI
79+
import com.intellij.util.ui.JBUI.Borders.empty
80+
import com.intellij.util.ui.JBUI.Borders.merge
81+
import com.intellij.util.ui.JBUI.scale
7382
import com.intellij.util.ui.JBUI.size
83+
import com.intellij.util.ui.UIUtil
84+
import com.intellij.util.ui.components.BorderLayoutPanel
7485
import java.awt.BorderLayout
7586
import java.nio.file.Files
7687
import java.nio.file.Path
7788
import java.nio.file.Paths
7889
import java.util.Objects
7990
import java.util.concurrent.TimeUnit
91+
import javax.swing.DefaultComboBoxModel
92+
import javax.swing.JComboBox
93+
import javax.swing.JComponent
94+
import javax.swing.JList
95+
import javax.swing.JPanel
8096
import kotlin.streams.toList
8197
import org.jetbrains.concurrency.Promise
82-
import javax.swing.*
8398

8499
private const val RECENTS_KEY = "org.utbot.recents"
85100

@@ -257,6 +272,34 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
257272

258273
private fun checkMembers(members: List<MemberInfo>) = members.forEach { it.isChecked = true }
259274

275+
private fun getTestRoot() : VirtualFile? {
276+
model.testSourceRoot?.let {
277+
if (it.isDirectory) return it
278+
}
279+
return null
280+
}
281+
282+
override fun doValidate(): ValidationInfo? {
283+
if (getTestRoot() == null) {
284+
return ValidationInfo("Test source root is not configured", testSourceFolderField.childComponent)
285+
}
286+
if (getRootDirectoryAndContentEntry() == null) {
287+
return ValidationInfo("Test source root is located out of content entry", testSourceFolderField.childComponent)
288+
}
289+
290+
membersTable.tableHeader?.background = UIUtil.getTableBackground()
291+
membersTable.background = UIUtil.getTableBackground()
292+
if (membersTable.selectedMemberInfos.isEmpty()) {
293+
membersTable.tableHeader?.background = JBUI.CurrentTheme.Validator.errorBackgroundColor()
294+
membersTable.background = JBUI.CurrentTheme.Validator.errorBackgroundColor()
295+
return ValidationInfo(
296+
"Tick any methods to generate tests for", membersTable
297+
)
298+
}
299+
return null
300+
}
301+
302+
260303
override fun doOKAction() {
261304
model.testPackageName =
262305
if (testPackageField.text != SAME_PACKAGE_LABEL) testPackageField.text else ""
@@ -330,20 +373,18 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
330373
* Creates test source root if absent and target packages for tests.
331374
*/
332375
private fun createTestRootAndPackages(): Boolean {
333-
val testSourceRoot = model.testSourceRoot ?: return false
334-
if (model.testSourceRoot?.isDirectory != true) return false
376+
val (sourceRoot, contentEntry) = getRootDirectoryAndContentEntry() ?: return false
377+
val modifiableModel = ModuleRootManager.getInstance(model.testModule).modifiableModel
378+
VfsUtil.createDirectoryIfMissing(urlToPath(sourceRoot.url))
379+
contentEntry.addSourceFolder(sourceRoot.url, codegenLanguages.item.testRootType())
380+
WriteCommandAction.runWriteCommandAction(model.project) { modifiableModel.commit() }
335381

336-
val rootExists = getOrCreateTestRoot(testSourceRoot)
337-
if (rootExists) {
338-
if (cbSpecifyTestPackage.isSelected) {
339-
createSelectedPackage(testSourceRoot)
340-
} else {
341-
createPackagesByClasses(testSourceRoot)
342-
}
343-
return true
382+
if (cbSpecifyTestPackage.isSelected) {
383+
createSelectedPackage(sourceRoot)
384+
} else {
385+
createPackagesByClasses(sourceRoot)
344386
}
345-
346-
return false
387+
return true
347388
}
348389

349390
private fun createPackagesByClasses(testSourceRoot: VirtualFile) {
@@ -372,19 +413,12 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
372413
"Generation error"
373414
)
374415

375-
private fun getOrCreateTestRoot(testSourceRoot: VirtualFile): Boolean {
376-
val modifiableModel = ModuleRootManager.getInstance(model.testModule).modifiableModel
377-
val contentEntry = modifiableModel.contentEntries
416+
private fun getRootDirectoryAndContentEntry() : Pair<VirtualFile, ContentEntry>? {
417+
val testSourceRoot = getTestRoot()?: return null
418+
val contentEntry = ModuleRootManager.getInstance(model.testModule).contentEntries
378419
.filterNot { it.file == null }
379-
.firstOrNull { VfsUtil.isAncestor(it.file!!, testSourceRoot, true) }
380-
?: return false
381-
382-
VfsUtil.createDirectoryIfMissing(urlToPath(testSourceRoot.url))
383-
384-
contentEntry.addSourceFolder(testSourceRoot.url, codegenLanguages.item.testRootType())
385-
WriteCommandAction.runWriteCommandAction(model.project) { modifiableModel.commit() }
386-
387-
return true
420+
.firstOrNull { VfsUtil.isAncestor(it.file!!, testSourceRoot, true) } ?: return null
421+
return Pair(testSourceRoot, contentEntry)
388422
}
389423

390424
private fun createPackageWrapper(packageName: String?): PackageWrapper =
@@ -614,9 +648,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
614648
itemsToHelpTooltip.forEach { (box, tooltip) -> box.setHelpTooltipTextChanger(tooltip) }
615649

616650
testSourceFolderField.childComponent.addActionListener { event ->
617-
val item = (event.source as JComboBox<*>).selectedItem as String
618-
619-
pathToFile(item)?.let { model.testSourceRoot = it }
651+
model.testSourceRoot = pathToFile((event.source as JComboBox<*>).selectedItem as String)
620652
}
621653

622654
mockStrategies.addActionListener { event ->
@@ -754,7 +786,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
754786
}
755787

756788
private fun staticsMockingConfigured(): Boolean {
757-
val entries = ModuleRootManager.getInstance(model.testModule).modifiableModel.contentEntries
789+
val entries = ModuleRootManager.getInstance(model.testModule).contentEntries
758790
val hasEntriesWithoutResources = entries
759791
.filterNot { it.sourceFolders.any { f -> f.rootType in testResourceRootTypes } }
760792
.isNotEmpty()

0 commit comments

Comments
 (0)