11package com .mapbox .geojson .shifter ;
22
3+ import com .google .gson .JsonParser ;
34import com .mapbox .geojson .BoundingBox ;
5+ import com .mapbox .geojson .LineString ;
46import com .mapbox .geojson .Point ;
57
68import static com .mapbox .core .TestUtils .DELTA ;
79import static org .junit .Assert .assertNotNull ;
810import static org .junit .Assert .assertEquals ;
11+ import static org .junit .Assert .assertThat ;
912
13+ import org .hamcrest .Matchers ;
1014import org .junit .Test ;
1115
1216import java .lang .reflect .Array ;
17+ import java .util .ArrayList ;
1318import java .util .Arrays ;
1419import java .util .List ;
1520
@@ -46,7 +51,7 @@ public List<Double> unshiftPoint(List<Double> coordinates) {
4651 };
4752
4853 @ Test
49- public void basic_shift () throws Exception {
54+ public void point_basic_shift () throws Exception {
5055
5156 Point southwest = Point .fromLngLat (2.0 , 2.0 );
5257 Point northeast = Point .fromLngLat (4.0 , 4.0 );
@@ -68,16 +73,27 @@ public void basic_shift() throws Exception {
6873 assertEquals (southwestManualShifted , southwestShifted );
6974 assertEquals (northeastManualShifted , northeastShifted );
7075
76+ CoordinateShifterManager .setCoordinateShifter (null );
77+ }
78+
79+ @ Test
80+ public void bbox_basic_shift () throws Exception {
81+
82+ CoordinateShifter shifter = new TestCoordinateShifter ();
83+
7184 BoundingBox boundingBoxFromDouble = BoundingBox .fromLngLats (2.0 , 2.0 , 4.0 , 4.0 );
72- BoundingBox boundingBoxFromPoints = BoundingBox .fromPoints (southwestShifted , northeastShifted );
85+
86+ BoundingBox boundingBoxFromPoints =
87+ BoundingBox .fromPoints (Point .fromLngLat (2.0 , 2.0 ),
88+ Point .fromLngLat (4.0 , 4.0 ));
7389
7490 assertEquals (boundingBoxFromDouble , boundingBoxFromPoints );
7591
7692 CoordinateShifterManager .setCoordinateShifter (null );
7793 }
7894
7995 @ Test
80- public void toJson () throws Exception {
96+ public void point_toJson () throws Exception {
8197
8298 // set shifter
8399 CoordinateShifterManager .setCoordinateShifter (new TestCoordinateShifter ());
@@ -91,7 +107,7 @@ public void toJson() throws Exception {
91107 }
92108
93109 @ Test
94- public void fromJson () throws Exception {
110+ public void point_fromJson () throws Exception {
95111
96112 // set shifter
97113 CoordinateShifterManager .setCoordinateShifter (new TestCoordinateShifter ());
@@ -104,4 +120,30 @@ public void fromJson() throws Exception {
104120
105121 CoordinateShifterManager .setCoordinateShifter (null );
106122 }
123+
124+ @ Test
125+ public void linestring_basic_shift_with_bbox () {
126+ // set shifter
127+ CoordinateShifterManager .setCoordinateShifter (new TestCoordinateShifter ());
128+
129+ List <Point > points = new ArrayList <>();
130+ points .add (Point .fromLngLat (1.0 , 1.0 ));
131+ points .add (Point .fromLngLat (2.0 , 2.0 ));
132+ points .add (Point .fromLngLat (3.0 , 3.0 ));
133+ BoundingBox bbox = BoundingBox .fromLngLats (1.0 , 2.0 , 3.0 , 4.0 );
134+ LineString lineString = LineString .fromLngLats (points , bbox );
135+
136+ String jsonString = lineString .toJson ();
137+ compareJson ("{\" coordinates\" :[[1,1],[2,2],[3,3]],"
138+ + "\" type\" :\" LineString\" ,\" bbox\" :[1.0,2.0,3.0,4.0]}" ,
139+ jsonString );
140+
141+ CoordinateShifterManager .setCoordinateShifter (null );
142+ }
143+
144+ public void compareJson (String expectedJson , String actualJson ) {
145+ JsonParser parser = new JsonParser ();
146+ assertThat (parser .parse (actualJson ), Matchers .equalTo (parser .parse (expectedJson )));
147+ }
148+
107149}
0 commit comments