### Question:
ObjectSearchFactsDelegate implements Delegate { public ResultSet<Fact> handle(SearchObjectFactsRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException { securityContext.checkPermission(TiFunctionConstants.viewThreatIntelFact); assertRequest(request); ObjectRecord object = resolveObject(request); securityContext.checkReadPermission(object); return factSearchHandler.search(toCriteria(request, object), request.getIncludeRetracted()); } @Inject  ObjectSearchFactsDelegate(TiSecurityContext securityContext,
                                   ObjectFactDao objectFactDao,
                                   SearchObjectFactsRequestConverter requestConverter,
                                   FactSearchHandler factSearchHandler,
                                   ObjectTypeHandler objectTypeHandler); ResultSet<Fact> handle(SearchObjectFactsRequest request);  }### Answer:
@Test(expected = AccessDeniedException.class) public void testSearchObjectFactsWithoutViewPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.viewThreatIntelFact); delegate.handle(new SearchObjectFactsRequest()); }
@Test(expected = IllegalArgumentException.class) public void testSearchObjectFactsWithoutSpecifiedObject() throws Exception { delegate.handle(new SearchObjectFactsRequest()); }
@Test(expected = InvalidArgumentException.class) public void testSearchObjectFactsWithNonExistingObjectType() throws Exception { SearchObjectFactsRequest request = new SearchObjectFactsRequest().setObjectType("type").setObjectValue("value"); doThrow(InvalidArgumentException.class).when(objectTypeHandler).assertObjectTypeExists(request.getObjectType(), "objectType"); delegate.handle(request); }
@Test public void testSearchObjectFactsByNonExistingId() throws Exception { SearchObjectFactsRequest request = new SearchObjectFactsRequest().setObjectID(UUID.randomUUID()); doThrow(AccessDeniedException.class).when(securityContext).checkReadPermission((ObjectRecord) isNull()); try { delegate.handle(request); fail(); } catch (AccessDeniedException ignored) { verify(objectFactDao).getObject(request.getObjectID()); } }
@Test public void testSearchObjectFactsByNonExistingTypeValue() throws Exception { SearchObjectFactsRequest request = new SearchObjectFactsRequest().setObjectType("type").setObjectValue("value"); doThrow(AccessDeniedException.class).when(securityContext).checkReadPermission((ObjectRecord) isNull()); try { delegate.handle(request); fail(); } catch (AccessDeniedException ignored) { verify(objectTypeHandler).assertObjectTypeExists(request.getObjectType(), "objectType"); verify(objectFactDao).getObject(request.getObjectType(), request.getObjectValue()); } }