[gui-tests] Greenify

This commit is contained in:
Maxim.Kolmakov
2017-10-09 13:04:16 +02:00
parent def09d5c9f
commit 7733f67129
6 changed files with 23 additions and 46 deletions
@@ -38,15 +38,15 @@ object Writer {
private fun write(str: String) {
print(str)
if (GuiRecorderComponent.getFrame() != null && GuiRecorderComponent.getFrame()!!.isSyncToEditor())
if (GuiRecorderComponent.frame != null && GuiRecorderComponent.frame!!.isSyncToEditor())
writeToEditor(str)
else
scriptBuffer.append(str)
}
private fun writeToEditor(str: String) {
if (GuiRecorderComponent.getFrame() != null && GuiRecorderComponent.getFrame()!!.getEditor() != null) {
val editor = GuiRecorderComponent.getFrame()!!.getEditor()
if (GuiRecorderComponent.frame != null && GuiRecorderComponent.frame!!.getEditor() != null) {
val editor = GuiRecorderComponent.frame!!.getEditor()
val document = editor.document
WriteCommandAction.runWriteCommandAction(null, { document.insertString(document.textLength, str) })
}
@@ -14,7 +14,7 @@ import com.intellij.testGuiFramework.recorder.ui.Notifier
class UpdateEditorAction : AnAction(null, "Update GUI Script Editor (get recorded from buffer)", AllIcons.Actions.NextOccurence) {
override fun actionPerformed(actionEvent: AnActionEvent?) {
val editor = GuiRecorderComponent.getFrame()!!.getEditor()
val editor = GuiRecorderComponent.frame!!.getEditor()
ApplicationManager.getApplication().runWriteAction { editor.document.setText(getGuiScriptBuffer()) }
Notifier.updateStatus("GUI script updated")
}
@@ -76,7 +76,7 @@ class LocalCompiler {
LOG.error(ce.message)
}
})
GuiRecorderComponent.setCurrentTask(taskFuture)
GuiRecorderComponent.currentTask = taskFuture
}
@@ -99,14 +99,14 @@ class LocalCompiler {
"Unable to load by pluginClassLoader $TEST_CLASS_NAME.class file")
val testCase = currentTest.newInstance()
val testMethod = currentTest.getMethod(ScriptWrapper.TEST_METHOD_NAME)
GuiRecorderComponent.setState(GuiRecorderComponent.States.RUNNING)
GuiRecorderComponent.state = GuiRecorderComponent.States.RUNNING
try {
testMethod.invoke(testCase)
Notifier.updateStatus("Script stopped")
GuiRecorderComponent.setState(GuiRecorderComponent.States.IDLE)
GuiRecorderComponent.state = GuiRecorderComponent.States.IDLE
}
catch (throwable: Throwable) {
GuiRecorderComponent.setState(GuiRecorderComponent.States.RUNNING_ERROR)
GuiRecorderComponent.state = GuiRecorderComponent.States.RUNNING_ERROR
Notifier.updateStatus("Running error, please see idea.log")
throw throwable
}
@@ -132,15 +132,15 @@ class LocalCompiler {
val setUpMethod = currentTest.getMethod("setUp")
val testMethod = currentTest.getMethod(ScriptWrapper.TEST_METHOD_NAME)
Notifier.updateStatus("${Notifier.LONG_OPERATION_PREFIX}Script running...")
GuiRecorderComponent.setState(GuiRecorderComponent.States.RUNNING)
GuiRecorderComponent.state = GuiRecorderComponent.States.RUNNING
try {
setUpMethod.invoke(testCase)
testMethod.invoke(testCase)
Notifier.updateStatus("Script stopped")
GuiRecorderComponent.setState(GuiRecorderComponent.States.IDLE)
GuiRecorderComponent.state = GuiRecorderComponent.States.IDLE
}
catch (throwable: Throwable) {
GuiRecorderComponent.setState(GuiRecorderComponent.States.RUNNING_ERROR)
GuiRecorderComponent.state = GuiRecorderComponent.States.RUNNING_ERROR
Notifier.updateStatus("Running error, please see idea.log")
throw throwable
}
@@ -164,7 +164,7 @@ class LocalCompiler {
val libDirLocation = getApplicationLibDir().parentFile
Notifier.updateStatus("${Notifier.LONG_OPERATION_PREFIX}Compiling...")
GuiRecorderComponent.setState(GuiRecorderComponent.States.COMPILING)
GuiRecorderComponent.state = GuiRecorderComponent.States.COMPILING
val compilationProcessBuilder = if (SystemInfo.isWindows)
@@ -182,12 +182,12 @@ class LocalCompiler {
if (process.exitValue() == 1) {
LOG.error(BufferedReader(InputStreamReader(process.errorStream)).lines().collect(Collectors.joining("\n")))
Notifier.updateStatus("Compilation error (see idea.log)")
GuiRecorderComponent.setState(GuiRecorderComponent.States.COMPILATION_ERROR)
GuiRecorderComponent.state = GuiRecorderComponent.States.COMPILATION_ERROR
throw CompilationException("Compilation error (see idea.log)")
}
else {
Notifier.updateStatus("Compilation is done")
GuiRecorderComponent.setState(GuiRecorderComponent.States.COMPILATION_DONE)
GuiRecorderComponent.state = GuiRecorderComponent.States.COMPILATION_DONE
}
return wait
}
@@ -28,32 +28,19 @@ object GuiRecorderComponent : ApplicationComponent, Disposable {
enum class States {IDLE, COMPILING, COMPILATION_ERROR, COMPILATION_DONE, RUNNING, RUNNING_ERROR, TEST_INIT }
var myState: States = States.IDLE;
var state: States = States.IDLE
var frame: GuiScriptEditorFrame? = null
var currentTask: Future<*>? = null
override fun dispose() {
}
private var myFrame: GuiScriptEditorFrame? = null
private var currentTask: Future<*>? = null
override fun dispose() {}
override fun getComponentName() = "GuiRecorderComponent"
fun setCurrentTask(task: Future<*>) { currentTask = task }
fun cancelCurrentTask() {
if (currentTask != null && !currentTask!!.isDone) currentTask!!.cancel(true)
}
fun getState() = myState
fun setState(yaState: States) {
myState = yaState
}
fun getFrame() = myFrame
fun getEditor() = myFrame!!.getGuiScriptEditorPanel().editor
fun getEditor() = frame!!.getGuiScriptEditorPanel().editor
fun placeCaretToEnd() {
val caretModel = getEditor().caretModel
@@ -61,17 +48,7 @@ object GuiRecorderComponent : ApplicationComponent, Disposable {
caretModel.moveToLogicalPosition(LogicalPosition(lineCount + 1, 0))
}
fun registerFrame(frame: GuiScriptEditorFrame) {
myFrame = frame
}
fun unregisterFrame() {
if (myFrame != null)
myFrame!!.dispose()
}
fun disposeFrame() {
myFrame = null
frame = null
}
}
@@ -52,7 +52,7 @@ class GuiScriptEditorFrame : Disposable {
myFrame.pack()
myFrame.isVisible = true
GuiRecorderComponent.registerFrame(this)
GuiRecorderComponent.frame = this
myFrame.addWindowListener(object : WindowAdapter() {
override fun windowClosing(e: WindowEvent?) {
dispose()
@@ -27,8 +27,8 @@ object Notifier {
fun updateStatus(statusMessage: String) {
if (GuiRecorderComponent.getFrame() == null) return
val guiScriptEditorPanel = GuiRecorderComponent.getFrame()!!.getGuiScriptEditorPanel()
if (GuiRecorderComponent.frame == null) return
val guiScriptEditorPanel = GuiRecorderComponent.frame!!.getGuiScriptEditorPanel()
val statusHandler: (String) -> Unit = { status ->
if (status.startsWith(LONG_OPERATION_PREFIX)) {