summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/geometry/GeoJsonConversionTest.java
blob: 90b82d56f3616e9d9485c943578eefd6806fdb1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.mapbox.mapboxsdk.testapp.geometry;

import com.mapbox.geojson.FeatureCollection;
import com.mapbox.geojson.Point;
import com.mapbox.geojson.Polygon;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
import com.mapbox.mapboxsdk.style.sources.CustomGeometrySource;
import com.mapbox.mapboxsdk.style.sources.GeometryTileProvider;
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest;
import org.junit.Test;

import static com.mapbox.geojson.Feature.fromGeometry;
import static com.mapbox.geojson.FeatureCollection.fromFeatures;
import static com.mapbox.geojson.GeometryCollection.fromGeometries;
import static com.mapbox.geojson.LineString.fromLngLats;
import static com.mapbox.geojson.MultiLineString.fromLineString;
import static com.mapbox.geojson.MultiPolygon.fromPolygon;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

/**
 * Instrumentation test to validate java geojson conversion to c++
 */
public class GeoJsonConversionTest extends EspressoTest {

  // Regression test for #12343
  @Test
  public void testEmptyFeatureCollection() {
    validateTestSetup();
    onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
      mapboxMap.getStyle().addSource(
        new CustomGeometrySource("test-id",
          new CustomProvider(fromFeatures(singletonList(fromGeometry(fromGeometries(emptyList())))))
        )
      );
      mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
    }));
  }

  @Test
  public void testPointFeatureCollection() {
    validateTestSetup();
    onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
      mapboxMap.getStyle().addSource(
        new CustomGeometrySource("test-id",
          new CustomProvider(fromFeatures(singletonList(fromGeometry(Point.fromLngLat(0.0,0.0)))))
        )
      );
      mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
    }));
  }

  @Test
  public void testMultiPointFeatureCollection() {
    validateTestSetup();
    onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
      mapboxMap.getStyle().addSource(
        new CustomGeometrySource("test-id",
          new CustomProvider(fromFeatures(singletonList(fromGeometry(fromLngLats(emptyList())))))
        )
      );
      mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
    }));
  }


  @Test
  public void testPolygonFeatureCollection() {
    validateTestSetup();
    onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
      mapboxMap.getStyle().addSource(
        new CustomGeometrySource("test-id",
          new CustomProvider(fromFeatures(singletonList(fromGeometry(Polygon.fromLngLats(emptyList())))))
        )
      );
      mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
    }));
  }

  @Test
  public void testMultiPolygonFeatureCollection() {
    validateTestSetup();
    onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
      mapboxMap.getStyle().addSource(
        new CustomGeometrySource("test-id",
          new CustomProvider(fromFeatures(singletonList(fromGeometry(fromPolygon(Polygon.fromLngLats(emptyList()))))))
        )
      );
      mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
    }));
  }

  @Test
  public void testLineStringFeatureCollection() {
    validateTestSetup();
    onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
      mapboxMap.getStyle().addSource(
        new CustomGeometrySource("test-id",
          new CustomProvider(fromFeatures(singletonList(fromGeometry(fromLngLats(emptyList())))))
        )
      );
      mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
    }));
  }

  @Test
  public void testMultiLineStringFeatureCollection() {
    validateTestSetup();
    onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
      mapboxMap.getStyle().addSource(
        new CustomGeometrySource("test-id",
          new CustomProvider(fromFeatures(singletonList(fromGeometry(fromLineString(fromLngLats(emptyList()))))))
        )
      );
      mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
    }));
  }

  class CustomProvider implements GeometryTileProvider {

    private FeatureCollection featureCollection;

    CustomProvider(FeatureCollection featureCollection) {
      this.featureCollection = featureCollection;
    }

    @Override
    public FeatureCollection getFeaturesForBounds(LatLngBounds bounds, int zoom) {
      return featureCollection;
    }
  }
}