Search in sources :

Example 1 with Tt1cgo

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());
}
Also used : Closure(groovy.lang.Closure) Tt1cgo(gls.ch06.s05.testClasses.Tt1cgo)

Example 2 with Tt1cgo

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());
}
Also used : Closure(groovy.lang.Closure) Tt1cgo(gls.ch06.s05.testClasses.Tt1cgo)

Example 3 with Tt1cgo

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());
}
Also used : Closure(groovy.lang.Closure) Tt1cgo(gls.ch06.s05.testClasses.Tt1cgo)

Example 4 with Tt1cgo

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());
}
Also used : Closure(groovy.lang.Closure) Tt1cgo(gls.ch06.s05.testClasses.Tt1cgo)

Aggregations

Tt1cgo (gls.ch06.s05.testClasses.Tt1cgo)4 Closure (groovy.lang.Closure)4