Friday, February 27, 2009

Okay,  why I really want to learn Groovy is that I need to adapt Unit Testing to a large, ancient legacy java application.   With no existing tests, and more 'spaghetti' than will be eaten in Italy this year,  I'm trying to inject mocks and stubs without having to refactor every class.

I've run the sample found at http://docs.codehaus.org/display/GROOVY/Using+the+Delegating+Meta+Class  where the String class behavior is changed during a script run.   However, the change is not replicated when the string.toString() method is called inside of a Java class (triggered from the Groovy Script).

I figure I'm missing a crucial understanding of the Groovy vs Java Classloader...  Or is that all real coders always design objects with setDepenedency() methods that allow for easy code injection?

1 comment:

  1. The Groovy String (http://groovy.codehaus.org/groovy-jdk/java/lang/String.html) class is a subclass of java.lang.String. But its toString() method returns a java.lang.String, not a GString. This is one instance where Groovy's transparent dynamic type casting turns out to be a hindrance.

    ReplyDelete