DATACMNS-1342 - TypeInformation.isCollectionLike() considers Streamable now.

This commit is contained in:
Oliver Gierke
2018-06-14 12:18:41 +02:00
parent 37ab0a5d8f
commit d570f4d79e
2 changed files with 27 additions and 2 deletions

View File

@@ -366,7 +366,10 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
Class<?> rawType = getType();
return rawType.isArray() || Iterable.class.equals(rawType) || Collection.class.isAssignableFrom(rawType);
return rawType.isArray() //
|| Iterable.class.equals(rawType) //
|| Collection.class.isAssignableFrom(rawType) //
|| Streamable.class.equals(rawType);
}
/*

View File

@@ -16,13 +16,14 @@
package org.springframework.data.util;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.util.ClassTypeInformation.*;
import static org.springframework.data.util.ClassTypeInformation.from;
import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -158,6 +159,15 @@ public class TypeDiscovererUnitTests {
});
}
@Test // DATACMNS-1342
public void considersStreamableToBeCollectionLike() {
TypeInformation<SomeStreamable> type = from(SomeStreamable.class);
assertThat(type.isCollectionLike()).isFalse();
assertThat(type.getRequiredProperty("streamable").isCollectionLike()).isTrue();
}
class Person {
Addresses addresses;
@@ -195,4 +205,16 @@ public class TypeDiscovererUnitTests {
}
}
// DATACMNS-1342
static class SomeStreamable implements Streamable<String> {
Streamable<String> streamable;
@Override
public Iterator<String> iterator() {
return Collections.emptyIterator();
}
}
}