### Question:
FactGetByIdDelegate implements Delegate { public Fact handle(GetFactByIdRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException, ObjectNotFoundException { securityContext.checkPermission(TiFunctionConstants.viewThreatIntelFact); FactRecord record = factRequestResolver.resolveFact(request.getId()); securityContext.checkReadPermission(record); return factResponseConverter.apply(record); } @Inject  FactGetByIdDelegate(TiSecurityContext securityContext,
                             FactRequestResolver factRequestResolver,
                             FactResponseConverter factResponseConverter); Fact handle(GetFactByIdRequest request);  }### Answer:
@Test(expected = AccessDeniedException.class) public void testFetchFactWithoutViewPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.viewThreatIntelFact); delegate.handle(new GetFactByIdRequest()); }
@Test(expected = AccessDeniedException.class) public void testFetchFactNoAccess() throws Exception { UUID id = UUID.randomUUID(); FactRecord record = new FactRecord(); when(factRequestResolver.resolveFact(id)).thenReturn(record); doThrow(AccessDeniedException.class).when(securityContext).checkReadPermission(record); delegate.handle(new GetFactByIdRequest().setId(id)); }
@Test public void testFetchFact() throws Exception { UUID id = UUID.randomUUID(); FactRecord record = new FactRecord(); when(factRequestResolver.resolveFact(id)).thenReturn(record); delegate.handle(new GetFactByIdRequest().setId(id)); verify(securityContext).checkReadPermission(record); verify(factResponseConverter).apply(record); }