### Question:
ObjectTypeUpdateDelegate implements Delegate { public ObjectType handle(UpdateObjectTypeRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException, ObjectNotFoundException { securityContext.checkPermission(TiFunctionConstants.updateThreatIntelType); ObjectTypeEntity entity = objectTypeRequestResolver.fetchExistingObjectType(request.getId()); if (!StringUtils.isBlank(request.getName())) { objectTypeHandler.assertObjectTypeNotExists(request.getName()); entity.setName(request.getName()); } entity = objectManager.saveObjectType(entity); return objectTypeResponseConverter.apply(entity); } @Inject  ObjectTypeUpdateDelegate(TiSecurityContext securityContext,
                                  ObjectManager objectManager,
                                  ObjectTypeResponseConverter objectTypeResponseConverter,
                                  ObjectTypeRequestResolver objectTypeRequestResolver,
                                  ObjectTypeHandler objectTypeHandler); ObjectType handle(UpdateObjectTypeRequest request);  }### Answer:
@Test(expected = AccessDeniedException.class) public void testUpdateObjectTypeWithoutPermission() throws Exception { doThrow(AccessDeniedException.class).when(securityContext).checkPermission(TiFunctionConstants.updateThreatIntelType); delegate.handle(createRequest()); }
@Test(expected = ObjectNotFoundException.class) public void testUpdateObjectTypeNotExisting() throws Exception { UpdateObjectTypeRequest request = createRequest(); when(objectTypeRequestResolver.fetchExistingObjectType(request.getId())).thenThrow(ObjectNotFoundException.class); delegate.handle(request); }
@Test(expected = InvalidArgumentException.class) public void testUpdateObjectTypeWithExistingName() throws Exception { UpdateObjectTypeRequest request = createRequest(); when(objectManager.getObjectType(request.getId())).thenReturn(new ObjectTypeEntity()); doThrow(InvalidArgumentException.class).when(objectTypeHandler).assertObjectTypeNotExists(request.getName()); delegate.handle(request); }
@Test public void testUpdateObjectType() throws Exception { UpdateObjectTypeRequest request = createRequest(); ObjectTypeEntity entity = new ObjectTypeEntity(); when(objectTypeRequestResolver.fetchExistingObjectType(request.getId())).thenReturn(entity); when(objectManager.saveObjectType(argThat(e -> { assertSame(entity, e); assertEquals(request.getName(), e.getName()); return true; }))).thenReturn(entity); delegate.handle(request); verify(objectTypeResponseConverter).apply(entity); }