use of org.jmock.api.Invocation in project gradle by gradle.
the class DefaultDomainObjectCollectionTest method allCallsActionForEachNewObjectAddedByTheAction.
@Test
public void allCallsActionForEachNewObjectAddedByTheAction() {
@SuppressWarnings("unchecked") final Action<CharSequence> action = context.mock(Action.class);
context.checking(new Expectations() {
{
oneOf(action).execute("a");
will(new org.jmock.api.Action() {
public Object invoke(Invocation invocation) throws Throwable {
container.add("c");
return null;
}
public void describeTo(Description description) {
description.appendText("add 'c'");
}
});
oneOf(action).execute("b");
oneOf(action).execute("c");
}
});
container.add("a");
container.add("b");
container.all(action);
}
use of org.jmock.api.Invocation in project intellij-community by JetBrains.
the class PathMacroManagerTest method setupApplication.
@Before
public final void setupApplication() throws Exception {
context = new JUnit4Mockery();
context.setImposteriser(ClassImposteriser.INSTANCE);
myApplication = context.mock(ApplicationEx.class, "application");
context.checking(new Expectations() {
{
allowing(myApplication).isUnitTestMode();
will(returnValue(false));
allowing(myApplication).getName();
will(returnValue("IDEA"));
// some tests leave invokeLater()'s after them
allowing(myApplication).invokeLater(with(any(Runnable.class)), with(any(ModalityState.class)));
allowing(myApplication).runReadAction(with(any(Runnable.class)));
will(new Action() {
@Override
public void describeTo(final Description description) {
description.appendText("runs runnable");
}
@Override
@Nullable
public Object invoke(final Invocation invocation) throws Throwable {
((Runnable) invocation.getParameter(0)).run();
return null;
}
});
}
});
final ExtensionsArea area = Extensions.getRootArea();
final String epName = PathMacrosCollector.MACRO_FILTER_EXTENSION_POINT_NAME.getName();
if (!area.hasExtensionPoint(epName)) {
area.registerExtensionPoint(epName, "com.intellij.openapi.application.PathMacroFilter");
Disposer.register(myRootDisposable, new Disposable() {
@Override
public void dispose() {
area.unregisterExtensionPoint(epName);
}
});
}
}
use of org.jmock.api.Invocation in project geode by apache.
the class AutoBalancerJUnitTest method destroyAutoBalancer.
@Test
public void destroyAutoBalancer() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
final CountDownLatch timerLatch = new CountDownLatch(1);
// simulate 20 milliseconds
final int timer = 20;
mockContext.checking(new Expectations() {
{
oneOf(mockAuditor).init(with(any(Properties.class)));
allowing(mockAuditor).execute();
allowing(mockClock).currentTimeMillis();
will(new CustomAction("returnTime") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
latch.countDown();
if (latch.getCount() == 0) {
assertTrue(timerLatch.await(1, TimeUnit.SECONDS));
// scheduler is destroyed before wait is over
fail();
}
return 1000L - timer;
}
});
}
});
Properties props = AutoBalancerJUnitTest.getBasicConfig();
assertEquals(2, latch.getCount());
AutoBalancer autoR = new AutoBalancer(null, mockAuditor, mockClock, null);
autoR.init(props);
assertTrue(latch.await(1, TimeUnit.SECONDS));
// after destroy no more execute will be called.
autoR.destroy();
timerLatch.countDown();
TimeUnit.MILLISECONDS.sleep(2 * timer);
}
use of org.jmock.api.Invocation in project sling by apache.
the class TopologyRequestValidatorTest method testTrustResponse.
@Test
public void testTrustResponse() throws IOException {
final HttpServletRequest request = context.mock(HttpServletRequest.class);
context.checking(new Expectations() {
{
allowing(request).getRequestURI();
will(returnValue("/Test/Uri2"));
}
});
final HttpServletResponse response = context.mock(HttpServletResponse.class);
final Map<Object, Object> headers = new HashMap<Object, Object>();
context.checking(new Expectations() {
{
allowing(response).setHeader(with(any(String.class)), with(any(String.class)));
will(new Action() {
public void describeTo(Description desc) {
desc.appendText("Setting header ");
}
public Object invoke(Invocation invocation) throws Throwable {
headers.put(invocation.getParameter(0), invocation.getParameter(1));
return null;
}
});
}
});
String clearMessage = "TestMessage2";
final String message = topologyRequestValidator.encodeMessage(clearMessage);
topologyRequestValidator.trustMessage(response, request, message);
final HttpEntity responseEntity = context.mock(HttpEntity.class);
context.checking(new Expectations() {
{
allowing(responseEntity).getContent();
will(returnValue(new ByteArrayInputStream(message.getBytes())));
}
});
final HttpResponse resp = context.mock(HttpResponse.class);
context.checking(new Expectations() {
{
allowing(resp).getFirstHeader(with(any(String.class)));
will(new Action() {
public void describeTo(Description desc) {
desc.appendText("Getting (first) header ");
}
public Object invoke(Invocation invocation) throws Throwable {
return new BasicHeader((String) invocation.getParameter(0), (String) headers.get(invocation.getParameter(0)));
}
});
allowing(resp).getEntity();
will(returnValue(responseEntity));
}
});
topologyRequestValidator.isTrusted(resp);
topologyRequestValidator.decodeMessage("/Test/Uri2", resp);
}
use of org.jmock.api.Invocation in project sling by apache.
the class RepositoryTestHelper method mockResourceResolverFactory.
public static ResourceResolverFactory mockResourceResolverFactory(final SlingRepository repositoryOrNull) throws Exception {
Mockery context = new JUnit4Mockery() {
{
// @see http://www.jmock.org/threading-synchroniser.html
setThreadingPolicy(new Synchroniser());
}
};
final ResourceResolverFactory resourceResolverFactory = context.mock(ResourceResolverFactory.class);
// final ResourceResolver resourceResolver = new MockResourceResolver();
// final ResourceResolver resourceResolver = new
// MockedResourceResolver();
context.checking(new Expectations() {
{
allowing(resourceResolverFactory).getServiceResourceResolver(null);
will(new Action() {
@Override
public Object invoke(Invocation invocation) throws Throwable {
return new MockedResourceResolver(repositoryOrNull);
}
@Override
public void describeTo(Description arg0) {
arg0.appendText("whateva - im going to create a new mockedresourceresolver");
}
});
}
});
return resourceResolverFactory;
}
Aggregations