• 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
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Junit Test JsonProcessingException

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have problem testing , can someone help me please?

Here is the code I want to test:



Here is the test method :



When I'm testing RuntimeException, test is ok, but when testing JsonProcessingException it's printing error :




My goal is to send invalid request param so when objectmapper start mapping json string in CustomClass to throw JsonProcessingException or IoException.
When i change starting in this " its going to throw this warnign:

Tnx
 
Bartender
Posts: 2113
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you hard coding the customFakeName parameter? If so , try this:
 
Senad Delic
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Himai,
I tried that also, it didn't work.
I'm caching RuntimeException but not JsonProcessingException
 
Himai Minh
Bartender
Posts: 2113
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
What other details printed on the console regarding to this RuntimeException?
 
Sheriff
Posts: 4995
319
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exceptions from controller mappings can not be handled in the way you are expecting when testing with MockMvc. Any exception thrown from a controller mapping method will be received in your test as a 500 HTTP response. So instead of a try catch arrangement you'll need to do something like this
 
moose poop looks like football shaped elk poop. About the size of this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic