### Question:
ObjectTypeGetByIdDelegate implements Delegate { public ObjectType handle(GetObjectTypeByIdRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException, ObjectNotFoundException { securityContext.checkPermission(TiFunctionConstants.viewThreatIntelType); return objectTypeResponseConverter.apply(objectTypeRequestResolver.fetchExistingObjectType(request.getId())); } @Inject  ObjectTypeGetByIdDelegate(TiSecurityContext securityContext,
                                   ObjectTypeResponseConverter objectTypeResponseConverter,
                                   ObjectTypeRequestResolver objectTypeRequestResolver); ObjectType handle(GetObjectTypeByIdRequest request);  }### Answer:
@Test(expected = AccessDeniedException.class) public void testFetchObjectTypeWithoutPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.viewThreatIntelType); delegate.handle(new GetObjectTypeByIdRequest()); }
@Test(expected = ObjectNotFoundException.class) public void testFetchObjectTypeNotFound() throws Exception { UUID id = UUID.randomUUID(); when(objectTypeRequestResolver.fetchExistingObjectType(id)).thenThrow(ObjectNotFoundException.class); delegate.handle(new GetObjectTypeByIdRequest().setId(id)); }
@Test public void testFetchObjectType() throws Exception { UUID id = UUID.randomUUID(); ObjectTypeEntity entity = new ObjectTypeEntity(); when(objectTypeRequestResolver.fetchExistingObjectType(id)).thenReturn(entity); delegate.handle(new GetObjectTypeByIdRequest().setId(id)); verify(objectTypeResponseConverter).apply(entity); }