### Question:
CustomEntityResource { @POST @Path("/") public Response createOrUpdatePost(@Context final UriInfo uriInfo, final EntityBody customEntity) { if (entityDefinition == null) { return Response.status(Status.NOT_FOUND).build(); } entityDefinition.getService().createOrUpdateCustom(entityId, customEntity); String uri = ResourceUtil.getURI(uriInfo, resourceHelper.extractVersion(uriInfo.getPathSegments()), PathConstants.TEMP_MAP.get(entityDefinition.getResourceName()), entityId, PathConstants.CUSTOM_ENTITIES) .toString(); return Response.status(Status.CREATED).header("Location", uri).build(); } CustomEntityResource(final String entityId, final EntityDefinition entityDefinition,
                                final ResourceHelper resourceHelper); @GET @Path("/") Response read(); @PUT @Path("/") Response createOrUpdatePut(final EntityBody customEntity); @POST @Path("/") Response createOrUpdatePost(@Context final UriInfo uriInfo,
                                       final EntityBody customEntity); @DELETE @Path("/") Response delete();  }### Answer:
@Test public void testCreateOrUpdatePOST() { EntityBody test = new EntityBody(); UriInfo uriInfo = Mockito.mock(UriInfo.class); final UriBuilder uriBuilder = Mockito.mock(UriBuilder.class); Mockito.when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder); final StringBuilder path = new StringBuilder(); Mockito.when(uriBuilder.path(Mockito.anyString())).thenAnswer(new Answer<UriBuilder>() { @Override public UriBuilder answer(InvocationOnMock invocation) throws Throwable { path.append("/").append(invocation.getArguments()[0]); return uriBuilder; } }); Mockito.when(uriBuilder.build()).thenAnswer(new Answer<URI>() { @Override public URI answer(InvocationOnMock invocation) throws Throwable { URI uri = new URI(path.toString()); return uri; } }); Response res = resource.createOrUpdatePost(uriInfo, test); assertNotNull(res); assertEquals(Status.CREATED.getStatusCode(), res.getStatus()); assertNotNull(res.getMetadata().get("Location")); assertEquals(1, res.getMetadata().get("Location").size()); assertEquals("/" + PathConstants.V1 + "/TEST-ID/custom", res.getMetadata().get("Location").get(0)); Mockito.verify(service).createOrUpdateCustom("TEST-ID", test); }