@@ -20,110 +20,106 @@ package groovy
2020
2121import org.junit.jupiter.api.Test
2222
23- import static org.junit.jupiter.api.Assertions.fail
23+ import static groovy.test.GroovyAssert.assertScript
24+ import static groovy.test.GroovyAssert.shouldFail
2425
25-
26- class ClosureMissingMethodTest {
26+ final class ClosureMissingMethodTest {
2727
2828 @Test
2929 void testInScript () {
30- GroovyShell shell = new GroovyShell ()
31- shell. evaluate("""
32- int count = 0
33-
34- foo = {
35- count++
36- bar()
37- }
38- baz = {
39- foo()
40- }
41-
42- try {
43- baz()
44- fail()
45- } catch (org.codehaus.groovy.runtime.InvokerInvocationException iie) {
46- assert iie.cause.method == 'bar'
47- assert count == 1
48- } catch (MissingMethodException mme) {
49- assert mme.method == 'bar'
50- assert count == 1
51- }
52- """ );
30+ assertScript '''
31+ int count = 0
32+
33+ def foo = {
34+ ++count
35+ bar()
36+ }
37+ def baz = {
38+ foo()
39+ }
40+
41+ try {
42+ baz()
43+ assert false
44+ } catch (org.codehaus.groovy.runtime.InvokerInvocationException iie) {
45+ assert iie.cause.method == 'bar'
46+ assert count == 1
47+ } catch (MissingMethodException mme) {
48+ assert mme.method == 'bar'
49+ assert count == 1
50+ }
51+ '''
5352 }
5453
5554 @Test
5655 void testInMethod () {
5756 int count = 0
5857
5958 def foo = {
60- count ++
59+ ++ count
6160 bar()
6261 }
6362 def baz = {
6463 foo()
6564 }
6665
67- try {
66+ def mme = shouldFail ( MissingMethodException ) {
6867 baz()
69- fail ()
70- } catch (MissingMethodException mme) {
71- assert mme. method == ' bar'
72- assert count == 1
7368 }
69+ assert mme. method == ' bar'
70+ assert count == 1
7471 }
7572
7673 @Test
7774 void testWithMetaClassInScript () {
78- GroovyShell shell = new GroovyShell ()
79- shell . evaluate( """
80- int count = 0
81-
82- foo = {
83- count++
84- bar()
85- }
86- baz = {
87- foo()
88- }
89- mc = new ExpandoMetaClass(baz.getClass())
90- mc .initialize()
91- baz.metaClass = mc
92-
93- try {
94- baz()
95- fail()
96- } catch (org.codehaus.groovy.runtime.InvokerInvocationException iie) {
97- assert iie.cause.method == 'bar'
98- assert count == 1
99- } catch (MissingMethodException mme) {
100- assert mme.method == 'bar'
101- assert count == 1
102- }
103- """ );
75+ assertScript '''
76+ int count = 0
77+
78+ def foo = {
79+ ++count
80+ bar()
81+ }
82+ def baz = {
83+ foo()
84+ }
85+
86+ def emc = new ExpandoMetaClass(baz.getClass())
87+ emc .initialize()
88+ baz.metaClass = emc
89+
90+ try {
91+ baz()
92+ assert false
93+ } catch (org.codehaus.groovy.runtime.InvokerInvocationException iie) {
94+ assert iie.cause.method == 'bar'
95+ assert count == 1
96+ } catch (MissingMethodException mme) {
97+ assert mme.method == 'bar'
98+ assert count == 1
99+ }
100+ '''
104101 }
105102
106103 @Test
107104 void testWithMetaClassInMethod () {
108105 int count = 0
109106
110107 def foo = {
111- count ++
108+ ++ count
112109 bar()
113110 }
114111 def baz = {
115112 foo()
116113 }
117- MetaClass mc = new ExpandoMetaClass (baz. getClass())
118- mc. initialize()
119- baz. metaClass = mc
120114
121- try {
115+ def emc = new ExpandoMetaClass (baz. getClass())
116+ emc. initialize()
117+ baz. metaClass = emc
118+
119+ def mme = shouldFail (MissingMethodException ) {
122120 baz()
123- fail ()
124- } catch (MissingMethodException mme) {
125- assert mme. method == ' bar'
126- assert count == 1
127121 }
122+ assert mme. method == ' bar'
123+ assert count == 1
128124 }
129125}
0 commit comments