Skip to content

Instantly share code, notes, and snippets.

@erdi
Created June 17, 2011 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erdi/1031051 to your computer and use it in GitHub Desktop.
Save erdi/1031051 to your computer and use it in GitHub Desktop.
MetaClassMixin
import grails.test.GrailsUnitTestCase
@Category(GrailsUnitTestCase)
class MetaClassMixin {
Delegate metaClassFor(Class clazz) {
registerMetaClass(clazz)
new Delegate(target: clazz.metaClass)
}
Delegate staticMetaClassFor(Class clazz) {
registerMetaClass(clazz)
new Delegate(target: clazz.metaClass.'static')
}
private static class Delegate {
Object target
@Override
void setProperty(String property, Object newValue) {
target.setProperty(property, newValue)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment