assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX3);
}
public void testObjectSupportNameHandlingWitnClosureValues() {
final Tt1cgo obj = new Tt1cgo(); // Test subclass of GroovyObjectSupport
final Closure newX = new Closure(null) {
public Object doCall(final Object params) {
return "new x";
}
};
final Closure newX1 = new Closure(null) {
public Object doCall(final Object params) {
return "new x1";
}
};
final Closure newX2 = new Closure(null) {
public Object doCall(final Object params) {
return "new x2";
}
};
final Closure newX3 = new Closure(null) {
public Object doCall(final Object params) {
return "new x3";
}
};
assertTrue(((Closure) obj.getProperty("x")).call() == obj.getX().call());
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());
obj.setProperty("x", newX);
obj.getMetaClass().setAttribute(obj, "x", newX1);
assertTrue(((Closure) obj.getProperty("x")).call() == newX.call());
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());
obj.setX(newX2);
obj.x = newX3;
assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
}