GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / groovy / org / codehaus / groovy / grails / commons / metaclass / ClosureInvokingDynamicMethodTests.groovy
blob87529962da0b54d21f89355365bc9b55734894c1
1 package org.codehaus.groovy.grails.commons.metaclass;
3 import java.util.regex.*
5 /* Copyright 2004-2005 Graeme Rocher
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 class ClosureInvokingDynamicMethodTests extends GroovyTestCase {
22 void testClosureInvokingDynamicMethod() {
23 def method1 = new ClosureInvokingDynamicMethod(/^find\w+$/, {
24 assertTrue it instanceof Matcher
25 return "foo"
28 def method2 = new ClosureInvokingDynamicMethod(/^find\w+$/, { matcher, args ->
29 assertTrue matcher instanceof Matcher
30 return args[1]
33 def method3 = new ClosureInvokingDynamicMethod(/^find\w+$/, {-> "foo" })
35 assertTrue method1.isMethodMatch("findBar")
36 assertTrue method2.isMethodMatch("findBar")
37 assertTrue method3.isMethodMatch("findBar")
39 assertEquals "foo", method1.invoke(this, "findBar", null)
40 assertEquals 2, method2.invoke(this, "findBar",[1,2,3] as Object[])
41 assertEquals "foo", method3.invoke(this,"findBar", null)
44 void testClosureInvokingDynamicMethodFailures() {
45 shouldFail {
46 new ClosureInvokingDynamicMethod(null, { })
49 shouldFail {
50 new ClosureInvokingDynamicMethod(null, null)
53 shouldFail {
54 new ClosureInvokingDynamicMethod("foo", null)