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