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