-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from JetBrains-Research/test-execution
Highlighting
- Loading branch information
Showing
26 changed files
with
972 additions
and
668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/kotlin/org/jetbrains/research/testspark/services/JavaClassBuilderService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.jetbrains.research.testspark.services | ||
|
||
import com.intellij.openapi.project.Project | ||
|
||
class JavaClassBuilderService(private val project: Project) { | ||
/** | ||
* Generates the code for a test class. | ||
* | ||
* @param className the name of the test class | ||
* @param body the body of the test class | ||
* @return the generated code as a string | ||
*/ | ||
fun generateCode( | ||
className: String, | ||
body: String, | ||
imports: Set<String>, | ||
packageString: String, | ||
runWith: String, | ||
otherInfo: String, | ||
): String { | ||
var testFullText = printUpperPart(className, imports, packageString, runWith, otherInfo) | ||
|
||
// Add each test (exclude expected exception) | ||
testFullText += body | ||
|
||
// close the test class | ||
testFullText += "}" | ||
|
||
return testFullText | ||
} | ||
|
||
/** | ||
* Returns the upper part of test suite (package name, imports, and test class name) as a string. | ||
* | ||
* @return the upper part of test suite (package name, imports, and test class name) as a string. | ||
*/ | ||
private fun printUpperPart( | ||
className: String, | ||
imports: Set<String>, | ||
packageString: String, | ||
runWith: String, | ||
otherInfo: String, | ||
): String { | ||
var testText = "" | ||
|
||
// Add package | ||
if (packageString.isNotBlank()) { | ||
testText += "package $packageString;\n" | ||
} | ||
|
||
// add imports | ||
imports.forEach { importedElement -> | ||
testText += "$importedElement\n" | ||
} | ||
|
||
testText += "\n" | ||
|
||
// add runWith if exists | ||
if (runWith.isNotBlank()) { | ||
testText += "@RunWith($runWith)\n" | ||
} | ||
// open the test class | ||
testText += "public class $className{\n\n" | ||
|
||
// Add other presets (annotations, non-test functions) | ||
if (otherInfo.isNotBlank()) { | ||
testText += otherInfo | ||
} | ||
|
||
return testText | ||
} | ||
} |
Oops, something went wrong.