### Question:
BackupResource { @GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON) public Response getBackup(@Auth UserInfo userInfo, @PathParam("id") String id) { log.debug("Getting backup with id {} for user {}", id, userInfo.getName()); return Response.ok(backupService.getBackup(userInfo.getName(), id)).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 getBackup() { when(backupService.getBackup(anyString(), anyString())).thenReturn(getBackupInfo()); final Response response = resources.getJerseyTest() .target("/infrastructure/backup/1") .request() .header("Authorization", "Bearer " + TOKEN) .get(); assertEquals(HttpStatus.SC_OK, response.getStatus()); assertEquals(getBackupInfo(), response.readEntity(BackupInfoRecord.class)); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verify(backupService).getBackup(USER.toLowerCase(), "1"); verifyNoMoreInteractions(backupService); verifyZeroInteractions(requestId, requestBuilder); }
@Test public void getBackupWithFailedAuth() throws AuthenticationException { authFailSetup(); when(backupService.getBackup(anyString(), anyString())).thenReturn(getBackupInfo()); final Response response = resources.getJerseyTest() .target("/infrastructure/backup/1") .request() .header("Authorization", "Bearer " + TOKEN) .get(); assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatus()); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verifyZeroInteractions(backupService, requestId, requestBuilder); }
@Test public void getBackupWithNotFoundException() { when(backupService.getBackup(anyString(), anyString())).thenThrow(new ResourceNotFoundException("Backup not " + "found")); final Response response = resources.getJerseyTest() .target("/infrastructure/backup/1") .request() .header("Authorization", "Bearer " + TOKEN) .get(); assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); verify(backupService).getBackup(USER.toLowerCase(), "1"); verifyNoMoreInteractions(backupService); verifyZeroInteractions(requestId, requestBuilder); }