Grails

Spock @ConfineMetaClassChanges annotation made writing grails unit test easier

Grails version 2.0 and above made unit testing much simpler with so many new annotations introduced. However if you wanted to mock a specific method of a class whose method is being tested or you wanted to create a stub of the class already annotated by @Mock, things would become difficult. So I always ended up […]

Amit Jain
Amit Jain
Read

Grails

MetaProgramming with MetaClass

As we all know that groovy is a dynamic programming language, so we can add any method to any class at runtime. First, let’s see a small and simple example of metaProgamming given below, in which we are adding a method (isEvent) into an Integer class. [groovy] Integer.metaClass.isEven = { -> // only (->) sign […]

Amit Kumar
Amit Kumar
Read

Technology

Playing with call() using Groovy Metaprogramming

In Groovy you can use “()” with any object which in turn is same as calling call() method on that object. You can write code which are more human readable using this groovy feature. This is somewhat overriding “()” operator. The blog adds Microsoft VB array access like syntax to Java List.

Bhagwat Kumar
Bhagwat Kumar
Read
Services