32
32
/**
33
33
* @author Christoph Strobl
34
34
*/
35
- public class GeoJsonModuleUnitTests {
35
+ class GeoJsonModuleUnitTests {
36
36
37
37
ObjectMapper mapper ;
38
38
39
39
@ BeforeEach
40
- public void setUp () {
40
+ void setUp () {
41
41
42
42
mapper = new ObjectMapper ();
43
43
mapper .registerModule (new GeoJsonModule ());
44
44
}
45
45
46
46
@ Test // DATAMONGO-1181
47
- public void shouldDeserializeJsonPointCorrectly () throws JsonParseException , JsonMappingException , IOException {
47
+ void shouldDeserializeJsonPointCorrectly () throws IOException {
48
48
49
49
String json = "{ \" type\" : \" Point\" , \" coordinates\" : [10.0, 20.0] }" ;
50
50
51
51
assertThat (mapper .readValue (json , GeoJsonPoint .class )).isEqualTo (new GeoJsonPoint (10D , 20D ));
52
52
}
53
53
54
54
@ Test // DATAMONGO-1181
55
- public void shouldDeserializeGeoJsonLineStringCorrectly ()
56
- throws JsonParseException , JsonMappingException , IOException {
55
+ void shouldDeserializeGeoJsonLineStringCorrectly ()
56
+ throws IOException {
57
57
58
58
String json = "{ \" type\" : \" LineString\" , \" coordinates\" : [ [10.0, 20.0], [30.0, 40.0], [50.0, 60.0] ]}" ;
59
59
@@ -62,8 +62,8 @@ public void shouldDeserializeGeoJsonLineStringCorrectly()
62
62
}
63
63
64
64
@ Test // DATAMONGO-1181
65
- public void shouldDeserializeGeoJsonMultiPointCorrectly ()
66
- throws JsonParseException , JsonMappingException , IOException {
65
+ void shouldDeserializeGeoJsonMultiPointCorrectly ()
66
+ throws IOException {
67
67
68
68
String json = "{ \" type\" : \" MultiPoint\" , \" coordinates\" : [ [10.0, 20.0], [30.0, 40.0], [50.0, 60.0] ]}" ;
69
69
@@ -73,8 +73,8 @@ public void shouldDeserializeGeoJsonMultiPointCorrectly()
73
73
74
74
@ Test // DATAMONGO-1181
75
75
@ SuppressWarnings ("unchecked" )
76
- public void shouldDeserializeGeoJsonMultiLineStringCorrectly ()
77
- throws JsonParseException , JsonMappingException , IOException {
76
+ void shouldDeserializeGeoJsonMultiLineStringCorrectly ()
77
+ throws IOException {
78
78
79
79
String json = "{ \" type\" : \" MultiLineString\" , \" coordinates\" : [ [ [10.0, 20.0], [30.0, 40.0] ], [ [50.0, 60.0] , [70.0, 80.0] ] ]}" ;
80
80
@@ -83,7 +83,7 @@ public void shouldDeserializeGeoJsonMultiLineStringCorrectly()
83
83
}
84
84
85
85
@ Test // DATAMONGO-1181
86
- public void shouldDeserializeGeoJsonPolygonCorrectly () throws JsonParseException , JsonMappingException , IOException {
86
+ void shouldDeserializeGeoJsonPolygonCorrectly () throws IOException {
87
87
88
88
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] ] ]}" ;
89
89
@@ -92,8 +92,8 @@ public void shouldDeserializeGeoJsonPolygonCorrectly() throws JsonParseException
92
92
}
93
93
94
94
@ Test // DATAMONGO-1181
95
- public void shouldDeserializeGeoJsonMultiPolygonCorrectly ()
96
- throws JsonParseException , JsonMappingException , IOException {
95
+ void shouldDeserializeGeoJsonMultiPolygonCorrectly ()
96
+ throws IOException {
97
97
98
98
String json = "{ \" type\" : \" Polygon\" , \" coordinates\" : ["
99
99
+ "[[[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()
110
110
new Point (100.2 , 0.8 ), new Point (100.2 , 0.2 ))))));
111
111
112
112
}
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
+ }
113
183
}
0 commit comments