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")));
}
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");
}
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();
}
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();
}
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));
}
Aggregations