-
-
Notifications
You must be signed in to change notification settings - Fork 765
Description
Feature summary
While working on the AssertJ support for Spring MVC, I've realized that assertJ does not provide a lot of conversion utilities for the actual value, which is more than fair, but can be helpful higher in the stack.
One of the support we have is for json path where you can craft an expression against the body result of an HTTP request and further assert the content. Our json path feature an "extractingPath" that is similar to AssertJ's extracting feature. But that operates on the raw value and we want to be able to assert that the raw JSON can be deserialized to a DTO.
Example
Let's take a silly little example with a family API that returns this:
{
"familyMembers": [
{ "name": "Homer" },
{ "name": "Marge" },
{ "name": "Bart" },
{ "name": "Lisa" },
{ "name": "Maggie" }
]
}Ignoring the setup, this is the pseudo code I am talking about:
@Test
void convertToTargetType() {
assertThat(mvc.perform(get("/family"))).body().jsonPath()
.extractingPath("$.familyMembers[0]").convertTo(Member.class)
.satisfies(member -> assertThat(member.name).isEqualTo("Homer"));
}This works but I am returning an AbstractObjectAssert against my DTO that represent a family member. What's I'd like to do is to express a type and, at the same time, provide a dedicated Assert implementation for it.
InstanceOfAssertFactory does what I need but getType is package private so I can't access it. Also I like the idea of having an interface for this concept and expose a Type so that generic types can be taken into account perhaps?
Also InstanceOfAssertFactorycarry the fact that the actual is expected to be of that type which, again, is totally fair but custom APIs may benefit from conversion as well.