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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
package com.mapbox.mapboxsdk.testapp.style;
import android.support.annotation.RawRes;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
import com.mapbox.services.commons.geojson.Feature;
import com.mapbox.services.commons.geojson.FeatureCollection;
import com.mapbox.services.commons.geojson.Point;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException;
import timber.log.Timber;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
/**
* Tests for {@link GeoJsonSource}
*/
@RunWith(AndroidJUnit4.class)
public class GeoJsonSourceTests extends BaseActivityTest {
@Override
protected Class getActivityClass() {
return RuntimeStyleTestActivity.class;
}
@Test
public void testFeatureCollection() throws Exception {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new BaseViewAction() {
@Override
public void perform(UiController uiController, View view) {
GeoJsonSource source = null;
try {
source = new GeoJsonSource("source", FeatureCollection
.fromJson(ResourceUtils.readRawResource(rule.getActivity(), R.raw.test_feature_collection)));
} catch (IOException exception) {
Timber.e(exception);
}
mapboxMap.addSource(source);
mapboxMap.addLayer(new CircleLayer("layer", source.getId()));
}
});
}
@Test
public void testPointGeometry() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new BaseViewAction() {
@Override
public void perform(UiController uiController, View view) {
GeoJsonSource source = new GeoJsonSource("source", Point.fromCoordinates(new double[] {0d, 0d}));
mapboxMap.addSource(source);
mapboxMap.addLayer(new CircleLayer("layer", source.getId()));
}
});
}
@Test
public void testFeatureProperties() throws IOException {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new BaseViewAction() {
@Override
public void perform(UiController uiController, View view) {
GeoJsonSource source = null;
try {
source = new GeoJsonSource("source",
ResourceUtils.readRawResource(rule.getActivity(), R.raw.test_feature_properties));
} catch (IOException exception) {
Timber.e(exception);
}
mapboxMap.addSource(source);
mapboxMap.addLayer(new CircleLayer("layer", source.getId()));
}
});
}
@Test
public void testPointFeature() {
testFeatureFromResource(R.raw.test_point_feature);
}
@Test
public void testLineStringFeature() {
testFeatureFromResource(R.raw.test_line_string_feature);
}
@Test
public void testPolygonFeature() {
testFeatureFromResource(R.raw.test_polygon_feature);
}
@Test
public void testPolygonWithHoleFeature() {
testFeatureFromResource(R.raw.test_polygon_with_hole_feature);
}
@Test
public void testMultiPointFeature() {
testFeatureFromResource(R.raw.test_multi_point_feature);
}
@Test
public void testMultiLineStringFeature() {
testFeatureFromResource(R.raw.test_multi_line_string_feature);
}
@Test
public void testMultiPolygonFeature() {
testFeatureFromResource(R.raw.test_multi_polygon_feature);
}
protected void testFeatureFromResource(final @RawRes int resource) {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new BaseViewAction() {
@Override
public void perform(UiController uiController, View view) {
GeoJsonSource source = new GeoJsonSource("source");
mapboxMap.addSource(source);
Layer layer = new CircleLayer("layer", source.getId());
mapboxMap.addLayer(layer);
try {
source.setGeoJson(Feature.fromJson(ResourceUtils.readRawResource(rule.getActivity(), resource)));
} catch (IOException exception) {
Timber.e(exception);
}
mapboxMap.removeLayer(layer);
mapboxMap.removeSource(source);
}
});
}
public abstract class BaseViewAction implements ViewAction {
@Override
public Matcher<View> getConstraints() {
return isDisplayed();
}
@Override
public String getDescription() {
return getClass().getSimpleName();
}
}
}
|