use of org.jmock.api.Invocation in project intellij-community by JetBrains.
the class TabPostFormatProcessorTest method doDocumentTest.
private void doDocumentTest(@NotNull String initial, @NotNull String expected, boolean useTabs, boolean smartTabs, int tabWidth) {
Pair<String, TextRange> pair = parse(initial);
final StringBuilder text = new StringBuilder(pair.first);
final TextRange range = pair.second;
myMockery.checking(new Expectations() {
{
allowing(myDocument).getCharsSequence();
will(returnValue(text.toString()));
allowing(myDocument).getTextLength();
will(returnValue(text.length()));
}
});
final LineSet lines = LineSet.createLineSet(myDocument.getCharsSequence());
myMockery.checking(new Expectations() {
{
allowing(myDocument).getLineNumber(with(any(int.class)));
will(new CustomAction("getLineNumber()") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
return lines.findLineIndex((Integer) invocation.getParameter(0));
}
});
allowing(myDocument).getLineStartOffset(with(any(int.class)));
will(new CustomAction("getLineStartOffset()") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
return lines.getLineStart((Integer) invocation.getParameter(0));
}
});
allowing(myDocument).getLineEndOffset(with(any(int.class)));
will(new CustomAction("getLineEndOffset()") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
return lines.getLineEnd((Integer) invocation.getParameter(0));
}
});
allowing(myDocument).replaceString(with(any(int.class)), with(any(int.class)), with(any(String.class)));
will(new CustomAction("replaceString") {
@Nullable
@Override
public Object invoke(Invocation invocation) throws Throwable {
int start = (Integer) invocation.getParameter(0);
int end = (Integer) invocation.getParameter(1);
String newText = (String) invocation.getParameter(2);
text.replace(start, end, newText);
return null;
}
});
}
});
TabPostFormatProcessor.processViaDocument(myDocument, range, useTabs, smartTabs, tabWidth);
assertEquals(expected, text.toString());
}
use of org.jmock.api.Invocation in project geode by apache.
the class AutoBalancerJUnitTest method testAuditorInvocation.
@Test
public void testAuditorInvocation() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(3);
mockContext.checking(new Expectations() {
{
oneOf(mockAuditor).init(with(any(Properties.class)));
exactly(2).of(mockAuditor).execute();
allowing(mockClock).currentTimeMillis();
will(new CustomAction("returnTime") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
latch.countDown();
return 990L;
}
});
}
});
Properties props = AutoBalancerJUnitTest.getBasicConfig();
assertEquals(3, latch.getCount());
AutoBalancer autoR = new AutoBalancer(null, mockAuditor, mockClock, null);
autoR.init(props);
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of org.jmock.api.Invocation 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.api.Invocation in project gradle by gradle.
the class TaskReportTaskTest method task.
private Task task(final String name, final String taskGroup, final Task... dependencies) {
final Task task = context.mock(Task.class);
context.checking(new Expectations() {
{
allowing(task).getName();
will(returnValue(name));
allowing(task).getPath();
will(returnValue(':' + name));
allowing(task).getProject();
will(returnValue(project));
allowing(project).relativeProjectPath(':' + name);
will(returnValue(name));
allowing(task).getGroup();
will(returnValue(taskGroup));
allowing(task).compareTo(with(Matchers.notNullValue(Task.class)));
will(new Action() {
public Object invoke(Invocation invocation) throws Throwable {
Task other = (Task) invocation.getParameter(0);
return name.compareTo(other.getName());
}
public void describeTo(Description description) {
description.appendText("compare to");
}
});
TaskDependency dependency = context.mock(TaskDependency.class);
allowing(task).getTaskDependencies();
will(returnValue(dependency));
allowing(dependency).getDependencies(task);
will(returnValue(toSet(dependencies)));
}
});
return task;
}
use of org.jmock.api.Invocation in project xwiki-platform by xwiki.
the class AnnotationsMockSetup method setupExpectations.
/**
* Sets up the expectations for the {@link IOService} and {@link IOTargetService} to return correctly the values in
* the test files for {@code docName}. Call this function when operating with mocked documents to provide all the
* information in the test file (document source, rendered contents, annotations).
*
* @param docName the name of the document to setup expectations for
* @throws IOServiceException if something wrong happens while mocking the documents access
* @throws IOException if something wrong happens while mocking the documents access
*/
public void setupExpectations(final String docName) throws IOServiceException, IOException {
mockery.checking(new Expectations() {
{
MockDocument mDoc = docFactory.getDocument(docName);
allowing(ioService).getAnnotations(with(docName));
will(returnValue(mDoc.getAnnotations()));
allowing(ioService).updateAnnotations(with(docName), with(any(Collection.class)));
// update the list of document annotations
will(new Action() {
@Override
public void describeTo(Description description) {
description.appendText("Updates the annotations");
}
@Override
public Object invoke(Invocation invocation) throws Throwable {
String documentName = (String) invocation.getParameter(0);
MockDocument document = docFactory.getDocument(documentName);
Collection<Annotation> annList = (Collection<Annotation>) invocation.getParameter(1);
for (Annotation ann : annList) {
Annotation toUpdate = getAnnotation(ann.getId(), document.getAnnotations());
// remove toUpdate and add ann
if (toUpdate != null) {
document.getAnnotations().remove(toUpdate);
}
document.getAnnotations().add(ann);
}
return null;
}
private Annotation getAnnotation(String annId, Collection<Annotation> list) {
for (Annotation ann : list) {
if (ann.getId().equals(annId)) {
return ann;
}
}
return null;
}
});
allowing(ioTargetService).getSource(with(docName));
will(returnValue(mDoc.getSource()));
allowing(ioTargetService).getSourceSyntax(with(docName));
will(returnValue(mDoc.getSyntax()));
}
});
}
Aggregations