@ -30,6 +30,7 @@ import org.junit.rules.ExpectedException;
@@ -30,6 +30,7 @@ import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith ;
import org.mockito.Mock ;
import org.mockito.runners.MockitoJUnitRunner ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.data.mongodb.MongoDbFactory ;
import org.springframework.data.mongodb.core.MongoOperations ;
import org.springframework.data.mongodb.core.convert.DbRefResolver ;
@ -206,6 +207,14 @@ public class PartTreeMongoQueryUnitTests {
@@ -206,6 +207,14 @@ public class PartTreeMongoQueryUnitTests {
assertThat ( query . getFieldsObject ( ) . get ( "firstname" ) , is ( ( Object ) 1 ) ) ;
}
@Test // DATAMONGO-1729
public void doesNotCreateFieldsObjectForOpenProjection ( ) {
org . springframework . data . mongodb . core . query . Query query = deriveQueryFromMethod ( "findAllBy" ) ;
assertThat ( query . getFieldsObject ( ) , is ( nullValue ( ) ) ) ;
}
private org . springframework . data . mongodb . core . query . Query deriveQueryFromMethod ( String method , Object . . . args ) {
Class < ? > [ ] types = new Class < ? > [ args . length ] ;
@ -266,6 +275,8 @@ public class PartTreeMongoQueryUnitTests {
@@ -266,6 +275,8 @@ public class PartTreeMongoQueryUnitTests {
@Query ( fields = "{ 'firstname' : 1 }" )
List < Person > findBySex ( Sex sex ) ;
OpenProjection findAllBy ( ) ;
}
interface PersonProjection {
@ -290,4 +301,12 @@ public class PartTreeMongoQueryUnitTests {
@@ -290,4 +301,12 @@ public class PartTreeMongoQueryUnitTests {
this . lastname = lastname ;
}
}
interface OpenProjection {
String getFirstname ( ) ;
@Value ( "#{target.firstname + ' ' + target.lastname}" )
String getFullname ( ) ;
}
}