Created
May 23, 2012 06:04
-
-
Save RobertFischer/2773494 to your computer and use it in GitHub Desktop.
An assert to affirm a method exists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The signature that works out more naturally | |
void assertHasMethod(Object obj, String name, Class[] types) { | |
def methods = obj.metaClass.respondsTo(obj, name, types) | |
if(methods.isEmpty()) fail("Could not find method $name($types) on $obj") | |
} | |
// Enables [Foo,Bar,Baz] notation | |
void assertHasMethod(Object obj, String name, List<Class> types) { | |
assertHasMethod(obj, name, types.toArray(new Class[0])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will check for both static and dynamic types. However, the dynamic types will need to be injected/configured/whatever for your test cases to detect them.