### Question:
ObjectTypeCreateDelegate implements Delegate { public ObjectType handle(CreateObjectTypeRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException { securityContext.checkPermission(TiFunctionConstants.addThreatIntelType); objectTypeHandler.assertObjectTypeNotExists(request.getName()); validatorHandler.assertValidatorExists(request.getValidator(), request.getValidatorParameter()); ObjectTypeEntity entity = new ObjectTypeEntity() .setId(UUID.randomUUID()) .setNamespaceID(GLOBAL_NAMESPACE) .setName(request.getName()) .setValidator(request.getValidator()) .setValidatorParameter(request.getValidatorParameter()); entity = objectManager.saveObjectType(entity); return objectTypeResponseConverter.apply(entity); } @Inject  ObjectTypeCreateDelegate(TiSecurityContext securityContext,
                                  ObjectManager objectManager,
                                  ObjectTypeResponseConverter objectTypeResponseConverter,
                                  ObjectTypeHandler objectTypeHandler,
                                  ValidatorHandler validatorHandler); ObjectType handle(CreateObjectTypeRequest request);  }### Answer:
@Test(expected = AccessDeniedException.class) public void testCreateObjectTypeWithoutPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.addThreatIntelType); delegate.handle(createRequest()); }
@Test(expected = InvalidArgumentException.class) public void testCreateAlreadyExistingObjectType() throws Exception { CreateObjectTypeRequest request = createRequest(); doThrow(InvalidArgumentException.class).when(objectTypeHandler).assertObjectTypeNotExists(request.getName()); delegate.handle(request); }
@Test(expected = InvalidArgumentException.class) public void testCreateObjectTypeValidatorNotFound() throws Exception { CreateObjectTypeRequest request = createRequest(); doThrow(InvalidArgumentException.class).when(validatorHandler).assertValidatorExists(request.getValidator(), request.getValidatorParameter()); delegate.handle(request); }
@Test public void testCreateObjectType() throws Exception { CreateObjectTypeRequest request = createRequest(); ObjectTypeEntity newEntity = new ObjectTypeEntity(); when(objectManager.saveObjectType(any())).thenReturn(newEntity); delegate.handle(request); verify(objectTypeResponseConverter).apply(newEntity); verify(objectManager).saveObjectType(argThat(entity -> { assertNotNull(entity.getId()); assertNotNull(entity.getNamespaceID()); assertEquals(request.getName(), entity.getName()); assertEquals(request.getValidator(), entity.getValidator()); assertEquals(request.getValidatorParameter(), entity.getValidatorParameter()); return true; })); }