Skip to content

Commit

Permalink
FBP-289. Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
valb3r committed Jul 2, 2023
1 parent 8c5d44d commit 9725e97
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import javax.swing.Icon
import javax.swing.JButton
import javax.swing.JCheckBox
import javax.swing.JTable
import javax.swing.JTextField
import javax.swing.SwingConstants
import javax.swing.plaf.basic.BasicArrowButton
import javax.swing.table.TableColumn
Expand Down Expand Up @@ -194,6 +195,7 @@ abstract class BaseUiTest {
protected val editorFactory = { id: BpmnElementId, type: PropertyType, value: String -> textFieldsConstructed.computeIfAbsent(Pair(id, type)) {
val res = mock<TextValueAccessor>()
whenever(res.text).thenReturn(value)
whenever(res.component).thenReturn(JTextField())
return@computeIfAbsent res
} }
protected val multiLineEditorFactory = { id: BpmnElementId, type: PropertyType, value: String -> multiLineTextFieldsConstructed.computeIfAbsent(Pair(id, type)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.valb3r.bpmn.intellij.plugin

import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.never
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyType
import com.valb3r.bpmn.intellij.plugin.core.newelements.registerNewElementsFactory
import com.valb3r.bpmn.intellij.plugin.core.properties.propertiesVisualizer
import com.valb3r.bpmn.intellij.plugin.core.tests.BaseUiTest
import com.valb3r.bpmn.intellij.plugin.flowable.parser.FlowableObjectFactory
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import javax.swing.JTextField

internal class ValidationTest: BaseUiTest() {

@BeforeEach
fun prepare() {
registerNewElementsFactory(project, FlowableObjectFactory())
prepareTwoServiceTaskView()
}

@Test
fun `Invalid ID (duplicate) not propagated`() {
clickOnId(serviceTaskEndDiagramId)
val idField = textFieldsConstructed[Pair(serviceTaskEndBpmnId, PropertyType.ID)]!!
whenever(idField.text).thenReturn(serviceTaskStartBpmnId.id)
(idField.component as JTextField).text = serviceTaskStartBpmnId.id

propertiesVisualizer(project).clear()

verify(fileCommitter, never()).executeCommitAndGetHash(any(), any(), any(), any())
}

@Test
fun `Valid ID (not duplicate) propagated`() {
clickOnId(serviceTaskEndDiagramId)
val idField = textFieldsConstructed[Pair(serviceTaskEndBpmnId, PropertyType.ID)]!!
whenever(idField.text).thenReturn(serviceTaskStartBpmnId.id + '1')
(idField.component as JTextField).text = serviceTaskStartBpmnId.id + '1'

propertiesVisualizer(project).clear()

verify(fileCommitter).executeCommitAndGetHash(any(), any(), any(), any())
}
}

0 comments on commit 9725e97

Please sign in to comment.