Search in sources :

Example 1 with DefaultProviderFactory

use of org.gradle.api.internal.provider.DefaultProviderFactory in project gradle by gradle.

the class AsmBackedClassGeneratorTest method doesNotAddSetterMethodsForPropertyWhoseTypeIsPropertyWhenTheSetterMethodsAlreadyExist.

@Test
public void doesNotAddSetterMethodsForPropertyWhoseTypeIsPropertyWhenTheSetterMethodsAlreadyExist() throws Exception {
    DefaultProviderFactory providerFactory = new DefaultProviderFactory();
    BeanWithProperty bean = generator.newInstance(BeanWithProperty.class, TestUtil.objectFactory());
    DynamicObject dynamicObject = ((DynamicObjectAware) bean).getAsDynamicObject();
    dynamicObject.setProperty("prop2", "value");
    assertEquals("[value]", bean.getProp2().get());
    dynamicObject.setProperty("prop2", 12);
    assertEquals("[12]", bean.getProp2().get());
    dynamicObject.setProperty("prop2", providerFactory.provider(new Callable<String>() {

        int count;

        @Override
        public String call() throws Exception {
            return "[" + String.valueOf(++count) + "]";
        }
    }));
    assertEquals("[1]", bean.getProp2().get());
    assertEquals("[2]", bean.getProp2().get());
}
Also used : BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) DefaultProviderFactory(org.gradle.api.internal.provider.DefaultProviderFactory) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 2 with DefaultProviderFactory

use of org.gradle.api.internal.provider.DefaultProviderFactory in project gradle by gradle.

the class AsmBackedClassGeneratorTest method addsSetterMethodsForPropertyWhoseTypeIsProperty.

@Test
public void addsSetterMethodsForPropertyWhoseTypeIsProperty() throws Exception {
    DefaultProviderFactory providerFactory = new DefaultProviderFactory();
    BeanWithProperty bean = generator.newInstance(BeanWithProperty.class, TestUtil.objectFactory());
    DynamicObject dynamicObject = ((DynamicObjectAware) bean).getAsDynamicObject();
    dynamicObject.setProperty("prop", "value");
    assertEquals("value", bean.getProp().get());
    dynamicObject.setProperty("prop", providerFactory.provider(new Callable<String>() {

        int count;

        @Override
        public String call() throws Exception {
            return "[" + String.valueOf(++count) + "]";
        }
    }));
    assertEquals("[1]", bean.getProp().get());
    assertEquals("[2]", bean.getProp().get());
}
Also used : BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) DefaultProviderFactory(org.gradle.api.internal.provider.DefaultProviderFactory) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Aggregations

Callable (java.util.concurrent.Callable)2 DefaultProviderFactory (org.gradle.api.internal.provider.DefaultProviderFactory)2 BeanDynamicObject (org.gradle.internal.metaobject.BeanDynamicObject)2 DynamicObject (org.gradle.internal.metaobject.DynamicObject)2 Test (org.junit.Test)2