• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Testing Spring MVC Controller that make use of @ModelAttribute to bind method return values

 
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am having a bit of a problem getting comfortable with testing Spring MVC controller.

Consider a method like this:



I have been using methods like these to expose collections to thymeleaf views(I am used to using Seam/CDI, go figure).

Now I wish to use Spring Test MVC to unit test my controllers but I am running into problems.
For example, I am trying to test the following method:



My test looks like:



But the problem is that the "branches" collection has never been populated ( I guess because I am executing in the context of spring-test-mvc).
I am doing something horribly wrong but I'm not sure what it is..
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so my solution was to mock the return values of all the service calls with Mockito so that regardless of when the method was called, it would still return sensible results.
 
reply
    Bookmark Topic Watch Topic
  • New Topic