Skip to content

Commit fd72173

Browse files
committed
GROOVY-11876: add test case
1 parent d9f84c0 commit fd72173

2 files changed

Lines changed: 71 additions & 25 deletions

File tree

subprojects/groovy-swing/src/test/groovy/groovy/swing/beans/BindableSwingTest.groovy

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,68 @@
1818
*/
1919
package groovy.swing.beans
2020

21+
import org.junit.jupiter.api.BeforeEach
2122
import org.junit.jupiter.api.Test
2223

23-
import static groovy.swing.GroovySwingTestCase.testInEDT
24+
import static groovy.test.GroovyAssert.assertScript
25+
import static groovy.util.HeadlessTestSupport.isHeadless
26+
import static org.junit.jupiter.api.Assumptions.assumeFalse
2427

2528
final class BindableSwingTest {
2629

30+
@BeforeEach
31+
void setUp() {
32+
assumeFalse(isHeadless())
33+
}
34+
2735
// GROOVY-8339, GROOVY-10070
2836
@Test
2937
void testExtendsComponent() {
30-
testInEDT {
31-
new GroovyShell().evaluate '''
32-
class BindableTestBean extends javax.swing.JPanel {
33-
@groovy.beans.Bindable String testValue
38+
assertScript '''
39+
class BindableTestBean extends javax.swing.JPanel {
40+
@groovy.beans.Bindable String testValue
41+
}
42+
43+
changed = false
44+
45+
def bean = new BindableTestBean(testValue: 'foo')
46+
bean.propertyChange = {changed = true}
47+
bean.testValue = 'bar'
48+
assert changed
49+
'''
50+
}
51+
52+
// GROOVY-11876
53+
@Test
54+
void testBindableProperties() {
55+
assertScript '''
56+
import groovy.beans.Bindable
57+
import groovy.swing.SwingBuilder
58+
59+
class Main {
60+
@Bindable
61+
static class Bean {
62+
String foo = 'bar'
3463
}
3564
36-
changed = false
65+
static def bean1 = new Bean()
66+
static Bean bean2 = new Bean()
67+
68+
static main(args) {
69+
new SwingBuilder().edt {
70+
def label1 = label(text: bind { bean1.foo })
71+
def label2 = label(text: bind { bean2.foo })
3772
38-
def bean = new BindableTestBean(testValue: 'foo')
39-
bean.propertyChange = {changed = true}
40-
bean.testValue = 'bar'
41-
assert changed
42-
'''
43-
}
73+
assert label1.text == 'bar'
74+
bean1.foo = 'baz'
75+
assert label1.text == 'baz'
76+
77+
assert label2.text == 'bar'
78+
bean2.foo = 'baz'
79+
assert label2.text == 'baz'
80+
}
81+
}
82+
}
83+
'''
4484
}
4585
}

subprojects/groovy-swing/src/test/groovy/groovy/swing/beans/VetoableSwingTest.groovy

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,34 @@
1818
*/
1919
package groovy.swing.beans
2020

21+
import org.junit.jupiter.api.BeforeEach
2122
import org.junit.jupiter.api.Test
2223

23-
import static groovy.swing.GroovySwingTestCase.testInEDT
24+
import static groovy.test.GroovyAssert.assertScript
25+
import static groovy.util.HeadlessTestSupport.isHeadless
26+
import static org.junit.jupiter.api.Assumptions.assumeFalse
2427

2528
final class VetoableSwingTest {
2629

30+
@BeforeEach
31+
void setUp() {
32+
assumeFalse(isHeadless())
33+
}
34+
2735
// GROOVY-8339, GROOVY-10070
2836
@Test
2937
void testExtendsComponent() {
30-
testInEDT {
31-
new GroovyShell().evaluate '''
32-
class VetoableTestBean extends javax.swing.JPanel {
33-
@groovy.beans.Vetoable String testValue
34-
}
38+
assertScript '''
39+
class VetoableTestBean extends javax.swing.JPanel {
40+
@groovy.beans.Vetoable String testValue
41+
}
3542
36-
changed = false
43+
changed = false
3744
38-
def bean = new VetoableTestBean(testValue: 'foo')
39-
bean.vetoableChange = {changed = true}
40-
bean.testValue = 'bar'
41-
assert changed
42-
'''
43-
}
45+
def bean = new VetoableTestBean(testValue: 'foo')
46+
bean.vetoableChange = {changed = true}
47+
bean.testValue = 'bar'
48+
assert changed
49+
'''
4450
}
4551
}

0 commit comments

Comments
 (0)