### Question:
FactSearchDelegate implements Delegate { public ResultSet<Fact> handle(SearchFactRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException { securityContext.checkPermission(TiFunctionConstants.viewThreatIntelFact); FactSearchCriteria criteria = requestConverter.apply(request); if (criteria.isUnbounded()) { throw new AccessDeniedException("Unbounded searches are not allowed. Specify at least one search parameter (in addition to 'limit')."); } return factSearchHandler.search(criteria, request.getIncludeRetracted()); } @Inject  FactSearchDelegate(TiSecurityContext securityContext,
                            SearchFactRequestConverter requestConverter,
                            FactSearchHandler factSearchHandler); ResultSet<Fact> handle(SearchFactRequest request);  }### Answer:
@Test public void testSearchFactsWithoutViewPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.viewThreatIntelFact); assertThrows(AccessDeniedException.class, () -> delegate.handle(new SearchFactRequest())); }
@Test public void testSearchFactsUnboundedRequest() throws Exception { when(requestConverter.apply(any())).thenReturn(FactSearchCriteria.builder() .setLimit(25) .setCurrentUserID(UUID.randomUUID()) .setAvailableOrganizationID(Collections.singleton(UUID.randomUUID())) .build()); assertThrows(AccessDeniedException.class, () -> delegate.handle(new SearchFactRequest())); }
@Test public void testSearchFacts() throws Exception { ResultSet<Fact> result = delegate.handle(new SearchFactRequest().setIncludeRetracted(true)); 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)); }