FieldMappingValidator { void validatePropertiesField(Field field) { assert field != null; if (!Map.class.isAssignableFrom(field.getType())) { throw new InvalidFieldMappingException( "Expected @Properties field to be a map, but it is a " + field.getType()); } if (isRawType(field.getGenericType())) { throw new InvalidFieldMappingException("@Properties field cannot be a raw map."); } final PropertiesParametersResolver parametersResolver = new PropertiesParametersResolver(field); if (!isValidIdentifierType(parametersResolver.getKeyType())) { throw new InvalidFieldMappingException( "@Properties key type is not a valid identifier type. Expected one of " + SUPPORTED_IDENTIFIER_TYPES); } validatePropertiesValueType(parametersResolver.getValueType()); }    }
@Test void nonMapPropertiesFieldThrowsException() { assertThrows(InvalidFieldMappingException.class, () -> validator.validatePropertiesField(getField("values"))); }
@Test void rawPropertiesMapThrowsException() { assertThrows(InvalidFieldMappingException.class, () -> validator.validatePropertiesField(getField("rawProperties"))); }
@Test void propertiesFieldRequiresValueTypeToBeSet() { assertThrows(InvalidFieldMappingException.class, () -> validator.validatePropertiesField(getField("propertiesWithIntegerValue"))); }
@Test void propertiesFieldWithInvalidKeyTypeThrowsException() { assertThrows(InvalidFieldMappingException.class, () -> validator.validatePropertiesField(getField("propertiesWithInvalidKey"))); }
@Test void validPropertiesFieldPassesValidation() throws Exception { validator.validatePropertiesField(getField("validProperties")); }