Search in sources :

Example 6 with TestClosure

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

the class DefaultDomainObjectCollectionTest method canGetFilteredCollectionContainingAllObjectsWhichMeetSpec.

@Test
public void canGetFilteredCollectionContainingAllObjectsWhichMeetSpec() {
    Spec<CharSequence> spec = new Spec<CharSequence>() {

        public boolean isSatisfiedBy(CharSequence element) {
            return !element.equals("b");
        }
    };
    TestClosure testClosure = new TestClosure() {

        public Object call(Object param) {
            return !param.equals("b");
        }
    };
    container.add("a");
    container.add("b");
    container.add("c");
    assertThat(toList(container.matching(spec)), equalTo(toList((CharSequence) "a", "c")));
    assertThat(toList(container.matching(TestUtil.toClosure(testClosure))), equalTo(toList((CharSequence) "a", "c")));
}
Also used : TestClosure(org.gradle.util.TestClosure) Spec(org.gradle.api.specs.Spec) Test(org.junit.Test)

Example 7 with TestClosure

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

the class DefaultDomainObjectCollectionTest method filteredCollectionExecutesClosureWhenMatchingObjectAdded.

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

        {
            oneOf(closure).call("a");
        }
    });
    Spec<CharSequence> spec = new Spec<CharSequence>() {

        public boolean isSatisfiedBy(CharSequence element) {
            return !element.equals("b");
        }
    };
    container.matching(spec).whenObjectAdded(TestUtil.toClosure(closure));
    container.add("a");
    container.add("b");
}
Also used : TestClosure(org.gradle.util.TestClosure) Expectations(org.jmock.Expectations) Spec(org.gradle.api.specs.Spec) Test(org.junit.Test)

Example 8 with TestClosure

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

the class DefaultTaskGraphExecuterTest method assertNotifiesBeforeTaskListenerAsTasksAreExecuted.

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

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

Example 9 with TestClosure

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

the class DefaultTaskGraphExecuterTest method assertNotifiesAfterTaskListenerAsTasksAreExecuted.

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

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

Example 10 with TestClosure

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

the class DefaultDomainObjectCollectionTest method allCallsClosureForEachExistingObject.

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

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