use of org.gradle.api.plugins.Convention in project gradle by gradle.
the class ExtensibleDynamicObjectTest method extraPropertyTakesPrecedenceOverConventionProperty.
@Test
public void extraPropertyTakesPrecedenceOverConventionProperty() {
Bean bean = new Bean();
bean.defineProperty("conventionProperty", "value");
Convention convention = bean.extensibleDynamicObject.getConvention();
ConventionBean conventionBean = new ConventionBean();
convention.getPlugins().put("test", conventionBean);
assertThat(bean.getProperty("conventionProperty"), equalTo((Object) "value"));
bean.setProperty("conventionProperty", "new value");
assertThat(bean.getProperty("conventionProperty"), equalTo((Object) "new value"));
assertThat(bean.extensibleDynamicObject.getDynamicProperties().get("conventionProperty"), equalTo((Object) "new value"));
assertThat(conventionBean.getConventionProperty(), nullValue());
}
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 conventionPropertiesAreInherited.
@Test
public void conventionPropertiesAreInherited() {
Bean bean = new Bean();
Convention convention = bean.extensibleDynamicObject.getConvention();
ConventionBean conventionBean = new ConventionBean();
conventionBean.setConventionProperty("value");
convention.getPlugins().put("convention", conventionBean);
DynamicObject inherited = bean.getInheritable();
assertTrue(inherited.hasProperty("conventionProperty"));
assertThat(inherited.getProperty("conventionProperty"), equalTo((Object) "value"));
assertThat(inherited.getProperties().get("conventionProperty"), equalTo((Object) "value"));
}
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 canInvokeMethodsOnJavaObjectFromGroovy.
@Test
public void canInvokeMethodsOnJavaObjectFromGroovy() {
Bean bean = new Bean();
Convention convention = bean.extensibleDynamicObject.getConvention();
convention.getPlugins().put("bean", new ConventionBean());
new ExtensibleDynamicObjectTestHelper().assertCanCallMethods(bean);
}
Aggregations