Created
October 26, 2011 02:37
-
-
Save nobeans/1315245 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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