use of gls.ch06.s05.testClasses.Tt1cgo in project groovy-core by groovy.
the class JName1Test method testObjectSupportNameHandlingWitnClosureValuesi.
public void testObjectSupportNameHandlingWitnClosureValuesi() {
final Tt1cgo obj = new Tt1cgo() {
};
// repeat test with subclass
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());
}
use of gls.ch06.s05.testClasses.Tt1cgo in project groovy-core by groovy.
the class JName1Test method testObjectSupportNameHandlingWitnClosureValues.
public void testObjectSupportNameHandlingWitnClosureValues() {
// Test subclass of GroovyObjectSupport
final Tt1cgo obj = new Tt1cgo();
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());
}
use of gls.ch06.s05.testClasses.Tt1cgo in project groovy by apache.
the class JName1Test method testObjectSupportNameHandlingWitnClosureValuesi.
public void testObjectSupportNameHandlingWitnClosureValuesi() {
final Tt1cgo obj = new Tt1cgo() {
};
// repeat test with subclass
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());
}
use of gls.ch06.s05.testClasses.Tt1cgo in project groovy by apache.
the class JName1Test method testObjectSupportNameHandlingWitnClosureValues.
public void testObjectSupportNameHandlingWitnClosureValues() {
// Test subclass of GroovyObjectSupport
final Tt1cgo obj = new Tt1cgo();
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());
}