### Question:
FactSearchMetaDelegate implements Delegate { public ResultSet<Fact> handle(SearchMetaFactsRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException, ObjectNotFoundException { securityContext.checkPermission(TiFunctionConstants.viewThreatIntelFact); securityContext.checkReadPermission(factRequestResolver.resolveFact(request.getFact())); return factSearchHandler.search(requestConverter.apply(request), request.getIncludeRetracted()); } @Inject  FactSearchMetaDelegate(TiSecurityContext securityContext,
                                SearchMetaFactsRequestConverter requestConverter,
                                FactRequestResolver factRequestResolver,
                                FactSearchHandler factSearchHandler); ResultSet<Fact> handle(SearchMetaFactsRequest request);  }### Answer:
@Test(expected = AccessDeniedException.class) public void testSearchMetaFactsWithoutViewPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.viewThreatIntelFact); delegate.handle(new SearchMetaFactsRequest()); }
@Test(expected = AccessDeniedException.class) public void testSearchMetaFactsNoAccessToFact() throws Exception { SearchMetaFactsRequest request = new SearchMetaFactsRequest().setFact(UUID.randomUUID()); when(factRequestResolver.resolveFact(request.getFact())).thenReturn(new FactRecord()); doThrow(AccessDeniedException.class).when(securityContext).checkReadPermission(isA(FactRecord.class)); delegate.handle(request); }
@Test public void testSearchMetaFacts() throws Exception { SearchMetaFactsRequest request = new SearchMetaFactsRequest().setFact(UUID.randomUUID()).setIncludeRetracted(true); mockSearchMetaFacts(); ResultSet<Fact> result = delegate.handle(request); assertEquals(25, result.getLimit()); assertEquals(100, result.getCount()); assertEquals(1, ListUtils.list(result.iterator()).size()); verify(requestConverter).apply(isNotNull()); verify(factSearchHandler).search(isNotNull(), eq(true)); verify(securityContext).checkReadPermission(isA(FactRecord.class)); }