Win a copy of Terraform in Action this week in the Cloud 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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: 2125
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: 2125
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?
 
Marshal
Posts: 5169
322
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
reply
    Bookmark Topic Watch Topic
  • New Topic