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.