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 8300841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:42:14+00:00 2026-06-08T16:42:14+00:00

In my controller, i have an action which uses criteria to hit db and

  • 0

In my controller, i have an action which uses criteria to hit db and fetch results.

def c = DomainObj.createCriteria()
def result =[]
result = c.list(params) {
    'eq'("employerid", id)
    }

I am trying to mock this criteria in my unit test.

def mycriteria =[
list: {Closure cls -> new DomainObj(id:1)}
]                                   ]
DomainObj.metaClass.static.createCriteria = {mycriteria}

The above does not work. It throws out an exception when c.list(params) is being executed. The exception is “groovy.lang.MissingMethodException: No signature of method: testSearch_closure3.docall() is applicable for arguement types:

PS- However, if i remove params from c.list() in controller i.e. see below:

def c = DomainObj.createCriteria()
    def result =[]
result = c.list() {
    }

then, it is working. Not sure what the problem here is. Any help is appreciated

  • 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-08T16:42:15+00:00Added an answer on June 8, 2026 at 4:42 pm

    This is because of the default parametes of the list method.

    e.g.

    def method(Object[] params = {/*no params*/}, Closure c, etc. etc.)  {...}
    

    above can be used like:

    method(c: {...})
    method(params) {...}
    method(params, {...}) // this is the same as the above
    method(params:new Object[]{...}, c: {...}) // and this also
    //etc.
    

    you change metaClass and add method list that takes only one parameter.

    So your mycriteria should look like this:

    def mycriteria = [
        list: {Object params=null, Closure cls -> new DomainObj(id:1)}
        //or recreate `list` declaration with all parameters
    ]
    DomainObj.metaClass.static.createCriteria = {mycriteria}
    

    consider this example:

    def cl = {String a = 'x', b -> println a +','+ b}
    cl("z")
    

    output is:

    x, z
    

    EDIT

    To change returned object you do as previously:

    class A {
    }
    
    A.metaClass.static.createCriteria = {
        [list: 
            {def a = new A(); a.metaClass.totalResult=5; a}
        ]
    }
    
    def c = A.createCriteria()
    def result = c.list()
    println result.totalResult
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller action that uses a static variable on Global.asax which is
I have controller users . In this controller I have action account which is
i have a controller named PagesController which used to have an action named contest
I have a controller named Content, which has an Index action, which is associated
I have a javascript function from which I need to call a controller action
I have an url domain.com/a which redirects to domain.com/controller/action/a . How do I get
I have a form which users must fill out and submit. The controller action
I have a controller, Hardware which has a Create action. The model looks like:
I have a unit test method which tests a controller action method. The action
I have a controller which uses AJAX for CRUD, however whenever I click on

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.