use of org.gradle.api.plugins.Convention in project gradle by gradle.
the class ExtensibleDynamicObjectTest method canInvokeMethodsOnJavaSubClassOfGroovyObjectFromGroovy.
@Test
public void canInvokeMethodsOnJavaSubClassOfGroovyObjectFromGroovy() {
// This doesn't work.
// It used to because at the bottom of the hierarchy chain the object implemented methodMissing().
// However, our normal “decorated” classes do not do this so it is not realistic.
// Groovy does something very strange here.
// For some reason (probably because the class is Java), it won't employ any dynamism.
// Even implementing invokeMethod at the Java level has no effect.
DynamicJavaBean javaBean = new DynamicJavaBean();
Convention convention = javaBean.extensibleDynamicObject.getConvention();
convention.getPlugins().put("bean", new ConventionBean());
new ExtensibleDynamicObjectTestHelper().assertCanCallMethods(javaBean);
}
use of org.gradle.api.plugins.Convention in project gradle by gradle.
the class ExtensibleDynamicObjectTest method canInvokeMethodsOnJavaObjectFromGroovy.
@Test
public void canInvokeMethodsOnJavaObjectFromGroovy() {
Bean bean = new Bean();
Convention convention = bean.extensibleDynamicObject.getConvention();
convention.getPlugins().put("bean", new ConventionBean());
new ExtensibleDynamicObjectTestHelper().assertCanCallMethods(bean);
}
use of org.gradle.api.plugins.Convention in project gradle by gradle.
the class ExtensibleDynamicObjectTest method conventionMethodsAreInherited.
@Test
public void conventionMethodsAreInherited() {
Bean bean = new Bean();
Convention convention = bean.extensibleDynamicObject.getConvention();
convention.getPlugins().put("convention", new ConventionBean());
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.api.plugins.Convention in project gradle by gradle.
the class ExtensibleDynamicObjectTest method canGetAndSetPropertyDefinedByConventionObject.
@Test
public void canGetAndSetPropertyDefinedByConventionObject() {
Bean bean = new Bean();
Convention convention = bean.extensibleDynamicObject.getConvention();
ConventionBean conventionBean = new ConventionBean();
convention.getPlugins().put("test", conventionBean);
conventionBean.setConventionProperty("value");
assertThat(bean.getProperty("conventionProperty"), equalTo((Object) "value"));
bean.setProperty("conventionProperty", "new value");
assertThat(bean.getProperty("conventionProperty"), equalTo((Object) "new value"));
assertThat(conventionBean.getConventionProperty(), equalTo((Object) "new value"));
}
use of org.gradle.api.plugins.Convention in project gradle by gradle.
the class ExtensibleDynamicObjectTest method canGetAllProperties.
@Test
public void canGetAllProperties() {
Bean parent = new Bean();
parent.defineProperty("parentProperty", "parentProperty");
parent.setReadWriteProperty("ignore me");
parent.doSetReadOnlyProperty("ignore me");
Convention parentConvention = parent.extensibleDynamicObject.getConvention();
parentConvention.getPlugins().put("parent", new ConventionBean());
GroovyBean bean = new GroovyBean();
bean.defineProperty("additional", "additional");
bean.setReadWriteProperty("readWriteProperty");
bean.doSetReadOnlyProperty("readOnlyProperty");
bean.setGroovyProperty("groovyProperty");
Convention convention = bean.extensibleDynamicObject.getConvention();
ConventionBean conventionBean = new ConventionBean();
conventionBean.setConventionProperty("conventionProperty");
convention.getPlugins().put("bean", conventionBean);
bean.setParent(parent.getAsDynamicObject());
Map<String, Object> properties = bean.getProperties();
assertThat(properties.get("properties"), sameInstance((Object) properties));
assertThat(properties.get("readWriteProperty"), equalTo((Object) "readWriteProperty"));
assertThat(properties.get("readOnlyProperty"), equalTo((Object) "readOnlyProperty"));
assertThat(properties.get("parentProperty"), equalTo((Object) "parentProperty"));
assertThat(properties.get("additional"), equalTo((Object) "additional"));
assertThat(properties.get("groovyProperty"), equalTo((Object) "groovyProperty"));
assertThat(properties.get("groovyDynamicProperty"), equalTo(null));
assertThat(properties.get("conventionProperty"), equalTo((Object) "conventionProperty"));
}
Aggregations