use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method additionalObjectMethodsAreInherited.
@Test
public void additionalObjectMethodsAreInherited() {
Bean other = new Bean();
Convention convention = other.extensibleDynamicObject.getConvention();
convention.getPlugins().put("convention", new ConventionBean());
Bean bean = new Bean();
bean.extensibleDynamicObject.addObject(other.getAsDynamicObject(), ExtensibleDynamicObject.Location.BeforeConvention);
DynamicObject inherited = bean.getInheritable();
assertTrue(inherited.hasMethod("conventionMethod", "a", "b"));
assertThat(inherited.invokeMethod("conventionMethod", "a", "b"), equalTo((Object) "convention:a.b"));
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method canCallGroovyDynamicMethods.
@Test
public void canCallGroovyDynamicMethods() {
DynamicGroovyBean bean = new DynamicGroovyBean();
DynamicObject object = new ExtensibleDynamicObject(bean, DynamicGroovyBean.class, ThreadGlobalInstantiator.getOrCreate());
Integer doubled = (Integer) object.invokeMethod("bar", 1);
assertThat(doubled, equalTo(2));
try {
object.invokeMethod("xxx", 1, 2, 3);
fail();
} catch (MissingMethodException e) {
assertThat(e.getMessage(), equalTo("Could not find method xxx() for arguments [1, 2, 3] on object of type " + DynamicGroovyBean.class.getName() + "."));
}
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method parentMethodsAreInherited.
@Test
public void parentMethodsAreInherited() {
Bean parent = new Bean();
Convention convention = parent.extensibleDynamicObject.getConvention();
convention.getPlugins().put("convention", new ConventionBean());
Bean bean = new Bean();
bean.setParent(parent.getAsDynamicObject());
DynamicObject inherited = bean.getInheritable();
assertTrue(inherited.hasMethod("conventionMethod", "a", "b"));
assertThat(inherited.invokeMethod("conventionMethod", "a", "b"), equalTo((Object) "convention:a.b"));
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method inheritedConventionPropertiesTrackChanges.
@Test
public void inheritedConventionPropertiesTrackChanges() {
Bean bean = new Bean();
DynamicObject inherited = bean.getInheritable();
assertFalse(inherited.hasProperty("conventionProperty"));
Convention convention = bean.extensibleDynamicObject.getConvention();
ConventionBean conventionBean = new ConventionBean();
conventionBean.setConventionProperty("value");
convention.getPlugins().put("convention", conventionBean);
assertTrue(inherited.hasProperty("conventionProperty"));
assertThat(inherited.getProperty("conventionProperty"), equalTo((Object) "value"));
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method inheritedAdditionalObjectPropertiesTrackChanges.
@Test
public void inheritedAdditionalObjectPropertiesTrackChanges() {
Bean other = new Bean();
other.defineProperty("other", "value");
Bean bean = new Bean();
DynamicObject inherited = bean.getInheritable();
assertFalse(inherited.hasProperty("other"));
bean.extensibleDynamicObject.addObject(other.getAsDynamicObject(), ExtensibleDynamicObject.Location.BeforeConvention);
assertTrue(inherited.hasProperty("other"));
assertThat(inherited.getProperty("other"), equalTo((Object) "value"));
}
Aggregations