0

I have a non-service class which is defined as such:

class A{
   B b
   A( B b ){ this.b = b }
}

where B is a grails service. In my unit tests, I tried this:

A a = new A( new B() );

For some reason, however, b never gets set, and the variable b [local, the argument to the mehod] isn't even visible in Intelli-J's debugger when running the test. That is, I can rename the argument to service, and the debugger shows it as undefined.

When I try to start a server, I get Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException, so I'm assuming this is related.

What's going on here?

Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406
  • Does this help? http://stackoverflow.com/questions/1703952/grails-how-do-you-unit-test-a-command-object-with-a-service-injected-into-it/ – tim_yates Jan 31 '11 at 09:00

1 Answers1

2

That seems like a strange scenario. What is A doing? Is there any chance that A is really a service?

I'd suggest making A a service, in which case you can inject the B service into it as per normal usage.

I don't think that doing 'new B()' would really be valid, unless B has no dependencies on anything (autowired fields). Perhaps injecting B into the test would be better?

Paul
  • 142
  • 2