### Question:
LocalPropertyDescriptor implements PropertyDescriptor { @Override public String get(Vertex vertex) { if (vertex.keys().contains(propertyName)) { String value = parser.parse(vertex.value(propertyName)); if (value != null) { return String.format("%s%s%s", prefix, value, postfix); } } return null; } LocalPropertyDescriptor(String propertyName, PropertyParser parser);  LocalPropertyDescriptor(String propertyName, PropertyParser parser, String prefix, String postfix); @Override String get(Vertex vertex); static final String DEFAULT_PREFIX; static final String DEFAULT_POSTFIX; }### Answer:
@Test public void getReturnsNullIfTheVertexDoesNotContainTheProperty() { LocalPropertyDescriptor instance = new LocalPropertyDescriptor("property", mock(PropertyParser.class)); String value = instance.get(vertex().build()); assertThat(value, is(nullValue())); }
@Test public void getReturnsValueFromParserParseIfTheVertexDoesContainTheProperty() { String propertyName = "propName"; String expectedValue = "a string"; PropertyParser parser = mock(PropertyParser.class); given(parser.parse(anyString())).willReturn(expectedValue); Vertex vertex = vertex().withProperty(propertyName, "a string 2").build(); LocalPropertyDescriptor instance = new LocalPropertyDescriptor(propertyName, parser); String value = instance.get(vertex); assertThat(value, is(equalTo(expectedValue))); verify(parser).parse(anyString()); }
@Test public void getReturnsTheValueWithAPrefixAndAPostfixIfTheyAreConfigured() { String propertyName = "propName"; String expectedValue = "a string"; String prefix = "["; String postfix = "]"; PropertyParser parser = mock(PropertyParser.class); given(parser.parse(anyString())).willReturn(expectedValue); Vertex vertex = vertex().withProperty(propertyName, "a string 2").build(); LocalPropertyDescriptor instance = new LocalPropertyDescriptor(propertyName, parser, prefix, postfix); String value = instance.get(vertex); assertThat(value, allOf(startsWith(prefix), endsWith(postfix))); verify(parser).parse(anyString()); }
@Test public void getReturnsNullIfTheParserReturnsNull() { String propertyName = "propName"; String prefix = "["; String postfix = "]"; PropertyParser parser = mock(PropertyParser.class); given(parser.parse(anyString())).willReturn(null); Vertex vertex = vertex().withProperty(propertyName, "a string 2").build(); LocalPropertyDescriptor instance = new LocalPropertyDescriptor(propertyName, parser, prefix, postfix); String value = instance.get(vertex); assertThat(value, is(nullValue())); }