Groovy: Use @Canonical to Get Compiler-generated Equals, HashCode and ToString

Groovy makes it extremely easy to create Java beans with getters, setters, equals, hashCode, and toString: You can then do: As you might have noticed, you may provide your own implementation of toString and reuse the auto-generated toString by calling _toString(). References JavaDoc for @Canonical. You can also use separately any of: @ToString. @EqualsAndHashCode, @TupleConstructor.Continue reading “Groovy: Use @Canonical to Get Compiler-generated Equals, HashCode and ToString”

Groovy: Creating an Interface Stub and Intercepting All Calls to It

It’s sometimes useful for unit testing to be able to create a simple no-op stub of an interface the class under test depends upon and to intercept all calls to the stub, for example to remember all the calls and parameters so that you can later verify that they’ve been invoked as expected. Often you’dContinue reading “Groovy: Creating an Interface Stub and Intercepting All Calls to It”