3636import org .springframework .data .geo .Point ;
3737import org .springframework .data .geo .Polygon ;
3838import org .springframework .data .mongodb .core .MongoOperations ;
39+ import org .springframework .data .mongodb .core .geo .GeoJsonPolygon ;
3940import org .springframework .data .mongodb .core .geo .Sphere ;
4041import org .springframework .data .mongodb .repository .ReadPreference ;
4142import org .springframework .data .repository .Repository ;
5354 */
5455public class QueryMethodContributionUnitTests {
5556
56- @ Test
57+ @ Test // GH-5004
5758 void rendersQueryForNearUsingPoint () throws NoSuchMethodException {
5859
5960 MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesNear" , Point .class );
@@ -64,7 +65,7 @@ void rendersQueryForNearUsingPoint() throws NoSuchMethodException {
6465 .contains ("return finder.matching(filterQuery).all()" );
6566 }
6667
67- @ Test
68+ @ Test // GH-5004
6869 void rendersQueryForWithinUsingCircle () throws NoSuchMethodException {
6970
7071 MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesWithin" , Circle .class );
@@ -76,7 +77,7 @@ void rendersQueryForWithinUsingCircle() throws NoSuchMethodException {
7677 .contains ("return finder.matching(filterQuery).all()" );
7778 }
7879
79- @ Test
80+ @ Test // GH-5004
8081 void rendersQueryForWithinUsingSphere () throws NoSuchMethodException {
8182
8283 MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesWithin" , Sphere .class );
@@ -88,7 +89,7 @@ void rendersQueryForWithinUsingSphere() throws NoSuchMethodException {
8889 .contains ("return finder.matching(filterQuery).all()" );
8990 }
9091
91- @ Test
92+ @ Test // GH-5004
9293 void rendersQueryForWithinUsingBox () throws NoSuchMethodException {
9394
9495 MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesWithin" , Box .class );
@@ -100,7 +101,7 @@ void rendersQueryForWithinUsingBox() throws NoSuchMethodException {
100101 .contains ("return finder.matching(filterQuery).all()" );
101102 }
102103
103- @ Test
104+ @ Test // GH-5004
104105 void rendersQueryForWithinUsingPolygon () throws NoSuchMethodException {
105106
106107 MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesWithin" , Polygon .class );
@@ -112,7 +113,18 @@ void rendersQueryForWithinUsingPolygon() throws NoSuchMethodException {
112113 .contains ("return finder.matching(filterQuery).all()" );
113114 }
114115
115- @ Test
116+ @ Test // GH-5004
117+ void rendersQueryForWithinUsingGeoJsonPolygon () throws NoSuchMethodException {
118+
119+ MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesWithin" , GeoJsonPolygon .class );
120+
121+ assertThat (methodSpec .toString ()) //
122+ .contains ("{'location.coordinates':{'$geoWithin':{'$geometry':?0}}" ) //
123+ .contains ("Object[]{ polygon }" ) //
124+ .contains ("return finder.matching(filterQuery).all()" );
125+ }
126+
127+ @ Test // GH-5004
116128 void rendersNearQueryForGeoResults () throws NoSuchMethodException {
117129
118130 MethodSpec methodSpec = codeOf (UserRepoWithMeta .class , "findByLocationCoordinatesNear" , Point .class ,
@@ -127,23 +139,22 @@ void rendersNearQueryForGeoResults() throws NoSuchMethodException {
127139 .contains ("return nearFinder.all()" );
128140 }
129141
130- @ Test
142+ @ Test // GH-5004
131143 void rendersNearQueryWithDistanceRangeForGeoResults () throws NoSuchMethodException {
132144
133- MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesNear" , Point .class ,
134- Range .class );
145+ MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesNear" , Point .class , Range .class );
135146
136147 assertThat (methodSpec .toString ()) //
137- .contains ("NearQuery.near(point)" ) //
138- .contains ("if(distance.getLowerBound().isBounded())" ) //
139- .contains ("nearQuery.minDistance(min).in(min.getMetric())" ) //
140- .contains ("if(distance.getUpperBound().isBounded())" ) //
141- .contains ("nearQuery.maxDistance(max).in(max.getMetric())" ) //
142- .contains (".near(nearQuery)" ) //
143- .contains ("return nearFinder.all()" );
148+ .contains ("NearQuery.near(point)" ) //
149+ .contains ("if(distance.getLowerBound().isBounded())" ) //
150+ .contains ("nearQuery.minDistance(min).in(min.getMetric())" ) //
151+ .contains ("if(distance.getUpperBound().isBounded())" ) //
152+ .contains ("nearQuery.maxDistance(max).in(max.getMetric())" ) //
153+ .contains (".near(nearQuery)" ) //
154+ .contains ("return nearFinder.all()" );
144155 }
145156
146- @ Test
157+ @ Test // GH-5004
147158 void rendersNearQueryReturningGeoPage () throws NoSuchMethodException {
148159
149160 MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesNear" , Point .class , Distance .class ,
@@ -158,7 +169,7 @@ void rendersNearQueryReturningGeoPage() throws NoSuchMethodException {
158169 .contains ("GeoPage<>(geoResult, pageable, resultPage.getTotalElements())" );
159170 }
160171
161- @ Test
172+ @ Test // GH-5004
162173 void rendersNearQueryWithFilterForGeoResults () throws NoSuchMethodException {
163174
164175 MethodSpec methodSpec = codeOf (UserRepository .class , "findByLocationCoordinatesNearAndLastname" , Point .class ,
0 commit comments