• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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:

 
Marshal
Posts: 16591
277
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic