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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:57:15+00:00 2026-05-13T07:57:15+00:00

Anyone used this annotation in grails unit tests? Didnt seem to work for me.

  • 0

Anyone used this annotation in grails unit tests?
Didnt seem to work for me.
Thanks.
D

Update: the last line of my test below does throw the expected exception. However the test fails (Stack trace too big for here…). I’m using grails 1.2 and running the test in eclipse’s junit runner. Maybe grails is using an earlier version of junit than 4?

/**
 * Get the EC by a manager of a different company. Should throw exception
 */
@ExpectedException(ServiceAuthorizationException.class)
void testGetEcByNonOwnerManagerOfDifferentCompany() {
    mockDomain(ExpenseClaim , [new ExpenseClaim(id:"1",narrative:"marksClaim", employee:userMark, company:dereksCompany)])      

    def authControl = mockFor(AuthenticateService)
    authControl.demand.userDomain(1..1)  {-> otherUserMgr }
    authControl.demand.ifAllGranted(1..1)  {String arg1 -> return "ROLE_COMPANYMANAGER".equals(arg1) } //returns true
    def testService = new ExpenseClaimService()
    testService.authenticateService = authControl.createMock()
    def thrown = false
    testService.getExpenseClaim("1")
}
  • 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-05-13T07:57:16+00:00Added an answer on May 13, 2026 at 7:57 am

    Only JUnit 3 is currently supported, so use shouldFail() instead:

    void testGetEcByNonOwnerManagerOfDifferentCompany() {
    
      shouldFail(ServiceAuthorizationException) {
        mockDomain(ExpenseClaim , [new ExpenseClaim(id:"1",
                                   narrative:"marksClaim", employee:userMark,
                                   company:dereksCompany)])      
    
        def authControl = mockFor(AuthenticateService)
        authControl.demand.userDomain(1..1)  {-> otherUserMgr }
        authControl.demand.ifAllGranted(1..1)  {String arg1 ->
           "ROLE_COMPANYMANAGER".equals(arg1) } //returns true
        def testService = new ExpenseClaimService()
        testService.authenticateService = authControl.createMock()
        testService.getExpenseClaim("1")
      }
    }
    

    shouldFail() is actually more convenient since you can use it more than once per test, and it returns the exception message so you can assert based on the message as well as the exception.

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

Sidebar

Related Questions

Has anyone used this ORM? Telerik OpenAccess Critiques/Praise? I work in an office that
Has anyone used this plugin? I don't know if my setup is right, but
Is anyone out there used Rapidminer for sentiment analysis... Is this a right combination???
Has anyone else come across this at all? I used to be able to
We're evaluating Sencha Touch for mobile development. Has anyone used this yet (I realize
What is the best way to secure ADO.NET data services? Has anyone used this
have anyone used this before, i need free country, city, IP database for sqlserver
Has anyone used this class and see if it is broken in android version
Has anyone used Hazelcast (preferably 2.1) with play framework 2.0/2.1 (not 1.2+)? I am
Has anyone used both Joone and Encog in production applications? Is there something you

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.