3232/**
3333 * @author Christoph Strobl
3434 */
35- public class GeoJsonModuleUnitTests {
35+ class GeoJsonModuleUnitTests {
3636
3737 ObjectMapper mapper ;
3838
3939 @ BeforeEach
40- public void setUp () {
40+ void setUp () {
4141
4242 mapper = new ObjectMapper ();
4343 mapper .registerModule (new GeoJsonModule ());
4444 }
4545
4646 @ Test // DATAMONGO-1181
47- public void shouldDeserializeJsonPointCorrectly () throws JsonParseException , JsonMappingException , IOException {
47+ void shouldDeserializeJsonPointCorrectly () throws IOException {
4848
4949 String json = "{ \" type\" : \" Point\" , \" coordinates\" : [10.0, 20.0] }" ;
5050
5151 assertThat (mapper .readValue (json , GeoJsonPoint .class )).isEqualTo (new GeoJsonPoint (10D , 20D ));
5252 }
5353
5454 @ Test // DATAMONGO-1181
55- public void shouldDeserializeGeoJsonLineStringCorrectly ()
56- throws JsonParseException , JsonMappingException , IOException {
55+ void shouldDeserializeGeoJsonLineStringCorrectly ()
56+ throws IOException {
5757
5858 String json = "{ \" type\" : \" LineString\" , \" coordinates\" : [ [10.0, 20.0], [30.0, 40.0], [50.0, 60.0] ]}" ;
5959
@@ -62,8 +62,8 @@ public void shouldDeserializeGeoJsonLineStringCorrectly()
6262 }
6363
6464 @ Test // DATAMONGO-1181
65- public void shouldDeserializeGeoJsonMultiPointCorrectly ()
66- throws JsonParseException , JsonMappingException , IOException {
65+ void shouldDeserializeGeoJsonMultiPointCorrectly ()
66+ throws IOException {
6767
6868 String json = "{ \" type\" : \" MultiPoint\" , \" coordinates\" : [ [10.0, 20.0], [30.0, 40.0], [50.0, 60.0] ]}" ;
6969
@@ -73,8 +73,8 @@ public void shouldDeserializeGeoJsonMultiPointCorrectly()
7373
7474 @ Test // DATAMONGO-1181
7575 @ SuppressWarnings ("unchecked" )
76- public void shouldDeserializeGeoJsonMultiLineStringCorrectly ()
77- throws JsonParseException , JsonMappingException , IOException {
76+ void shouldDeserializeGeoJsonMultiLineStringCorrectly ()
77+ throws IOException {
7878
7979 String json = "{ \" type\" : \" MultiLineString\" , \" coordinates\" : [ [ [10.0, 20.0], [30.0, 40.0] ], [ [50.0, 60.0] , [70.0, 80.0] ] ]}" ;
8080
@@ -83,7 +83,7 @@ public void shouldDeserializeGeoJsonMultiLineStringCorrectly()
8383 }
8484
8585 @ Test // DATAMONGO-1181
86- public void shouldDeserializeGeoJsonPolygonCorrectly () throws JsonParseException , JsonMappingException , IOException {
86+ void shouldDeserializeGeoJsonPolygonCorrectly () throws IOException {
8787
8888 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] ] ]}" ;
8989
@@ -92,8 +92,8 @@ public void shouldDeserializeGeoJsonPolygonCorrectly() throws JsonParseException
9292 }
9393
9494 @ Test // DATAMONGO-1181
95- public void shouldDeserializeGeoJsonMultiPolygonCorrectly ()
96- throws JsonParseException , JsonMappingException , IOException {
95+ void shouldDeserializeGeoJsonMultiPolygonCorrectly ()
96+ throws IOException {
9797
9898 String json = "{ \" type\" : \" Polygon\" , \" coordinates\" : ["
9999 + "[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],"
@@ -110,4 +110,74 @@ public void shouldDeserializeGeoJsonMultiPolygonCorrectly()
110110 new Point (100.2 , 0.8 ), new Point (100.2 , 0.2 ))))));
111111
112112 }
113+
114+ @ Test
115+ void shouldSerializeJsonPointCorrectly () throws IOException {
116+
117+ String json = "{\" type\" :\" Point\" ,\" coordinates\" :[10.0,20.0]}" ;
118+
119+ assertThat (mapper .writeValueAsString (new GeoJsonPoint (10D , 20D ))).isEqualTo (json );
120+ }
121+
122+ @ Test
123+ void shouldSerializeGeoJsonLineStringCorrectly ()
124+ throws IOException {
125+
126+ String json = "{\" type\" :\" LineString\" ,\" coordinates\" :[[10.0,20.0],[30.0,40.0],[50.0,60.0]]}" ;
127+
128+ assertThat (mapper .writeValueAsString (new GeoJsonLineString (Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 ), new Point (50 , 60 )))))
129+ .isEqualTo (json );
130+ }
131+
132+ @ Test
133+ void shouldSerializeGeoJsonMultiPointCorrectly ()
134+ throws IOException {
135+
136+ String json = "{\" type\" :\" MultiPoint\" ,\" coordinates\" :[[10.0,20.0],[30.0,40.0],[50.0,60.0]]}" ;
137+
138+ assertThat (mapper .writeValueAsString (new GeoJsonMultiPoint (Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 ), new Point (50 , 60 )))))
139+ .isEqualTo (json );
140+ }
141+
142+ @ Test
143+ @ SuppressWarnings ("unchecked" )
144+ void shouldSerializeGeoJsonMultiLineStringCorrectly ()
145+ throws IOException {
146+
147+ String json = "{\" type\" :\" MultiLineString\" ,\" coordinates\" :[[[10.0,20.0],[30.0,40.0]],[[50.0,60.0],[70.0,80.0]]]}" ;
148+
149+ assertThat (mapper .writeValueAsString (new GeoJsonMultiLineString (
150+ Arrays .asList (new Point (10 , 20 ), new Point (30 , 40 )), Arrays .asList (new Point (50 , 60 ), new Point (70 , 80 )))))
151+ .isEqualTo (json );
152+ }
153+
154+ @ Test
155+ void shouldSerializeGeoJsonPolygonCorrectly () throws IOException {
156+
157+ 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]]]}" ;
158+
159+ assertThat (mapper .writeValueAsString (new GeoJsonPolygon (
160+ Arrays .asList (new Point (100 , 0 ), new Point (101 , 0 ), new Point (101 , 1 ), new Point (100 , 1 ), new Point (100 , 0 )))))
161+ .isEqualTo (json );
162+ }
163+
164+ @ Test
165+ void shouldSerializeGeoJsonMultiPolygonCorrectly ()
166+ throws IOException {
167+
168+ String json ="{\" type\" :\" MultiPolygon\" ,\" coordinates\" :["
169+ +"[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]],"
170+ +"[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]],"
171+ +"[[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]" //
172+ +"]}" ;
173+
174+ assertThat (mapper .writeValueAsString (new GeoJsonMultiPolygon (Arrays .asList (
175+ new GeoJsonPolygon (Arrays .asList (new Point (102 , 2 ), new Point (103 , 2 ), new Point (103 , 3 ), new Point (102 , 3 ),
176+ new Point (102 , 2 ))),
177+ new GeoJsonPolygon (Arrays .asList (new Point (100 , 0 ), new Point (101 , 0 ), new Point (101 , 1 ), new Point (100 , 1 ),
178+ new Point (100 , 0 ))),
179+ new GeoJsonPolygon (Arrays .asList (new Point (100.2 , 0.2 ), new Point (100.8 , 0.2 ), new Point (100.8 , 0.8 ),
180+ new Point (100.2 , 0.8 ), new Point (100.2 , 0.2 ))))))).isEqualTo (json );
181+
182+ }
113183}
0 commit comments