2525
2626import org .springframework .data .geo .Point ;
2727
28- import com .fasterxml .jackson .core .JsonParseException ;
29- import com .fasterxml .jackson .databind .JsonMappingException ;
3028import com .fasterxml .jackson .databind .ObjectMapper ;
3129
3230/**
3331 * @author Christoph Strobl
32+ * @author Artyom Muravlev
3433 */
35- public class GeoJsonModuleUnitTests {
34+ class GeoJsonModuleUnitTests {
3635
3736 ObjectMapper mapper ;
3837
3938 @ BeforeEach
40- public void setUp () {
39+ void setUp () {
4140
4241 mapper = new ObjectMapper ();
4342 mapper .registerModule (new GeoJsonModule ());
4443 }
4544
4645 @ Test // DATAMONGO-1181
47- public void shouldDeserializeJsonPointCorrectly () throws JsonParseException , JsonMappingException , IOException {
46+ void shouldDeserializeJsonPointCorrectly () throws IOException {
4847
4948 String json = "{ \" type\" : \" Point\" , \" coordinates\" : [10.0, 20.0] }" ;
5049
5150 assertThat (mapper .readValue (json , GeoJsonPoint .class )).isEqualTo (new GeoJsonPoint (10D , 20D ));
5251 }
5352
5453 @ Test // DATAMONGO-1181
55- public void shouldDeserializeGeoJsonLineStringCorrectly ()
56- throws JsonParseException , JsonMappingException , IOException {
54+ void shouldDeserializeGeoJsonLineStringCorrectly ()
55+ throws IOException {
5756
5857 String json = "{ \" type\" : \" LineString\" , \" coordinates\" : [ [10.0, 20.0], [30.0, 40.0], [50.0, 60.0] ]}" ;
5958
@@ -62,8 +61,8 @@ public void shouldDeserializeGeoJsonLineStringCorrectly()
6261 }
6362
6463 @ Test // DATAMONGO-1181
65- public void shouldDeserializeGeoJsonMultiPointCorrectly ()
66- throws JsonParseException , JsonMappingException , IOException {
64+ void shouldDeserializeGeoJsonMultiPointCorrectly ()
65+ throws IOException {
6766
6867 String json = "{ \" type\" : \" MultiPoint\" , \" coordinates\" : [ [10.0, 20.0], [30.0, 40.0], [50.0, 60.0] ]}" ;
6968
@@ -73,8 +72,8 @@ public void shouldDeserializeGeoJsonMultiPointCorrectly()
7372
7473 @ Test // DATAMONGO-1181
7574 @ SuppressWarnings ("unchecked" )
76- public void shouldDeserializeGeoJsonMultiLineStringCorrectly ()
77- throws JsonParseException , JsonMappingException , IOException {
75+ void shouldDeserializeGeoJsonMultiLineStringCorrectly ()
76+ throws IOException {
7877
7978 String json = "{ \" type\" : \" MultiLineString\" , \" coordinates\" : [ [ [10.0, 20.0], [30.0, 40.0] ], [ [50.0, 60.0] , [70.0, 80.0] ] ]}" ;
8079
@@ -83,7 +82,7 @@ public void shouldDeserializeGeoJsonMultiLineStringCorrectly()
8382 }
8483
8584 @ Test // DATAMONGO-1181
86- public void shouldDeserializeGeoJsonPolygonCorrectly () throws JsonParseException , JsonMappingException , IOException {
85+ void shouldDeserializeGeoJsonPolygonCorrectly () throws IOException {
8786
8887 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] ] ]}" ;
8988
@@ -92,8 +91,8 @@ public void shouldDeserializeGeoJsonPolygonCorrectly() throws JsonParseException
9291 }
9392
9493 @ Test // DATAMONGO-1181
95- public void shouldDeserializeGeoJsonMultiPolygonCorrectly ()
96- throws JsonParseException , JsonMappingException , IOException {
94+ void shouldDeserializeGeoJsonMultiPolygonCorrectly ()
95+ throws IOException {
9796
9897 String json = "{ \" type\" : \" Polygon\" , \" coordinates\" : ["
9998 + "[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],"
@@ -110,4 +109,74 @@ public void shouldDeserializeGeoJsonMultiPolygonCorrectly()
110109 new Point (100.2 , 0.8 ), new Point (100.2 , 0.2 ))))));
111110
112111 }
112+
113+ @ Test // GH-4950
114+ void shouldSerializeJsonPointCorrectly () throws IOException {
115+
116+ String json = "{\" type\" :\" Point\" ,\" coordinates\" :[10.0,20.0]}" ;
117+
118+ assertThat (mapper .writeValueAsString (new GeoJsonPoint (10D , 20D ))).isEqualTo (json );
119+ }
120+
121+ @ Test // GH-4950
122+ void shouldSerializeGeoJsonLineStringCorrectly ()
123+ throws IOException {
124+
125+ String json = "{\" type\" :\" LineString\" ,\" coordinates\" :[[10.0,20.0],[30.0,40.0],[50.0,60.0]]}" ;
126+
127+ assertThat (mapper .writeValueAsString (new GeoJsonLineString (Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 ), new Point (50 , 60 )))))
128+ .isEqualTo (json );
129+ }
130+
131+ @ Test // GH-4950
132+ void shouldSerializeGeoJsonMultiPointCorrectly ()
133+ throws IOException {
134+
135+ String json = "{\" type\" :\" MultiPoint\" ,\" coordinates\" :[[10.0,20.0],[30.0,40.0],[50.0,60.0]]}" ;
136+
137+ assertThat (mapper .writeValueAsString (new GeoJsonMultiPoint (Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 ), new Point (50 , 60 )))))
138+ .isEqualTo (json );
139+ }
140+
141+ @ Test // GH-4950
142+ @ SuppressWarnings ("unchecked" )
143+ void shouldSerializeGeoJsonMultiLineStringCorrectly ()
144+ throws IOException {
145+
146+ String json = "{\" type\" :\" MultiLineString\" ,\" coordinates\" :[[[10.0,20.0],[30.0,40.0]],[[50.0,60.0],[70.0,80.0]]]}" ;
147+
148+ assertThat (mapper .writeValueAsString (new GeoJsonMultiLineString (
149+ Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 )), Arrays .asList (new Point (50 , 60 ), new Point (70 , 80 )))))
150+ .isEqualTo (json );
151+ }
152+
153+ @ Test // GH-4950
154+ void shouldSerializeGeoJsonPolygonCorrectly () throws IOException {
155+
156+ 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]]]}" ;
157+
158+ assertThat (mapper .writeValueAsString (new GeoJsonPolygon (
159+ Arrays .asList (new Point (100 , 0 ), new Point (101 , 0 ), new Point (101 , 1 ), new Point (100 , 1 ), new Point (100 , 0 )))))
160+ .isEqualTo (json );
161+ }
162+
163+ @ Test // GH-4950
164+ void shouldSerializeGeoJsonMultiPolygonCorrectly ()
165+ throws IOException {
166+
167+ String json ="{\" type\" :\" MultiPolygon\" ,\" coordinates\" :["
168+ +"[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]],"
169+ +"[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]],"
170+ +"[[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]" //
171+ +"]}" ;
172+
173+ assertThat (mapper .writeValueAsString (new GeoJsonMultiPolygon (Arrays .asList (
174+ new GeoJsonPolygon (Arrays .asList (new Point (102 , 2 ), new Point (103 , 2 ), new Point (103 , 3 ), new Point (102 , 3 ),
175+ new Point (102 , 2 ))),
176+ new GeoJsonPolygon (Arrays .asList (new Point (100 , 0 ), new Point (101 , 0 ), new Point (101 , 1 ), new Point (100 , 1 ),
177+ new Point (100 , 0 ))),
178+ new GeoJsonPolygon (Arrays .asList (new Point (100.2 , 0.2 ), new Point (100.8 , 0.2 ), new Point (100.8 , 0.8 ),
179+ new Point (100.2 , 0.8 ), new Point (100.2 , 0.2 ))))))).isEqualTo (json );
180+
181+ }
113182}
0 commit comments