### Question:
AndroidVariantEndpoint extends AbstractVariantEndpoint<AndroidVariant> { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registerAndroidVariant( AndroidVariant androidVariant, @PathParam("pushAppID") String pushApplicationID, @Context UriInfo uriInfo) { PushApplication pushApp = getSearch().findByPushApplicationIDForDeveloper(pushApplicationID); if (pushApp == null) { return Response.status(Status.NOT_FOUND).entity(ErrorBuilder.forPushApplications().notFound().build()).build(); } try { validateModelClass(androidVariant); } catch (ConstraintViolationException cve) { logger.trace("Unable to create Android variant"); ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } logger.trace("Register Android variant with Push Application '{}'", pushApplicationID); variantService.addVariant(androidVariant); pushAppService.addVariant(pushApp, androidVariant); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(androidVariant.getVariantID())).build()).entity(androidVariant).build(); } AndroidVariantEndpoint();   AndroidVariantEndpoint(Validator validator, SearchManager searchManager); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response registerAndroidVariant(
            AndroidVariant androidVariant,
            @PathParam("pushAppID") String pushApplicationID,
            @Context UriInfo uriInfo); @GET @Produces(MediaType.APPLICATION_JSON) Response listAllAndroidVariationsForPushApp(@PathParam("pushAppID") String pushApplicationID); @PUT @Path("/{androidID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateAndroidVariant(
            @PathParam("pushAppID") String pushApplicationId,
            @PathParam("androidID") String androidID,
            AndroidVariant updatedAndroidApplication);  }### Answer:
@Test public void shouldRegisterAndroidVariantSuccessfully() { final AndroidVariant variant = new AndroidVariant(); final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http: final PushApplication pushApp = new PushApplication(); when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp); when(validator.validate(variant)).thenReturn(Collections.EMPTY_SET); final Response response = this.endpoint.registerAndroidVariant(variant, "push-app-id", uriInfo); assertEquals(response.getStatus(), 201); assertTrue(response.getEntity() == variant); assertEquals(response.getMetadata().get("location").get(0).toString(), "http: verify(variantService).addVariant(variant); verify(pushAppService).addVariant(pushApp, variant); }
@Test public void registerAndroidVariantShouldReturn404WhenPushAppDoesNotExist() { final AndroidVariant variant = new AndroidVariant(); final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http: final PushApplication pushApp = new PushApplication(); when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(null); final Response response = this.endpoint.registerAndroidVariant(variant, "push-app-id", uriInfo); assertEquals(response.getStatus(), 404); verify(variantService, never()).addVariant(any()); verify(validator, never()).validate(any()); verify(pushAppService, never()).addVariant(any(), any()); }
@Test public void registerAndroidVariantShouldReturn400WhenVariantModelIsNotValid() { final AndroidVariant variant = new AndroidVariant(); final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http: final PushApplication pushApp = new PushApplication(); when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp); when(validator.validate(variant)).thenReturn(Sets.newHashSet(sampleViolation)); final Response response = this.endpoint.registerAndroidVariant(variant, "push-app-id", uriInfo); assertEquals(response.getStatus(), 400); verify(variantService, never()).addVariant(variant); verify(pushAppService, never()).addVariant(pushApp, variant); }