### Question:
PropertyMapping { public static PropertyMapping fromObject(String propertyKey, Object stringOrMap) { if (stringOrMap instanceof String) { String neoPropertyKey = (String) stringOrMap; return fromObject( propertyKey, Collections.singletonMap( PROPERTY_KEY, neoPropertyKey ) ); } else if (stringOrMap instanceof Map) { Map<String, Object> relPropertyMap = (Map) stringOrMap; Object propertyNameValue = relPropertyMap.getOrDefault(PROPERTY_KEY, propertyKey); if (!(propertyNameValue instanceof String)) { throw new IllegalArgumentException(formatWithLocale( "Expected the value of '%s' to be of type String, but was '%s'.", PROPERTY_KEY, propertyNameValue.getClass().getSimpleName() )); } String neoPropertyKey = (String) propertyNameValue; final Object aggregationValue = relPropertyMap.get(RelationshipProjection.AGGREGATION_KEY); Aggregation aggregation; if (aggregationValue == null) { aggregation = Aggregation.DEFAULT; } else if (aggregationValue instanceof String) { aggregation = Aggregation.lookup(((String) aggregationValue).toUpperCase(Locale.ENGLISH)); } else { throw new IllegalStateException(formatWithLocale( "Expected the value of '%s' to be of type String, but was '%s'", RelationshipProjection.AGGREGATION_KEY, aggregationValue.getClass().getSimpleName() )); } return PropertyMapping.of( propertyKey, neoPropertyKey, relPropertyMap.get(DEFAULT_VALUE_KEY), aggregation ); } else { throw new IllegalStateException(formatWithLocale( "Expected stringOrMap to be of type String or Map, but got %s", stringOrMap.getClass().getSimpleName() )); } }  abstract @Nullable String propertyKey(); @Value.Default @Nullable String neoPropertyKey(); @Value.Default DefaultValue defaultValue(); @Value.Default Aggregation aggregation(); @Value.Check void validateProperties(); static PropertyMapping fromObject(String propertyKey, Object stringOrMap); boolean hasValidName(); boolean exists(); Map.Entry<String, Object> toObject(boolean includeAggregation); PropertyMapping setNonDefaultAggregation(Aggregation aggregation); static PropertyMapping of(String propertyKey); static PropertyMapping of(String neoPropertyKey, Object defaultValue); static PropertyMapping of(String propertyKey, String neoPropertyKey, Object defaultValue); static PropertyMapping of(
        String propertyKey,
        Object defaultValue,
        Aggregation aggregation
    ); static PropertyMapping of(
        String propertyKey,
        Aggregation aggregation
    ); static PropertyMapping of(
        String propertyKey,
        String neoPropertyKey,
        Aggregation aggregation
    ); static PropertyMapping of(
        String propertyKey,
        String neoPropertyKey,
        Object defaultValue,
        Aggregation aggregation
    ); static final String PROPERTY_KEY; static final String DEFAULT_VALUE_KEY; }### Answer:
@Test void failsOnWrongKeyType() { IllegalArgumentException ex = assertThrows( IllegalArgumentException.class, () -> PropertyMapping.fromObject("transaction_count", MapUtil.map( "property", 42 ))); assertThat(ex.getMessage(), containsString("Expected the value of 'property' to be of type String, but was 'Integer'.")); }