Skip to content

Commit

Permalink
DATACMNS-444 - DefaultPersistentPropertyPath now skips null converted…
Browse files Browse the repository at this point in the history
… names.

If a Converter handed into DefaultPersistentPropertyPath.toDotPath(…) returns null or an empty string for a mapped property name, that value is skipped during path construction.
  • Loading branch information
odrotbohm committed Feb 19, 2014
1 parent f089acb commit 4cee676
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
Expand Up @@ -93,10 +93,15 @@ public String toPath(String delimiter, Converter<? super T, String> converter) {
List<String> result = new ArrayList<String>();

for (T property : properties) {
result.add(converterToUse.convert(property));

String convert = converterToUse.convert(property);

if (StringUtils.hasText(convert)) {
result.add(convert);
}
}

return StringUtils.collectionToDelimitedString(result, delimiterToUse);
return result.isEmpty() ? null : StringUtils.collectionToDelimitedString(result, delimiterToUse);
}

/*
Expand Down
Expand Up @@ -38,11 +38,9 @@
@RunWith(MockitoJUnitRunner.class)
public class DefaultPersistenPropertyPathUnitTests<T extends PersistentProperty<T>> {

@Mock
T first, second;
@Mock T first, second;

@Mock
Converter<T, String> converter;
@Mock Converter<T, String> converter;

PersistentPropertyPath<T> oneLeg;
PersistentPropertyPath<T> twoLegs;
Expand Down Expand Up @@ -121,4 +119,39 @@ public void pathReturnsCorrectSize() {
assertThat(oneLeg.getLength(), is(1));
assertThat(twoLegs.getLength(), is(2));
}

/**
* @see DATACMNS-444
*/
@Test
public void skipsMappedPropertyNameIfConverterReturnsNull() {

String result = twoLegs.toDotPath(new Converter<T, String>() {

@Override
public String convert(T source) {
return null;
}
});

assertThat(result, is(nullValue()));
}

/**
* @see DATACMNS-444
*/
@Test
public void skipsMappedPropertyNameIfConverterReturnsEmptyStrings() {

String result = twoLegs.toDotPath(new Converter<T, String>() {

@Override
public String convert(T source) {
return "";
}
});

assertThat(result, is(nullValue()));
}

}

0 comments on commit 4cee676

Please sign in to comment.