Search in sources :

Example 1 with Sequence

use of org.jmock.Sequence in project gradle by gradle.

the class DefaultScriptRunnerFactoryTest method wrapsExecutionExceptionAndRestoresStateWhenScriptFails.

@Test
public void wrapsExecutionExceptionAndRestoresStateWhenScriptFails() {
    final RuntimeException failure = new RuntimeException();
    ScriptRunner<?, Void> scriptRunner = factory.create(compiledScriptMock, scriptSourceDummy, classLoaderDummy);
    expectScriptInstantiated();
    context.checking(new Expectations() {

        {
            Sequence sequence = context.sequence("seq");
            allowing(compiledScriptMock).getRunDoesSomething();
            will(returnValue(true));
            one(scriptExecutionListenerMock).scriptClassLoaded(scriptSourceDummy, Script.class);
            inSequence(sequence);
            one(scriptMock).init(target, scriptServices);
            inSequence(sequence);
            one(standardOutputCaptureMock).start();
            inSequence(sequence);
            one(scriptMock).run();
            inSequence(sequence);
            will(throwException(failure));
            one(standardOutputCaptureMock).stop();
            inSequence(sequence);
        }
    });
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    assertThat(originalClassLoader, not(sameInstance(classLoaderDummy)));
    try {
        scriptRunner.run(target, scriptServices);
        fail();
    } catch (GradleScriptException e) {
        assertThat(e.getMessage(), equalTo("A problem occurred evaluating <script-to-string>."));
        assertThat(e.getCause(), sameInstance((Throwable) failure));
    }
    assertThat(Thread.currentThread().getContextClassLoader(), sameInstance(originalClassLoader));
}
Also used : Expectations(org.jmock.Expectations) Script(org.gradle.groovy.scripts.Script) GradleScriptException(org.gradle.api.GradleScriptException) Sequence(org.jmock.Sequence) Test(org.junit.Test)

Example 2 with Sequence

use of org.jmock.Sequence in project gradle by gradle.

the class DefaultScriptRunnerFactoryTest method setsUpAndTearsDownWhenNonEmptyScriptIsRun.

@Test
public void setsUpAndTearsDownWhenNonEmptyScriptIsRun() {
    ScriptRunner<?, Void> scriptRunner = factory.create(compiledScriptMock, scriptSourceDummy, classLoaderDummy);
    expectScriptInstantiated();
    context.checking(new Expectations() {

        {
            Sequence sequence = context.sequence("seq");
            allowing(compiledScriptMock).getRunDoesSomething();
            will(returnValue(true));
            one(scriptExecutionListenerMock).scriptClassLoaded(scriptSourceDummy, Script.class);
            inSequence(sequence);
            one(scriptMock).init(target, scriptServices);
            inSequence(sequence);
            one(standardOutputCaptureMock).start();
            inSequence(sequence);
            one(scriptMock).run();
            inSequence(sequence);
            will(doAll(new Action() {

                public void describeTo(Description description) {
                    description.appendValue("check context classloader");
                }

                public Object invoke(Invocation invocation) throws Throwable {
                    assertThat(Thread.currentThread().getContextClassLoader(), sameInstance(classLoaderDummy));
                    return null;
                }
            }));
            one(standardOutputCaptureMock).stop();
            inSequence(sequence);
        }
    });
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    assertThat(originalClassLoader, not(sameInstance(classLoaderDummy)));
    scriptRunner.run(target, scriptServices);
    assertThat(Thread.currentThread().getContextClassLoader(), sameInstance(originalClassLoader));
}
Also used : Expectations(org.jmock.Expectations) Script(org.gradle.groovy.scripts.Script) Action(org.jmock.api.Action) Description(org.hamcrest.Description) Invocation(org.jmock.api.Invocation) Sequence(org.jmock.Sequence) Test(org.junit.Test)

Example 3 with Sequence

use of org.jmock.Sequence in project gradle by gradle.

the class AbstractReportTaskTest method passesEachProjectToRenderer.

