### Question:
LocalProperty extends ReadableProperty { @Override public Vertex save(Graph graph, String clientPropertyName) { Vertex propertyVertex = super.save(graph, clientPropertyName); propertyVertex.property(DATABASE_PROPERTY_NAME, propName); if (converter instanceof HasOptions) { try { propertyVertex.property(OPTIONS_PROPERTY_NAME, new ObjectMapper().writeValueAsString(((HasOptions) converter).getOptions())); } catch (JsonProcessingException e) { LOG.error("Failed to write options to database for property {}", propName); } } return propertyVertex; } LocalProperty(String propName, Converter converter); String getDatabasePropertyName(); Optional<Collection<String>> getOptions(); Optional<Collection<String>> getParts(); void setJson(Vertex vertex, JsonNode value); void setValue(Vertex vertex, Object value); @Override String getTypeId(); @Override String getUniqueTypeId(); @Override Vertex save(Graph graph, String clientPropertyName); static final String DATABASE_PROPERTY_NAME; static final String OPTIONS_PROPERTY_NAME; }### Answer:
@Test public void saveCreatesANewVertexWithCorrectLabelAndProperties() { final String propertyName = "testProp"; final String propertyType = "type"; final String clientPropName = "clientPropName"; Converter converter = mock(Converter.class); given(converter.getUniqueTypeIdentifier()).willReturn(propertyType); LocalProperty property = new LocalProperty(propertyName, converter); Vertex result = property.save(graph, clientPropName); assertThat(result, likeVertex() .withLabel(DATABASE_LABEL) .withProperty(DATABASE_PROPERTY_NAME, propertyName) .withProperty(CLIENT_PROPERTY_NAME, clientPropName) .withProperty(PROPERTY_TYPE_NAME, propertyType) ); }
@Test public void saveSetsOptionsPropertyWhenTheConverterHasOptions() throws JsonProcessingException { final String propertyName = "testProp"; final String clientPropName = "clientPropName"; final String[] options = { "val1", "val2" }; Converter converter = new StringArrayToEncodedArrayOfLimitedValues(options); LocalProperty property = new LocalProperty(propertyName, converter); Vertex result = property.save(graph, clientPropName); assertThat(result, likeVertex() .withProperty(OPTIONS_PROPERTY_NAME, new ObjectMapper().writeValueAsString(options)) .withProperty(PROPERTY_TYPE_NAME, converter.getUniqueTypeIdentifier()) ); }