[jax-rs-spec users] Re: Why is "Entity" class final

From: <>
Date: Thu, 20 Aug 2015 19:12:13 +0000 (UTC)

Hi Marek. Thanks for replying...

What I really want to stub is the Inovcation.Builder that makes the
actually http call; in unit test, I don't really want it to call HTTP,
so I want to stub it.

The source code looks like this:

// some code to set up the "formPart" parameters...

        final MultiPart multiPart = formPart.bodyPart(new
StreamDataBodyPart("file", inStream));

        final Response response =,
        return response.readEntity(JsonObject.class);

Note that "invocationBuilder" is a class field, so in my unit test i
have something like this, using Mockito:

        Invocation.Builder mockBuilder =
        Response mockResponse = mock(Response.class);

// i had to match "entity" to "any()" because "Entity" is final

        JsonObject expResult = null;

        instance.invocationBuilder = mockBuilder;

        JsonObject result =
instance.retrieveMatchingSidings(matchingCriteria, originalImage);
        assertEquals(expResult, result);

Note that I had to match the "entity" parameter to "any" and downcast
it because "Entity" class is final. Ideally I'd want to give a more
reasonable/verifying stub of "entity" to check my logic; but can not
here due to the "final" mark on Entity.