### Question:
MarkForDeletionJob implements Runnable { @Override public void run() { try (Timer.Context context = timer.time()) { aclService.assertHasAccess("Insufficient privileges to delete object " + pid.getUUID(), pid, agent.getPrincipals(), markForDeletion); RepositoryObject repoObj = repositoryObjectLoader.getRepositoryObject(pid); if (repoObj instanceof AdminUnit) { aclService.assertHasAccess("Insufficient privileges to delete admin unit " + pid.getUUID(), pid, agent.getPrincipals(), markForDeletionUnit); } if (!(repoObj instanceof ContentObject)) { throw new InvalidOperationForObjectType("Cannot mark object " + pid.getUUID() + " for deletion, objects of type " + repoObj.getClass().getName() + " are not eligible."); } String updateString = createSparqlReplace(pid.getRepositoryPath(), markedForDeletion, true); sparqlUpdateService.executeUpdate(repoObj.getMetadataUri().toString(), updateString); repoObj.getPremisLog().buildEvent(Premis.Deaccession) .addImplementorAgent(AgentPids.forPerson(agent)) .addEventDetail("Item marked for deletion and not available without permissions") .addEventDetail(message) .writeAndClose(); } } MarkForDeletionJob(PID pid, String message, AgentPrincipals agent,
            RepositoryObjectLoader repositoryObjectLoader, SparqlUpdateService sparqlUpdateService,
            AccessControlService aclService); @Override void run();  }### Answer:
@Test(expected = AccessRestrictionException.class) public void insufficientAccessTest() { doThrow(new AccessRestrictionException()).when(aclService) .assertHasAccess(anyString(), eq(pid), any(AccessGroupSet.class), eq(markForDeletion)); job.run(); }
@Test(expected = AccessRestrictionException.class) public void insufficientAccessAdminUnitTest() { when(repositoryObjectLoader.getRepositoryObject(pid)).thenReturn(repoObj); doThrow(new AccessRestrictionException()).when(aclService) .assertHasAccess(anyString(), eq(pid), any(AccessGroupSet.class), eq(markForDeletionUnit)); job.run(); }
@Test(expected = InvalidOperationForObjectType.class) public void invalidObjectTypeTest() { DepositRecord depObj = mock(DepositRecord.class); when(repositoryObjectLoader.getRepositoryObject(any(PID.class))).thenReturn(depObj); job.run(); }
@Test public void markForDeletionTest() { job.run(); verify(sparqlUpdateService).executeUpdate(anyString(), anyString()); verify(premisLogger).buildEvent(eq(Premis.Deaccession)); verify(eventBuilder, times(2)).addEventDetail(messageCaptor.capture()); List<String> details = messageCaptor.getAllValues(); assertTrue(details.contains(MESSAGE)); verify(eventBuilder).writeAndClose(); }