### Question:
ContextsJaxrsService { protected Class<?> getContextClass(MediaType mediaType) { Class<?> contextClass = contextsManager.getContextDescriptionClass(getType(mediaType)); if (contextClass == null) { throw new WebApplicationException(Response.Status.UNSUPPORTED_MEDIA_TYPE); } return contextClass; }  @POST Response createContext(InputStream stream, @HeaderParam(HttpHeaders.CONTENT_TYPE) MediaType mediaType,
            @HeaderParam(HttpHeaders.ACCEPT) MediaType accept, @Context HttpServletRequest request, @Context UriInfo uriInfo); @GET @Path("/{uuid}") @Produces({MediaType.APPLICATION_JSON}) Response getContextDetails(@PathParam("uuid") UUID uuid,
            @Context HttpServletRequest request); @DELETE @Path("/{uuid}") Response removeContextDetails(@PathParam("uuid") UUID uuid); @GET @Path("/{uuid}/metadata") Response getContextMetadata(@PathParam("uuid") UUID uuid, @Context HttpServletRequest request); @POST @Path("/{uuid}/metadata") Response getContextMetadata(@PathParam("uuid") UUID uuid, InputStream stream,
            @HeaderParam(HttpHeaders.CONTENT_TYPE) MediaType mediaType);  }### Answer:
@Test public void getConnectionClass(){ final String connectionType = "lfc"; final String type = "application/connections." + connectionType + "+json"; Class expectedClass = Number.class; when(contextsManager.getContextDescriptionClass(connectionType)).thenReturn(expectedClass); final Class<?> result = service.getContextClass(MediaType.valueOf(type)); assertSame(result, expectedClass); }
@Test(expectedExceptions = WebApplicationException.class) public void getConnectionClass_notExistentType_exception(){ service.getContextClass(MediaType.valueOf("application/connections.notExistentType+xml")); }
@Test(expectedExceptions = WebApplicationException.class) public void getConnectionClass_nullMediaType_exception(){ service.getContextClass(null); }