AttributeModificationValidator { public static void verifyCanModify(FieldSpecification<?, ?> fieldSpec) { Objects.requireNonNull(fieldSpec); if (fieldSpec.isInferred()) { throw new InferredAttributeModifiedException( "Field " + fieldSpec + " may contain inferences and cannot be modified."); } if (fieldSpec instanceof AbstractAttribute && ((AbstractAttribute) fieldSpec).isLexicalForm()) { throw new AttributeModificationForbiddenException("Field " + fieldSpec + " is configured to contain lexical form of literals and cannot be modified."); } } private  AttributeModificationValidator(); static void verifyCanModify(FieldSpecification<?, ?> fieldSpec);  }
@Test void verifyCanModifyThrowsInferredAttributeModifiedExceptionWhenInferredAttributeIsModified() { final FieldSpecification<?, ?> fs = mock(FieldSpecification.class); when(fs.isInferred()).thenReturn(true); assertThrows(InferredAttributeModifiedException.class, () -> AttributeModificationValidator.verifyCanModify(fs)); }
@Test void verifyCanModifyThrowsAttributeModificationForbiddenWhenLexicalFormAttributeValueIsModified() { final AbstractAttribute<?, ?> att = mock(AbstractAttribute.class); when(att.isLexicalForm()).thenReturn(true); assertThrows(AttributeModificationForbiddenException.class, () -> AttributeModificationValidator.verifyCanModify(att)); }
@Test void verifyCanModifyAllowsModificationToRegularFields() { final FieldSpecification<?, ?> fs = mock(FieldSpecification.class); assertDoesNotThrow(() -> AttributeModificationValidator.verifyCanModify(fs)); }