Please feel free to add more suggestions or otherwise comment.
Thursday, 22 January 2009
On selenium testing...
I updated my blog to list some useful tips for writing more resilient Selenium XPath tests.
Tuesday, 6 January 2009
Groovy Truth and the instanceof Operator
I just stumbled across a little gotcha which would have failed compilation in Java, but in Groovy compiles but doesn't do what the developer intended.
The problem is missing braces. What Groovy is actually evaluating is
if (!obj instanceof SomeEnum) throw new IllegalArgumentException()Clearly, the intention was to throw
// do something with obj.name()
IllegalArgumentException
if obj
is not the correct type, but instead the code was throwing MissingMethodException
from the access to obj.name()
.The problem is missing braces. What Groovy is actually evaluating is
if (false instanceof SomeEnum)
!obj
evaluates to false as obj
is not null. The correct code would be:if (!(obj instanceof SomeEnum)) throw new IllegalArgumentException()
Subscribe to:
Posts (Atom)