test(2048): test case to show how single expression operation results in unexpected result
*/
package com.querydsl.collections;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
-import org.junit.Test;
-
-import com.querydsl.core.*;
-import com.querydsl.core.types.*;
+import com.querydsl.core.Fetchable;
+import com.querydsl.core.Module;
+import com.querydsl.core.QueryExecution;
+import com.querydsl.core.Target;
+import com.querydsl.core.Tuple;
+import com.querydsl.core.types.ArrayConstructorExpression;
+import com.querydsl.core.types.Concatenation;
+import com.querydsl.core.types.Expression;
+import com.querydsl.core.types.ParamNotSetException;
+import com.querydsl.core.types.Predicate;
+import com.querydsl.core.types.Projections;
+import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.Param;
+import org.junit.Test;
public class CollQueryStandardTest {
@@ -80,7 +92,7 @@ public class CollQueryStandardTest {
}
@Test
- public void tupleProjection() {
+ public void tupleMultipleFieldsProjection() {
List<Tuple> tuples = CollQueryFactory.from(cat, data)
.select(cat.name, cat.birthdate).fetch();
for (Tuple tuple : tuples) {
@@ -89,6 +101,27 @@ public class CollQueryStandardTest {
}
}
+ @Test
+ public void tupleOneFieldProjection() {
+ List<Tuple> tuples = CollQueryFactory.from(cat, data)
+ .select(new Expression<?>[] {cat.name}).fetch();
+ for (Tuple tuple : tuples) {
+ assertEquals(1, tuple.size());
+ assertNotNull(tuple.get(cat.name));
+ }
+ }
+
+ @Test
+ public void tupleOneNullFieldProjection() {
+ List<Tuple> tuples = CollQueryFactory.from(cat, data)
+ .select(new Expression<?>[] {Expressions.nullExpression()}).fetch();
+ for (Tuple tuple : tuples) {
+ assertNotNull(tuple);
+ assertEquals(1, tuple.size()); // THIS FAILS WITH NPE
+ assertNull(tuple.get(Expressions.nullExpression()));
+ }
+ }
+
@Test
public void nested_tupleProjection() {
Concatenation concat = new Concatenation(cat.name, cat.name);