@Test
public void passesEachProjectToRenderer() throws IOException {
    final Project child1 = createChildProject(project, "child1");
    final Project child2 = createChildProject(project, "child2");
    task.setProjects(project.getAllprojects());
    context.checking(new Expectations() {

        {
            Sequence sequence = context.sequence("seq");
            one(renderer).setClientMetaData((BuildClientMetaData) with(notNullValue()));
            inSequence(sequence);
            one(renderer).setOutput((StyledTextOutput) with(notNullValue()));
            inSequence(sequence);
            one(renderer).startProject(project);
            inSequence(sequence);
            one(generator).run();
            inSequence(sequence);
            one(renderer).completeProject(project);
            inSequence(sequence);
            one(renderer).startProject(child1);
            inSequence(sequence);
            one(generator).run();
            inSequence(sequence);
            one(renderer).completeProject(child1);
            inSequence(sequence);
            one(renderer).startProject(child2);
            inSequence(sequence);
            one(generator).run();
            inSequence(sequence);
            one(renderer).completeProject(child2);
            inSequence(sequence);
            one(renderer).complete();
            inSequence(sequence);
        }
    });
    task.generate();
}
Also used : Expectations(org.jmock.Expectations) BuildClientMetaData(org.gradle.initialization.BuildClientMetaData) Project(org.gradle.api.Project) TestUtil.createChildProject(org.gradle.util.TestUtil.createChildProject) Sequence(org.jmock.Sequence) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) Test(org.junit.Test)

Example 4 with Sequence

use of org.jmock.Sequence in project gradle by gradle.

the class AbstractReportTaskTest method setsOutputFileNameOnRendererBeforeGeneration.

@Test
public void setsOutputFileNameOnRendererBeforeGeneration() throws IOException {
    final File file = tmpDir.getTestDirectory().file("report.txt");
    context.checking(new Expectations() {

        {
            Sequence sequence = context.sequence("sequence");
            one(renderer).setClientMetaData((BuildClientMetaData) with(notNullValue()));
            inSequence(sequence);
            one(renderer).setOutputFile(file);
            inSequence(sequence);
            one(renderer).startProject(project);
            inSequence(sequence);
            one(generator).run();
            inSequence(sequence);
            one(renderer).completeProject(project);
            inSequence(sequence);
            one(renderer).complete();
            inSequence(sequence);
        }
    });
    task.setOutputFile(file);
    task.generate();
}
Also used : Expectations(org.jmock.Expectations) BuildClientMetaData(org.gradle.initialization.BuildClientMetaData) Sequence(org.jmock.Sequence) File(java.io.File) Test(org.junit.Test)

Example 5 with Sequence

use of org.jmock.Sequence in project gradle by gradle.

the class AbstractReportTaskTest method completesRendererAtEndOfGeneration.

@Test
public void completesRendererAtEndOfGeneration() throws IOException {
    context.checking(new Expectations() {

        {
            Sequence sequence = context.sequence("sequence");
            one(renderer).setClientMetaData((BuildClientMetaData) with(notNullValue()));
            inSequence(sequence);
            one(renderer).setOutput((StyledTextOutput) with(notNullValue()));
            inSequence(sequence);
            one(renderer).startProject(project);
            inSequence(sequence);
            one(generator).run();
            inSequence(sequence);
            one(renderer).completeProject(project);
            inSequence(sequence);
            one(renderer).complete();
            inSequence(sequence);
        }
    });
    task.generate();
}
Also used : Expectations(org.jmock.Expectations) BuildClientMetaData(org.gradle.initialization.BuildClientMetaData) Sequence(org.jmock.Sequence) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) Test(org.junit.Test)

Aggregations

Expectations (org.jmock.Expectations)19 Sequence (org.jmock.Sequence)19 Test (org.junit.Test)19 OutputStream (java.io.OutputStream)7 UnitTest (org.apache.geode.test.junit.categories.UnitTest)7 BuildClientMetaData (org.gradle.initialization.BuildClientMetaData)3 List (java.util.List)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 Script (org.gradle.groovy.scripts.Script)2 StyledTextOutput (org.gradle.internal.logging.text.StyledTextOutput)2 File (java.io.File)1 GradleScriptException (org.gradle.api.GradleScriptException)1 Project (org.gradle.api.Project)1 Rule (org.gradle.api.Rule)1 Task (org.gradle.api.Task)1 TestUtil.createChildProject (org.gradle.util.TestUtil.createChildProject)1 Description (org.hamcrest.Description)1 Action (org.jmock.api.Action)1 Invocation (org.jmock.api.Invocation)1 Bundle (org.osgi.framework.Bundle)1