### Question:
OriginGetByIdDelegate implements Delegate { public Origin handle(GetOriginByIdRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException, ObjectNotFoundException { securityContext.checkPermission(TiFunctionConstants.viewThreatIntelOrigin); OriginEntity entity = originResolver.apply(request.getId()); if (entity == null) { throw new ObjectNotFoundException(String.format("Origin with id = %s does not exist.", request.getId()), "origin.not.exist", "id", request.getId().toString()); } securityContext.checkReadPermission(entity); return originResponseConverter.apply(entity); } @Inject  OriginGetByIdDelegate(TiSecurityContext securityContext,
                               OriginResolver originResolver,
                               OriginResponseConverter originResponseConverter); Origin handle(GetOriginByIdRequest request);  }### Answer:
@Test(expected = ObjectNotFoundException.class) public void testFetchOriginNotFound() throws Exception { delegate.handle(new GetOriginByIdRequest().setId(UUID.randomUUID())); }
@Test(expected = AccessDeniedException.class) public void testFetchOriginWithoutGeneralViewPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.viewThreatIntelOrigin); delegate.handle(new GetOriginByIdRequest().setId(UUID.randomUUID())); }
@Test(expected = AccessDeniedException.class) public void testFetchOriginWithoutSpecificViewPermission() throws Exception { OriginEntity origin = new OriginEntity() .setId(UUID.randomUUID()) .setOrganizationID(UUID.randomUUID()); when(originResolver.apply(origin.getId())).thenReturn(origin); doThrow(AccessDeniedException.class).when(securityContext).checkReadPermission(origin); delegate.handle(new GetOriginByIdRequest().setId(origin.getId())); }
@Test public void testFetchOrigin() throws Exception { OriginEntity origin = new OriginEntity() .setId(UUID.randomUUID()) .setOrganizationID(UUID.randomUUID()); when(originResolver.apply(origin.getId())).thenReturn(origin); delegate.handle(new GetOriginByIdRequest().setId(origin.getId())); verify(originResolver).apply(origin.getId()); verify(originResponseConverter).apply(origin); verify(securityContext).checkPermission(TiFunctionConstants.viewThreatIntelOrigin); verify(securityContext).checkReadPermission(origin); }