### Question:
BackupResource { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response createBackup(@Auth UserInfo userInfo, @Valid BackupFormDTO backupFormDTO) { log.debug("Creating backup for user {} with parameters {}", userInfo.getName(), backupFormDTO); final EnvBackupDTO dto = requestBuilder.newBackupCreate(backupFormDTO, UUID.randomUUID().toString()); final String uuid = backupService.createBackup(dto, userInfo); requestId.put(userInfo.getName(), uuid); return Response.accepted(uuid).build(); } @Inject  BackupResource(BackupService backupService, RequestBuilder requestBuilder, RequestId requestId); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) Response createBackup(@Auth UserInfo userInfo,
								 @Valid BackupFormDTO backupFormDTO); @GET @Produces(MediaType.APPLICATION_JSON) Response getBackups(@Auth UserInfo userInfo); @GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON) Response getBackup(@Auth UserInfo userInfo,
							  @PathParam("id") String id);  }### Answer:
@Test public void createBackup() { when(requestBuilder.newBackupCreate(any(BackupFormDTO.class), anyString())).thenReturn(getEnvBackupDto()); when(backupService.createBackup(any(EnvBackupDTO.class), any(UserInfo.class))).thenReturn("someUuid"); when(requestId.put(anyString(), anyString())).thenReturn("someUuid"); final Response response = resources.getJerseyTest() .target("/infrastructure/backup") .request() .header("Authorization", "Bearer " + TOKEN) .post(Entity.json(getBackupFormDto())); assertEquals(HttpStatus.SC_ACCEPTED, response.getStatus()); assertEquals(MediaType.TEXT_PLAIN, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verify(requestBuilder).newBackupCreate(eq(getBackupFormDto()), anyString()); verify(backupService).createBackup(getEnvBackupDto(), getUserInfo()); verify(requestId).put(USER.toLowerCase(), "someUuid"); verifyNoMoreInteractions(requestBuilder, backupService, requestId); }
@Test public void createBackupWithFailedAuth() throws AuthenticationException { authFailSetup(); when(requestBuilder.newBackupCreate(any(BackupFormDTO.class), anyString())).thenReturn(getEnvBackupDto()); when(backupService.createBackup(any(EnvBackupDTO.class), any(UserInfo.class))).thenReturn("someUuid"); when(requestId.put(anyString(), anyString())).thenReturn("someUuid"); final Response response = resources.getJerseyTest() .target("/infrastructure/backup") .request() .header("Authorization", "Bearer " + TOKEN) .post(Entity.json(getBackupFormDto())); assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatus()); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verifyZeroInteractions(requestBuilder, backupService, requestId); }