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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:13:08+00:00 2026-06-10T08:13:08+00:00

I am trying to write a test case for this method, which works when

  • 0

I am trying to write a test case for this method, which works when it is hit from non test case code…

import grails.converters.XML
Class itemService(){

    def getData(Map){
        def helperBean = new HelperBean(Map)
        def requestXml = helperBean as XML
            -------- some code-------------
        return requestXml
        }
    }

To test this method, I have a test case like this:

 void testGetData(){

            def service = new itemService()
            def id="123"
            def map = [id:id.toLong()]
            def result = service.getData(map)
            assertNotNull(result)
            assertEquals "123", result.id
        }

But it keeps throwing this exception

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.xyz.groovy.utils.helperBean@443acc67' with class 'com.xyz.groovy.utils.HelperBean' to class 'grails.converters.XML'

at this line in the getData(Map method)

   def requestXml = userBean as XML

Can anyone help me out with why it is throwing that exception when the getData(Map) is being hit from the test case only? It is working fine when that method is hit from non test case code.

  • 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-10T08:13:09+00:00Added an answer on June 10, 2026 at 8:13 am

    Found the solution. Adding
    addConverters(helperBean) in the setup() method of the test case should solve the problem.

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

Sidebar

Related Questions

This is for Play! Framework 2.0. I'm trying to write a simple test case
I am trying to write code to test a method by mocking the class
I am trying to write an Android test case on a block of code
I am trying to write a test case for the depot application. Below is
I'm trying to write a unit test for a piece of code that generates
I'm trying to write a test case for Selenium and I'm having a little
I'am trying to write something like this: trait Typed[T] trait Test { def testMap:
I am trying to test that a particular method throws an expected exception from
I'm trying to write a test for the following method: public class Sort {
I'm trying to write a test case where my scenario is that two byte

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.