Skip to content

Instantly share code, notes, and snippets.

@nobeans
Created October 26, 2011 02:37
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 nobeans/1315245 to your computer and use it in GitHub Desktop.
Save nobeans/1315245 to your computer and use it in GitHub Desktop.
class Groovy5101Test extends GroovyTestCase {
static class ClassA {
Runnable r
ClassA(Runnable r) { this.r = r }
String getSomething() { "hello" }
}
static class Factory {
ClassA getClassA1(Runnable r) {
new ClassA(r)
}
ClassA getClassA2(Runnable r) {
new ClassA(r) {
String getSomething() { "a fixed message" }
}
}
ClassA getClassA3(Runnable r) {
new ClassA(r) {
String getSomething() { r.toString() }
}
}
}
Runnable r
Factory factory
void setUp() {
this.r = new Runnable() {
void run() { "A!" }
}
this.factory = new Factory()
}
void test_NotInnerAnonymousClass() {
assert factory.getClassA1(r).getSomething() == "hello"
}
void test_InnerAnonymousClass_NotUsingArgument() {
assert factory.getClassA2(r).getSomething() == "a fixed message"
}
void test_InnerAnonymousClass_UsingArgument() {
// it should be OK but the result is NG
assert factory.getClassA3(r).getSomething() == r.toString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment