Search in sources :

Example 36 with DynamicObject

use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.

the class ExtensibleDynamicObjectTest method parentPropertiesAreInherited.

@Test
public void parentPropertiesAreInherited() {
    Bean parent = new Bean();
    parent.defineProperty("parentProperty", "value");
    Bean bean = new Bean();
    bean.setParent(parent.getAsDynamicObject());
    DynamicObject inherited = bean.getInheritable();
    assertTrue(inherited.hasProperty("parentProperty"));
    assertThat(inherited.getProperty("parentProperty"), equalTo((Object) "value"));
    assertThat(inherited.getProperties().get("parentProperty"), equalTo((Object) "value"));
}
Also used : BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) Test(org.junit.Test)

Example 37 with DynamicObject

use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.

the class ExtensibleDynamicObjectTest method extraPropertiesAreInherited.

@Test
public void extraPropertiesAreInherited() {
    Bean bean = new Bean();
    bean.defineProperty("additional", "value");
    DynamicObject inherited = bean.getInheritable();
    assertTrue(inherited.hasProperty("additional"));
    assertThat(inherited.getProperty("additional"), equalTo((Object) "value"));
    assertThat(inherited.getProperties().get("additional"), equalTo((Object) "value"));
}
Also used : BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) Test(org.junit.Test)

Example 38 with DynamicObject

use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.

the class ExtensibleDynamicObjectTest method cannotSetInheritedProperties.

@Test
public void cannotSetInheritedProperties() {
    Bean bean = new Bean();
    bean.defineProperty("additional", "value");
    DynamicObject inherited = bean.getInheritable();
    try {
        inherited.setProperty("additional", "new value");
        fail();
    } catch (MissingPropertyException e) {
        assertThat(e.getMessage(), equalTo("Could not find property 'additional' inherited from <bean>."));
    }
}
Also used : BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) MissingPropertyException(groovy.lang.MissingPropertyException) Test(org.junit.Test)

Example 39 with DynamicObject

use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.

the class ExtensibleDynamicObjectTest method otherMethodsAreNotInherited.

@Test
public void otherMethodsAreNotInherited() {
    Bean bean = new Bean();
    assertTrue(bean.hasMethod("javaMethod", "a", "b"));
    DynamicObject inherited = bean.getInheritable();
    assertFalse(inherited.hasMethod("javaMethod", "a", "b"));
}
Also used : BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) Test(org.junit.Test)

Example 40 with DynamicObject

use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.

the class ExtensibleDynamicObjectTest method additionalObjectPropertiesAreInherited.

@Test
public void additionalObjectPropertiesAreInherited() {
    Bean other = new Bean();
    other.defineProperty("other", "value");
    Bean bean = new Bean();
    bean.extensibleDynamicObject.addObject(other.getAsDynamicObject(), ExtensibleDynamicObject.Location.BeforeConvention);
    DynamicObject inherited = bean.getInheritable();
    assertTrue(inherited.hasProperty("other"));
    assertThat(inherited.getProperty("other"), equalTo((Object) "value"));
    assertThat(inherited.getProperties().get("other"), equalTo((Object) "value"));
}
Also used : BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) Test(org.junit.Test)

Aggregations

DynamicObject (org.gradle.internal.metaobject.DynamicObject)45 BeanDynamicObject (org.gradle.internal.metaobject.BeanDynamicObject)40 Test (org.junit.Test)37 Convention (org.gradle.api.plugins.Convention)10 Callable (java.util.concurrent.Callable)5 DynamicObjectAware (org.gradle.api.internal.DynamicObjectAware)5 DefaultProviderFactory (org.gradle.api.internal.provider.DefaultProviderFactory)5 ExtensibleDynamicObject (org.gradle.internal.extensibility.ExtensibleDynamicObject)4 Closure (groovy.lang.Closure)3 MissingPropertyException (groovy.lang.MissingPropertyException)3 MissingMethodException (groovy.lang.MissingMethodException)2 File (java.io.File)2 Map (java.util.Map)2 ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)2 DynamicInvokeResult (org.gradle.internal.metaobject.DynamicInvokeResult)2 Predicate (com.google.common.base.Predicate)1 DirectoryTree (org.gradle.api.file.DirectoryTree)1 ExtensibleDynamicObject (org.gradle.api.internal.ExtensibleDynamicObject)1 ScriptHandlerInternal (org.gradle.api.internal.initialization.ScriptHandlerInternal)1