This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JUnit test of controller failing

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a test method testing admin privileges for a put method in my controller, which updates the my Route entity in a JPARepository.  I added some logic to the controller to test if the update returns successfully by returning how many records were updated.  It returns a 400 if the Integer returned is <1.  Since I added that logic my unit test refuses to pass.  I'm wondering what about the logic is making it so that it always returns a 400?  Is my test written incorrectly?

Test Code:


Controller Code:

 
Sheriff
Posts: 15754
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The logic seems pretty staightforward. It's probably your expectation that your mock is returning 1 that's not lining up with the actual return value. If the value of noRecords on line 4 in your controller code is actually 0 then I'd look into how the mocks are getting set up. 0 is usually a default value so I'd look into why the thenReturn(new Integer(1)) isn't having the desired effect.
 
Rancher
Posts: 4610
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume that isn't a copy/paste from your code as what you've posted won't compile, for the test:


Your sourceDest is a List<String>, but matrixMap is declared as accepting a String value.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic