Thank you ever so much for the replies! In the end I started to refactor the first snippet and wow.. I opened a can of worms. There was so much code to refactor Ive spent the best part of two days doing it and nearly completed. The whole application object model is so tightly coupled its been a real pain sorting it out to use DI. Thanks for your help though!
Darren Carr wrote:In the end I started to refactor the first snippet and wow.. I opened a can of worms. There was so much code to refactor Ive spent the best part of two days doing it and nearly completed.
Consider yourself lucky they were just worms and it only took you two days to clean it up! Not that I have anything against worms but I have seen things much more disgusting than that in my day
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
I resolved the problem and posting the solution here to help others .
First off my problem was that I was using the standaloneSetup method from the MockMVCBuilders class. This does not use the configuration that I loaded from the @ContextConfiguation annotation (i.e RegistrationControllerTesting-context.xml)
So it was simply a case of using the MockMVCBuilders.xmlConfigSetup to load in my servlet context with mock objects, and then remove the @ContextConfiguration.
So the code:
This example uses spring-test-mvc and loads in the servlet context from an xml file and injects mocked objects into the controllers @Autowired attributes. It calls a rest service passing in some Json.
Unit Test Case
Hope it helps others.
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad: