I am using morphia
(ODM for mongodb
) in my project and write its annotations on my models.
I want to write unit tests to validate the mapping.
I can call the mapper, using morphia.getMapper().toDBObject(input)
and run a test on the output.
For example, for the model
Car:
@Property("COLOR")
String color;
@Property("PlaTE")
int plate;
@Property("seats")
int seats;
I expect to receive the output:
{ "COLOR" : "value", "PlaTE" : 111, "seats" : 4 }
In order to test it, I need to create a string that represent this output, and in java it's a nightmare...
String expected = "{ \"COLOR\": \"value\", \"PlaTE\": 111, \"seats\" }";
And you can see how ugly this can get with embedded objects and arrays...
I was thinking of writing the output in a json
file and read it during the test, but it kinda breaks the rules of unit testing...
Is there any convenient way of representing json objects in java to achieve a neat and clean unit tests?