Skip to content

Commit

Permalink
update adorner unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mi-sts committed May 4, 2024
1 parent cccc64b commit d7b30e2
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package solve.interactive.scene.view.association

import javafx.beans.property.SimpleDoubleProperty
import javafx.scene.layout.Pane
import javafx.scene.shape.Rectangle
import org.junit.jupiter.api.Assertions.assertEquals
Expand All @@ -11,18 +10,19 @@ import solve.interactive.InteractiveTestClass
import solve.scene.view.association.AssociationAdorner
import solve.testMemoryLeak
import solve.utils.structures.DoublePoint
import tornadofx.*

@ExtendWith(ApplicationExtension::class)
internal class AssociationConnectionAdornerTests : InteractiveTestClass() {
@Test
fun `Adorner rectangle fills the corresponding frame`() {
val width = 10.0
val height = 5.0
val position = DoublePoint(20.0, 30.0)
val scale = SimpleDoubleProperty(1.0)
val adorner = AssociationAdorner(width, height, position, scale)
assertEquals(position.x, adorner.node.layoutX)
assertEquals(position.y, adorner.node.layoutY)
val getPosition = { DoublePoint(20.0, 30.0) }
val getScale = { 1.0 }
val adorner = AssociationAdorner(width, height, getPosition, getScale)
assertEquals(getPosition().x, adorner.node.layoutX)
assertEquals(getPosition().y, adorner.node.layoutY)
val pane = adorner.node as Pane
val rect = pane.children.filterIsInstance<Rectangle>().single()
assertEquals(width, rect.width)
Expand All @@ -33,9 +33,11 @@ internal class AssociationConnectionAdornerTests : InteractiveTestClass() {
fun `Scale adorner`() {
val width = 10.0
val height = 5.0
val position = DoublePoint(20.0, 30.0)
val scale = SimpleDoubleProperty(2.0)
val adorner = AssociationAdorner(width, height, position, scale)
val getPosition = { DoublePoint(20.0, 30.0) }
val scale = doubleProperty(2.0)
val getScale = { scale.value }
val adorner = AssociationAdorner(width, height, getPosition, getScale)
val position = getPosition()
assertEquals(position.x * scale.value, adorner.node.layoutX)
assertEquals(position.y * scale.value, adorner.node.layoutY)
val pane = adorner.node as Pane
Expand All @@ -44,7 +46,7 @@ internal class AssociationConnectionAdornerTests : InteractiveTestClass() {
assertEquals(height * scale.value, rect.height)

scale.value = 0.5

Thread.sleep(100)
assertEquals(position.x * scale.value, adorner.node.layoutX)
assertEquals(position.y * scale.value, adorner.node.layoutY)
assertEquals(width * scale.value, rect.width)
Expand All @@ -53,10 +55,10 @@ internal class AssociationConnectionAdornerTests : InteractiveTestClass() {

@Test
fun `Adorner can be garbage collected after dispose`() {
val scale = SimpleDoubleProperty(1.0)
val factory = { AssociationAdorner(100.0, 50.0, DoublePoint(10.0, 10.0), scale) }
val scale = 1.0
val factory = { AssociationAdorner(100.0, 50.0, { DoublePoint(10.0, 10.0) }, { scale }) }
testMemoryLeak(factory) { adorner ->
adorner.dispose()
adorner.destroy()
}
}
}

0 comments on commit d7b30e2

Please sign in to comment.