• 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

JUnit test of controller failing

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 16146
269
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic