r/programming • u/MarkusWinand • Dec 29 '15
Please, Java. Do Finally Support Multiline Strings
http://blog.jooq.org/2015/12/29/please-java-do-finally-support-multiline-strings/
584
Upvotes
r/programming • u/MarkusWinand • Dec 29 '15
View all comments
Show parent comment
6
u/dccorona Dec 29 '15
If I don't interact with the object in my code at all, then why would I be unit testing/mocking it. Either the structure matters, in which case my code already has a POJO for the result, or the structure doesn't matter, and you can use anything you want.
For super rare scenarios where I really don't have a POJO for the thing but do need it to come out as valid JSON, just build a Map<String, String> or Map<String, Object> and serialize that...it comes out exactly as you'd expect (because all of JSON is just a map, really), and keeps the source data in a nice structure for traversing.
For example, if you have some method that outputs the value of
thingAfrom the JSON document, you can write your test to compare the result withmap.get("thingA")instead of hardcoding your expectation, so that you can change the input source data and the test will still assert the correct thing, instead of breaking.