Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8491385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:24:30+00:00 2026-06-10T22:24:30+00:00

I have a following snippet with JMock expectations in my test method: context.checking(new Expectations()

  • 0

I have a following snippet with JMock expectations in my test method:

context.checking(new Expectations() {{
    allowing(listener).tableChanged(with(anyInsertionEvent()));
    oneOf(listener).tableChanged(with(aRowChangedEvent(0)));
}});

where anyInsertionEvent and aRowChangedEventAs return instances of Matcher<TableModelEvent>.
This is taken from book “Growing Object-Oriented Software Guided by Tests” (p. 181).

I try to convert this test to Groovy, but the method I need:

org.jmock.Expectations.with(org.hamcrest.Matcher<T>)

is shadowed by:

org.codehaus.groovy.runtime.DefaultGroovyMethods.with(java.lang.Object, 
    groovy.lang.Closure<T>)

As a result I get an error during my tests like:

groovy.lang.MissingMethodException: No signature of method: $Proxy8.tableChanged() is     applicable for argument types: (java.lang.Boolean) values: [false]
Possible solutions: tableChanged(javax.swing.event.TableModelEvent)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
    at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.rorick.auctionsniper.ui.SnipersTableModelTest$1.<init>(SnipersTableModelTest.groovy:43)
    at org.rorick.auctionsniper.ui.SnipersTableModelTest.setSniperValuesInColumns(SnipersTableModelTest.groovy:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)
    at org.jmock.integration.junit4.JMock$1.invoke(JMock.java:37)
    at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:105)
    at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:86)
    at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
    at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:98)
    at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
    at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:54)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
    at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:52)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

How can I use appropriate with method? Or, please, advice any other way to resolve this issue.

UPDATE: it is not shadowing. The method actually called is Expectations.with(Matcher<Boolean>) hence false value in stack-trace. So, method is incorrectly dispatched. Any ideas what to do with that?

UPDATE: Matcher method are the following:

public Matcher<TableModelEvent> anyInsertionEvent() {
    Matcher<Integer> insertMatcher = equalTo(TableModelEvent.INSERT);
    return new FeatureMatcher<TableModelEvent, Integer>(insertMatcher, "is an insertion event", "event type") {
        @Override
        protected Integer featureValueOf(TableModelEvent actual) {
            return actual.getType();
        }
    };
}

private Matcher<TableModelEvent> aRowChangedEvent(int row) {
    return samePropertyValuesAs(new TableModelEvent(model, row));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:24:31+00:00Added an answer on June 10, 2026 at 10:24 pm

    Finally, I found a workaround for this. See the checking code below. new Expectations() {{}} Java syntax has gone and is replaced with closure:

    context.checking {
        allowing(listener).tableChanged(argThat(anyInsertionEvent()));
        oneOf(listener).tableChanged(argThat(aRowChangedEvent(0)));
    }
    

    Note that with is replaced with argThat (modeled after Mockito). context is not an instance of org.jmock.integration.junit4.JUnit4Mockery as it were, but is an instance of the following class:

    class JUnit4GroovyMockery extends JUnit4Mockery {
        public void checking(Closure c) {
             ClosureExpectations expectations = new ClosureExpectations();
             expectations.closureInit(c, expectations);
             super.checking(expectations);
        }
    
        private static class ClosureExpectations extends Expectations {
            void closureInit(Closure cl, Object delegate) {
                cl.setDelegate(delegate);
                cl.call();
            }
    
            public Object argThat(Matcher<?> matcher) {
                currentBuilder().addParameterMatcher(matcher);
                return null;
            }
        }
    }
    

    This is based on JUnit4GroovyMockery class from http://docs.codehaus.org/display/GROOVY/Using+JMock+with+Groovy. argThat is copy-pasted from Expectations.with(Matcher<T>) and Expectations.addParameterMatcher(Matcher<?>).

    This works for me, though I’m not very pleased with this solution; and I’d prefer to keep with name for the method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following snippet of java code: File directoryToMoveTo = new File(file.getParent()+_TEMP); boolean
I have the following snippet of java code: final Class<?> junitCoreClass = AccessController.doPrivileged( new
I have following snippet: static void Main(string[] args) { var container = new UnityContainer();
I have following code snippet in c#. var list = new List<string> { a,
I have following code snippet: var reg = /^[0-9]$/; $('input[type=text]').keypress(function(){ console.log(reg.test(parseInt($(this).val()))); }); When I
I have the following snippet of code, changeTextArea is a TextArea object. changeTextArea.addKeyboardListener(new KeyboardListenerAdapter()
I have the following snippet of code that's generating the Use new keyword if
I have following code snippet: addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) {
I have following code snippet: self.xmlHttpReq = new XMLHttpRequest(); self.xmlHttpReq.onreadystatechange = function() { if(self.xmlHttpReq.readyState
I have following code snippet in c# List<int> list = new List<int>() { 1,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.