1818 */
1919package bugs
2020
21- import org.junit.Test
21+ import org.junit.jupiter.api. Test
2222
2323import static groovy.test.GroovyAssert.assertScript
2424import static groovy.test.GroovyAssert.shouldFail
@@ -79,87 +79,86 @@ final class Groovy8678 {
7979 @Test
8080 void testMissingPropertyOrMethod () {
8181 def x = new WithMethods ()
82- def throwable = shouldFail () -> x . ' 42 '
83- assert throwable. class == MissingPropertyException . class
82+
83+ def throwable = shouldFail ( MissingPropertyException ) { x . ' 42 ' }
8484 assert throwable. message. startsWith(' No such property: 42 for class: bugs.Groovy8678$WithMethods' )
85- throwable = shouldFail () -> x . ' 42d '
86- assert throwable. class == MissingPropertyException . class
85+
86+ throwable = shouldFail ( MissingPropertyException ) { x . ' 42d ' }
8787 assert throwable. message. startsWith(' No such property: 42d for class: bugs.Groovy8678$WithMethods' )
88- throwable = shouldFail () -> x . ' 84 ' ()
89- assert throwable. class == MissingMethodException . class
90- assert throwable. message. startsWith(' No signature of method: bugs.Groovy8678$WithMethods.84() is applicable for argument types: () values: []' )
91- throwable = shouldFail () -> x . ' 84f ' ()
92- assert throwable. class == MissingMethodException . class
93- assert throwable. message. startsWith(' No signature of method: bugs.Groovy8678$WithMethods.84f() is applicable for argument types: () values: []' )
88+
89+ throwable = shouldFail ( MissingMethodException ) { x . ' 84 ' () }
90+ assert throwable. message. startsWith(' No signature of method: 84 for class: bugs.Groovy8678$WithMethods is applicable for argument types: () values: []' )
91+
92+ throwable = shouldFail ( MissingMethodException ) { x . ' 84f ' () }
93+ assert throwable. message. startsWith(' No signature of method: 84f for class: bugs.Groovy8678$WithMethods is applicable for argument types: () values: []' )
9494 }
9595
9696 @Test
97- @SuppressWarnings (" all" )
9897 void testCompilationFailure () {
9998 shouldNotCompile(' \' 42\' ' , ' \' FortyTwo\' ' , ' 42' ,
10099 // after GROOVY-8678
101- cls -> cls == MissingMethodException . class ,
102- msg -> msg. startsWith(' No signature of method: WithMethods. call() is applicable for argument types: (BigDecimal) values: [0.42]' ))
100+ MissingMethodException ,
101+ msg -> msg. startsWith(' No signature of method: call for class: WithMethods is applicable for argument types: (BigDecimal) values: [0.42]' ))
103102 // before GROOVY-8678
104- // cls -> cls == MultipleCompilationErrorsException.class ,
103+ // MultipleCompilationErrorsException,
105104 // msg -> msg.contains('Unexpected input: \'x.42\''))
106105 shouldNotCompile(' \' 42\' ' , ' \' FortyTwo\' ' , ' 42()' ,
107106 // after GROOVY-8678
108- cls -> cls == MissingMethodException . class ,
109- msg -> msg. startsWith(' No signature of method: java.math.BigDecimal.call() is applicable for argument types: () values: []' ))
107+ MissingMethodException ,
108+ msg -> msg. startsWith(' No signature of method: call for class: java.math.BigDecimal is applicable for argument types: () values: []' ))
110109 // before GROOVY-8678
111- // cls -> cls == MultipleCompilationErrorsException.class ,
110+ // MultipleCompilationErrorsException,
112111 // msg -> msg.contains('Unexpected input: \'x.42\''))
113112 shouldNotCompile(' \' 42d\' ' , ' \' FortyTwo\' ' , ' 42d' ,
114113 // after GROOVY-8678
115- cls -> cls == MissingMethodException . class ,
116- msg -> msg. startsWith(' No signature of method: WithMethods. call() is applicable for argument types: (Double) values: [0.42]' ))
114+ MissingMethodException ,
115+ msg -> msg. startsWith(' No signature of method: call for class: WithMethods is applicable for argument types: (Double) values: [0.42]' ))
117116 // before GROOVY-8678
118- // cls -> cls == MultipleCompilationErrorsException.class ,
117+ // MultipleCompilationErrorsException,
119118 // msg -> msg.contains('Unexpected input: \'x.42d\''))
120119 shouldNotCompile(' \' 42d\' ' , ' \' FortyTwo\' ' , ' 42d()' ,
121120 // after GROOVY-8678
122- cls -> cls == MissingMethodException . class ,
123- msg -> msg. startsWith(' No signature of method: java.lang.Double.call() is applicable for argument types: () values: []' ))
121+ MissingMethodException ,
122+ msg -> msg. startsWith(' No signature of method: call for class: java.lang.Double is applicable for argument types: () values: []' ))
124123 // before GROOVY-8678
125- // cls -> cls == MultipleCompilationErrorsException.class ,
124+ // MultipleCompilationErrorsException,
126125 // msg -> msg.contains('Unexpected input: \'x.42d\''))
127126 shouldNotCompile(' get84' , ' \' EightyFour\' ' , ' 84' ,
128127 // after GROOVY-8678
129- cls -> cls == MissingMethodException . class ,
130- msg -> msg. startsWith(' No signature of method: WithMethods. call() is applicable for argument types: (BigDecimal) values: [0.84]' ))
128+ MissingMethodException ,
129+ msg -> msg. startsWith(' No signature of method: call for class: WithMethods is applicable for argument types: (BigDecimal) values: [0.84]' ))
131130 // before GROOVY-8678
132- // cls -> cls == MultipleCompilationErrorsException.class ,
131+ // MultipleCompilationErrorsException,
133132 // msg -> msg.contains('Unexpected input: \'x.84\''))
134133 shouldNotCompile(' get84' , ' \' EightyFour\' ' , ' 84()' ,
135134 // after GROOVY-8678
136- cls -> cls == MissingMethodException . class ,
137- msg -> msg. startsWith(' No signature of method: java.math.BigDecimal.call() is applicable for argument types: () values: []' ))
135+ MissingMethodException ,
136+ msg -> msg. startsWith(' No signature of method: call for class: java.math.BigDecimal is applicable for argument types: () values: []' ))
138137 // before GROOVY-8678
139- // cls -> cls == MultipleCompilationErrorsException.class ,
138+ // MultipleCompilationErrorsException,
140139 // msg -> msg.contains('Unexpected input: \'x.84\''))
141140 shouldNotCompile(' get84f' , ' \' EightyFourEff\' ' , ' 84f' ,
142141 // after GROOVY-8678
143- cls -> cls == MissingMethodException . class ,
144- msg -> msg. startsWith(' No signature of method: WithMethods. call() is applicable for argument types: (Float) values: [0.84]' ))
142+ MissingMethodException ,
143+ msg -> msg. startsWith(' No signature of method: call for class: WithMethods is applicable for argument types: (Float) values: [0.84]' ))
145144 // before GROOVY-8678
146- // cls -> cls == MultipleCompilationErrorsException.class ,
145+ // MultipleCompilationErrorsException,
147146 // msg -> msg.contains('Unexpected input: \'x.84f\''))
148147 shouldNotCompile(' get84f' , ' \' EightyFourEff\' ' , ' 84f()' ,
149148 // after GROOVY-8678
150- cls -> cls == MissingMethodException . class ,
151- msg -> msg. startsWith(' No signature of method: java.lang.Float.call() is applicable for argument types: () values: []' ))
149+ MissingMethodException ,
150+ msg -> msg. startsWith(' No signature of method: call for class: java.lang.Float is applicable for argument types: () values: []' ))
152151 // before GROOVY-8678
153- // cls -> cls == MultipleCompilationErrorsException.class ,
152+ // MultipleCompilationErrorsException,
154153 // msg -> msg.contains('Unexpected input: \'x.84f\''))
155154 }
156155
157156 private static void shouldNotCompile (String methodName ,
158157 String returnValue ,
159158 String expression ,
160- Closure< Class<? extends Exception > > exceptionAssertion ,
159+ Class<? extends Exception > exceptionType ,
161160 Closure<String > messageAssertion ) {
162- def throwable = shouldFail """
161+ def throwable = shouldFail exceptionType, """
163162 class WithMethods {
164163 def ${ methodName} () {
165164 ${ returnValue}
@@ -168,7 +167,6 @@ final class Groovy8678 {
168167 def x = new WithMethods()
169168 x.${ expression}
170169 """ . stripIndent()
171- assert exceptionAssertion(throwable. class)
172170 assert messageAssertion(throwable. message)
173171 }
174172
0 commit comments