Search in sources :

Example 11 with TestClosure

use of org.gradle.util.TestClosure in project gradle by gradle.

the class DefaultDomainObjectCollectionTest method allCallsClosureForEachNewObject.

@Test
public void allCallsClosureForEachNewObject() {
    final TestClosure closure = context.mock(TestClosure.class);
    context.checking(new Expectations() {

        {
            oneOf(closure).call("a");
        }
    });
    container.all(TestUtil.toClosure(closure));
    container.add("a");
}
Also used : TestClosure(org.gradle.util.TestClosure) Expectations(org.jmock.Expectations) Test(org.junit.Test)

Example 12 with TestClosure

use of org.gradle.util.TestClosure in project gradle by gradle.

the class DefaultNamedDomainObjectSetTest method canExecuteClosureForAllElementsInATypeFilteredCollection.

@Test
public void canExecuteClosureForAllElementsInATypeFilteredCollection() {
    class OtherBean extends Bean {

        public OtherBean(String name) {
            super(name);
        }

        public OtherBean() {
        }
    }
    final TestClosure closure = context.mock(TestClosure.class);
    Bean bean1 = new Bean("b1");
    final OtherBean bean2 = new OtherBean("b2");
    container.add(bean1);
    container.add(bean2);
    context.checking(new Expectations() {

        {
            one(closure).call(bean2);
        }
    });
    container.withType(OtherBean.class, TestUtil.toClosure(closure));
}
Also used : TestClosure(org.gradle.util.TestClosure) Expectations(org.jmock.Expectations) Test(org.junit.Test)

Example 13 with TestClosure

use of org.gradle.util.TestClosure in project gradle by gradle.

the class DefaultNamedDomainObjectSetTest method callsClosureWhenObjectAdded.

@Test
public void callsClosureWhenObjectAdded() {
    final TestClosure closure = context.mock(TestClosure.class);
    final Bean bean = new Bean();
    context.checking(new Expectations() {

        {
            one(closure).call(bean);
        }
    });
    container.whenObjectAdded(TestUtil.toClosure(closure));
    container.add(bean);
}
Also used : TestClosure(org.gradle.util.TestClosure) Expectations(org.jmock.Expectations) Test(org.junit.Test)

Example 14 with TestClosure

use of org.gradle.util.TestClosure in project gradle by gradle.

the class DefaultNamedDomainObjectSetTest method filteredCollectionExecutesClosureWhenMatchingObjectAdded.

@Test
public void filteredCollectionExecutesClosureWhenMatchingObjectAdded() {
    final TestClosure closure = context.mock(TestClosure.class);
    final Bean bean = new Bean();
    context.checking(new Expectations() {

        {
            one(closure).call(bean);
        }
    });
    Spec<Bean> spec = new Spec<Bean>() {

        public boolean isSatisfiedBy(Bean element) {
            return element == bean;
        }
    };
    container.matching(spec).whenObjectAdded(TestUtil.toClosure(closure));
    container.add(bean);
    container.add(new Bean());
}
Also used : TestClosure(org.gradle.util.TestClosure) Expectations(org.jmock.Expectations) Spec(org.gradle.api.specs.Spec) Test(org.junit.Test)

Example 15 with TestClosure

use of org.gradle.util.TestClosure in project gradle by gradle.

the class DefaultNamedDomainObjectSetTest method allCallsClosureForEachNewObject.

@Test
public void allCallsClosureForEachNewObject() {
    final TestClosure closure = context.mock(TestClosure.class);
    final Bean bean = new Bean();
    context.checking(new Expectations() {

        {
            one(closure).call(bean);
        }
    });
    container.all(TestUtil.toClosure(closure));
    container.add(bean);
}
Also used : TestClosure(org.gradle.util.TestClosure) Expectations(org.jmock.Expectations) Test(org.junit.Test)

Aggregations

TestClosure (org.gradle.util.TestClosure)16 Expectations (org.jmock.Expectations)14 Test (org.junit.Test)13 Spec (org.gradle.api.specs.Spec)4 Task (org.gradle.api.Task)3