Package groovy.lang

Examples of groovy.lang.Closure


        tree.visit(visitor);
    }

    @Test
    public void visitsEachTreeWithClosure() {
        final Closure visitor = HelperUtil.TEST_CLOSURE;

        context.checking(new Expectations() {{
            one(source1).visit(visitor);
            one(source2).visit(visitor);
        }});
View Full Code Here


    }

    @Test
    public void dependencyWithClosure() {
        final String dependencyNotation = "someNotation";
        final Closure configureClosure = HelperUtil.toClosure("{}");
        final ModuleDependency dependencyDummy = context.mock(ModuleDependency.class);
        letFactoryStubReturnDependency(dependencyNotation, dependencyDummy);
        moduleFactoryDelegate.dependency(dependencyNotation, configureClosure);
        assertThat(clientModule.getDependencies(), Matchers.equalTo(WrapUtil.toSet(dependencyDummy)));
    }
View Full Code Here

    }

    @Test
    public void module() {
        final String clientModuleNotation = "someNotation";
        final Closure configureClosure = HelperUtil.toClosure("{}");
        final ClientModule clientModuleDummy = context.mock(ClientModule.class);
        context.checking(new Expectations() {{
            allowing(dependencyFactoryStub).createModule(clientModuleNotation, configureClosure);
            will(returnValue(clientModuleDummy));
        }});
View Full Code Here

        assertThat(container.add("task", Task.class), sameInstance(task));
    }

    @Test
    public void addsTaskWithNameAndConfigureClosure() {
        final Closure action = HelperUtil.toClosure("{ description = 'description' }");
        final Map<String, ?> options = GUtil.map(Task.TASK_NAME, "task");
        final Task task = task("task");

        context.checking(new Expectations(){{
            one(taskFactory).createTask(project, options);
View Full Code Here

        final Map map = WrapUtil.toMap("key", "value");
        context.checking(new Expectations() {{
            allowing(projectDependencyFactoryStub).createProjectDependencyFromMap(projectFinderDummy, map);
            will(returnValue(projectDependency));
        }});
        Closure configureClosure = HelperUtil.toClosure("{ transitive = false }");
        assertThat(dependencyFactory.createProjectDependencyFromMap(projectFinderDummy, map), sameInstance(projectDependency));
    }
View Full Code Here

            one(clientModuleMock).addDependency(dependencyDummy1);
            one(clientModuleMock).addDependency(dependencyDummy2);
            one(clientModuleMock).addDependency(dependencyDummy3);
            one(clientModuleMock).addDependency(dependencyMock);
        }});
        Closure configureClosure = HelperUtil.toClosure(String.format(
                "{dependency('%s'); dependencies('%s', '%s'); dependency('%s') { transitive = true }}",
                someNotation1, someNotation2, someNotation3, someNotation4));
        assertThat(dependencyFactory.createModule(someModuleNotation, configureClosure), equalTo(clientModuleMock));
    }
View Full Code Here

    private static <T> T configure(Closure configureClosure, T delegate, int resolveStrategy) {
        if (configureClosure == null) {
            return delegate;
        }
        Closure copy = (Closure) configureClosure.clone();
        copy.setResolveStrategy(resolveStrategy);
        copy.setDelegate(delegate);
        if (copy.getMaximumNumberOfParameters() == 0) {
            copy.call();
        } else {
            copy.call(delegate);
        }
        return delegate;
    }
View Full Code Here

        assertThat(transformer.transform("original"), equalTo("b"));
    }

    @Test
    public void canUseAClosureAsATransformer() {
        Closure closure = HelperUtil.toClosure("{ it + ' transformed' }");

        transformer.add(closure);

        assertThat(transformer.transform("original"), equalTo("original transformed"));
    }
View Full Code Here

        assertThat(transformer.transform("original"), equalTo("original transformed"));
    }

    @Test
    public void usesOriginalObjectWhenClosureReturnsNull() {
        Closure closure = HelperUtil.toClosure("{ null }");

        transformer.add(closure);

        assertThat(transformer.transform("original"), equalTo("original"));
    }
View Full Code Here

        assertThat(transformer.transform("original"), equalTo("original"));
    }

    @Test
    public void usesOriginalObjectWhenClosureReturnsObjectOfUnexpectedType() {
        Closure closure = HelperUtil.toClosure("{ 9 }");

        transformer.add(closure);

        assertThat(transformer.transform("original"), equalTo("original"));
    }
View Full Code Here

TOP

Related Classes of groovy.lang.Closure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.