1515 */
1616package org .springframework .data .mongodb .core .geo ;
1717
18- import static org .assertj .core .api .Assertions .*;
19-
20- import java .io .IOException ;
21- import java .util .Arrays ;
22-
18+ import com .fasterxml .jackson .databind .ObjectMapper ;
2319import org .junit .jupiter .api .BeforeEach ;
2420import org .junit .jupiter .api .Test ;
25-
2621import org .springframework .data .geo .Point ;
2722
28- import com .fasterxml .jackson .core .JsonParseException ;
29- import com .fasterxml .jackson .databind .JsonMappingException ;
30- import com .fasterxml .jackson .databind .ObjectMapper ;
23+ import java .io .IOException ;
24+ import java .util .Arrays ;
25+
26+ import static org .assertj .core .api .Assertions .assertThat ;
3127
3228/**
3329 * @author Christoph Strobl
30+ * @author Artyom Muravlev
3431 */
35- public class GeoJsonModuleUnitTests {
32+ class GeoJsonModuleUnitTests {
3633
3734 ObjectMapper mapper ;
3835
3936 @ BeforeEach
40- public void setUp () {
37+ void setUp () {
4138
4239 mapper = new ObjectMapper ();
4340 mapper .registerModule (new GeoJsonModule ());
4441 }
4542
4643 @ Test // DATAMONGO-1181
47- public void shouldDeserializeJsonPointCorrectly () throws JsonParseException , JsonMappingException , IOException {
44+ void shouldDeserializeJsonPointCorrectly () throws IOException {
4845
4946 String json = "{ \" type\" : \" Point\" , \" coordinates\" : [10.0, 20.0] }" ;
5047
5148 assertThat (mapper .readValue (json , GeoJsonPoint .class )).isEqualTo (new GeoJsonPoint (10D , 20D ));
5249 }
5350
5451 @ Test // DATAMONGO-1181
55- public void shouldDeserializeGeoJsonLineStringCorrectly ()
56- throws JsonParseException , JsonMappingException , IOException {
52+ void shouldDeserializeGeoJsonLineStringCorrectly ()
53+ throws IOException {
5754
5855 String json = "{ \" type\" : \" LineString\" , \" coordinates\" : [ [10.0, 20.0], [30.0, 40.0], [50.0, 60.0] ]}" ;
5956
@@ -62,8 +59,8 @@ public void shouldDeserializeGeoJsonLineStringCorrectly()
6259 }
6360
6461 @ Test // DATAMONGO-1181
65- public void shouldDeserializeGeoJsonMultiPointCorrectly ()
66- throws JsonParseException , JsonMappingException , IOException {
62+ void shouldDeserializeGeoJsonMultiPointCorrectly ()
63+ throws IOException {
6764
6865 String json = "{ \" type\" : \" MultiPoint\" , \" coordinates\" : [ [10.0, 20.0], [30.0, 40.0], [50.0, 60.0] ]}" ;
6966
@@ -73,8 +70,8 @@ public void shouldDeserializeGeoJsonMultiPointCorrectly()
7370
7471 @ Test // DATAMONGO-1181
7572 @ SuppressWarnings ("unchecked" )
76- public void shouldDeserializeGeoJsonMultiLineStringCorrectly ()
77- throws JsonParseException , JsonMappingException , IOException {
73+ void shouldDeserializeGeoJsonMultiLineStringCorrectly ()
74+ throws IOException {
7875
7976 String json = "{ \" type\" : \" MultiLineString\" , \" coordinates\" : [ [ [10.0, 20.0], [30.0, 40.0] ], [ [50.0, 60.0] , [70.0, 80.0] ] ]}" ;
8077
@@ -83,7 +80,7 @@ public void shouldDeserializeGeoJsonMultiLineStringCorrectly()
8380 }
8481
8582 @ Test // DATAMONGO-1181
86- public void shouldDeserializeGeoJsonPolygonCorrectly () throws JsonParseException , JsonMappingException , IOException {
83+ void shouldDeserializeGeoJsonPolygonCorrectly () throws IOException {
8784
8885 String json = "{ \" type\" : \" Polygon\" , \" coordinates\" : [ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ]}" ;
8986
@@ -92,8 +89,8 @@ public void shouldDeserializeGeoJsonPolygonCorrectly() throws JsonParseException
9289 }
9390
9491 @ Test // DATAMONGO-1181
95- public void shouldDeserializeGeoJsonMultiPolygonCorrectly ()
96- throws JsonParseException , JsonMappingException , IOException {
92+ void shouldDeserializeGeoJsonMultiPolygonCorrectly ()
93+ throws IOException {
9794
9895 String json = "{ \" type\" : \" Polygon\" , \" coordinates\" : ["
9996 + "[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],"
@@ -110,4 +107,74 @@ public void shouldDeserializeGeoJsonMultiPolygonCorrectly()
110107 new Point (100.2 , 0.8 ), new Point (100.2 , 0.2 ))))));
111108
112109 }
110+
111+ @ Test // GH-4950
112+ void shouldSerializeJsonPointCorrectly () throws IOException {
113+
114+ String json = "{\" type\" :\" Point\" ,\" coordinates\" :[10.0,20.0]}" ;
115+
116+ assertThat (mapper .writeValueAsString (new GeoJsonPoint (10D , 20D ))).isEqualTo (json );
117+ }
118+
119+ @ Test // GH-4950
120+ void shouldSerializeGeoJsonLineStringCorrectly ()
121+ throws IOException {
122+
123+ String json = "{\" type\" :\" LineString\" ,\" coordinates\" :[[10.0,20.0],[30.0,40.0],[50.0,60.0]]}" ;
124+
125+ assertThat (mapper .writeValueAsString (new GeoJsonLineString (Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 ), new Point (50 , 60 )))))
126+ .isEqualTo (json );
127+ }
128+
129+ @ Test // GH-4950
130+ void shouldSerializeGeoJsonMultiPointCorrectly ()
131+ throws IOException {
132+
133+ String json = "{\" type\" :\" MultiPoint\" ,\" coordinates\" :[[10.0,20.0],[30.0,40.0],[50.0,60.0]]}" ;
134+
135+ assertThat (mapper .writeValueAsString (new GeoJsonMultiPoint (Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 ), new Point (50 , 60 )))))
136+ .isEqualTo (json );
137+ }
138+
139+ @ Test // GH-4950
140+ @ SuppressWarnings ("unchecked" )
141+ void shouldSerializeGeoJsonMultiLineStringCorrectly ()
142+ throws IOException {
143+
144+ String json = "{\" type\" :\" MultiLineString\" ,\" coordinates\" :[[[10.0,20.0],[30.0,40.0]],[[50.0,60.0],[70.0,80.0]]]}" ;
145+
146+ assertThat (mapper .writeValueAsString (new GeoJsonMultiLineString (
147+ Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 )), Arrays .asList (new Point (50 , 60 ), new Point (70 , 80 )))))
148+ .isEqualTo (json );
149+ }
150+
151+ @ Test // GH-4950
152+ void shouldSerializeGeoJsonPolygonCorrectly () throws IOException {
153+
154+ String json = "{\" type\" :\" Polygon\" ,\" coordinates\" :[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]}" ;
155+
156+ assertThat (mapper .writeValueAsString (new GeoJsonPolygon (
157+ Arrays .asList (new Point (100 , 0 ), new Point (101 , 0 ), new Point (101 , 1 ), new Point (100 , 1 ), new Point (100 , 0 )))))
158+ .isEqualTo (json );
159+ }
160+
161+ @ Test // GH-4950
162+ void shouldSerializeGeoJsonMultiPolygonCorrectly ()
163+ throws IOException {
164+
165+ String json ="{\" type\" :\" MultiPolygon\" ,\" coordinates\" :["
166+ +"[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]],"
167+ +"[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]],"
168+ +"[[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]" //
169+ +"]}" ;
170+
171+ assertThat (mapper .writeValueAsString (new GeoJsonMultiPolygon (Arrays .asList (
172+ new GeoJsonPolygon (Arrays .asList (new Point (102 , 2 ), new Point (103 , 2 ), new Point (103 , 3 ), new Point (102 , 3 ),
173+ new Point (102 , 2 ))),
174+ new GeoJsonPolygon (Arrays .asList (new Point (100 , 0 ), new Point (101 , 0 ), new Point (101 , 1 ), new Point (100 , 1 ),
175+ new Point (100 , 0 ))),
176+ new GeoJsonPolygon (Arrays .asList (new Point (100.2 , 0.2 ), new Point (100.8 , 0.2 ), new Point (100.8 , 0.8 ),
177+ new Point (100.2 , 0.8 ), new Point (100.2 , 0.2 ))))))).isEqualTo (json );
178+
179+ }
113180}
0 commit comments