Search in sources :

Example 1 with TestClosure

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

the class DefaultTaskGraphExecuterTest method assertExecutesWhenReadyListenerBeforeExecute.

void assertExecutesWhenReadyListenerBeforeExecute(Action<TestClosure> whenReadySubscriber) {
    final TestClosure runnable = context.mock(TestClosure.class);
    Task a = task("a");
    whenReadySubscriber.execute(runnable);
    taskExecuter.addTasks(toList(a));
    context.checking(new Expectations() {

        {
            one(runnable).call(taskExecuter);
        }
    });
    taskExecuter.execute();
}
Also used : TestClosure(org.gradle.util.TestClosure) Expectations(org.jmock.Expectations) Task(org.gradle.api.Task)

Example 2 with TestClosure

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

the class DefaultNamedDomainObjectSetTest method allCallsClosureForEachExistingObject.

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

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

Example 3 with TestClosure

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

the class DefaultNamedDomainObjectSetTest method canGetFilteredCollectionContainingAllObjectsWhichMeetSpec.

@Test
public void canGetFilteredCollectionContainingAllObjectsWhichMeetSpec() {
    final Bean bean1 = new Bean("a");
    Bean bean2 = new Bean("b");
    Bean bean3 = new Bean("c");
    Spec<Bean> spec = new Spec<Bean>() {

        public boolean isSatisfiedBy(Bean element) {
            return element != bean1;
        }
    };
    TestClosure testClosure = new TestClosure() {

        public Object call(Object param) {
            return param != bean1;
        }
    };
    container.add(bean1);
    container.add(bean2);
    container.add(bean3);
    assertThat(toList(container.matching(spec)), equalTo(toList(bean2, bean3)));
    assertThat(toList(container.matching(TestUtil.toClosure(testClosure))), equalTo(toList(bean2, bean3)));
    assertThat(container.matching(spec).findByName("a"), nullValue());
    assertThat(container.matching(spec).findByName("b"), sameInstance(bean2));
}
Also used : TestClosure(org.gradle.util.TestClosure) Spec(org.gradle.api.specs.Spec) Test(org.junit.Test)

Example 4 with TestClosure

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

the class DefaultDomainObjectCollectionTest method callsClosureWithNewObjectAsParameterWhenObjectAdded.

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

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

Example 5 with TestClosure

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

the class DefaultDomainObjectCollectionTest method callsClosureWithRemovedObjectAsParameterWhenObjectRemoved.

@Test
public void callsClosureWithRemovedObjectAsParameterWhenObjectRemoved() {
    final TestClosure closure = context.mock(TestClosure.class);
    container.add("a");
    context.checking(new Expectations() {

        {
            oneOf(closure).call("a");
        }
    });
    container.whenObjectRemoved(TestUtil.toClosure(closure));
    container.remove("a");
}
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