DATACMNS-1578 - Polishing.
This commit is contained in:
@@ -37,10 +37,8 @@ import com.querydsl.core.types.dsl.SimpleExpression;
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
* @since 1.11
|
||||
*
|
||||
* @author Colin Gao
|
||||
* @since 2.1
|
||||
* @since 1.11
|
||||
*/
|
||||
class QuerydslDefaultBinding implements MultiValueBinding<Path<? extends Object>, Object> {
|
||||
|
||||
@@ -72,16 +70,17 @@ class QuerydslDefaultBinding implements MultiValueBinding<Path<? extends Object>
|
||||
|
||||
if (path instanceof SimpleExpression) {
|
||||
|
||||
SimpleExpression expression = (SimpleExpression) path;
|
||||
|
||||
if (value.size() > 1) {
|
||||
return Optional.of(((SimpleExpression) path).in(value));
|
||||
return Optional.of(expression.in(value));
|
||||
}
|
||||
|
||||
Object object = value.iterator().next();
|
||||
if (object == null) {
|
||||
return Optional.of(((SimpleExpression) path).isNull());
|
||||
}
|
||||
|
||||
return Optional.of(((SimpleExpression) path).eq(object));
|
||||
|
||||
return Optional.of(object == null //
|
||||
? expression.isNull() //
|
||||
: expression.eq(object));
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(
|
||||
|
||||
@@ -54,7 +54,8 @@ public class QuerydslDefaultBindingUnitTests {
|
||||
|
||||
Optional<Predicate> predicate = binding.bind(QUser.user.address.city, Collections.singleton("two rivers"));
|
||||
|
||||
assertThat(predicate).hasValueSatisfying(it -> assertThat(it.toString()).isEqualTo(QUser.user.address.city.eq("two rivers").toString()));
|
||||
assertThat(predicate).hasValueSatisfying(
|
||||
it -> assertThat(it.toString()).isEqualTo(QUser.user.address.city.eq("two rivers").toString()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@@ -78,9 +79,13 @@ public class QuerydslDefaultBindingUnitTests {
|
||||
assertThat(binding.bind(QUser.user.lastname, Collections.emptySet())).isNotPresent();
|
||||
}
|
||||
|
||||
@Test //DATACMNS-1578
|
||||
public void shouldCreatePredicateWithIsNullWhenPropertyIsAnNestedObjectAndValueIsNull() {
|
||||
@Test // DATACMNS-1578
|
||||
public void shouldCreatePredicateWithIsNullWhenPropertyIsANestedObjectAndValueIsNull() {
|
||||
|
||||
Optional<Predicate> predicate = binding.bind(QUser.user.address.city, Collections.singleton(null));
|
||||
assertThat(predicate).hasValueSatisfying(it -> assertThat(it.toString()).isEqualTo(QUser.user.address.city.isNull().toString()));
|
||||
|
||||
assertThat(predicate).hasValueSatisfying(it -> {
|
||||
assertThat(it.toString()).isEqualTo(QUser.user.address.city.isNull().toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user