Skip to content

Commit 7336065

Browse files
Add test data utils tests
1 parent a3346c7 commit 7336065

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.ona.kujaku.sample;
2+
3+
import com.mapbox.geojson.Feature;
4+
5+
import org.json.JSONArray;
6+
import org.junit.Test;
7+
8+
import java.util.List;
9+
10+
import static io.ona.kujaku.sample.utils.TestDataUtils.createFeatureJsonArray;
11+
import static io.ona.kujaku.sample.utils.TestDataUtils.createFeatureList;
12+
import static junit.framework.Assert.assertEquals;
13+
import static junit.framework.Assert.assertNotNull;
14+
15+
/**
16+
* @author Vincent Karuri
17+
*/
18+
public class TestDataUtilsTest {
19+
20+
@Test
21+
public void testCreateFeatureListShouldNotBeEmptyList() {
22+
List<Feature> features = null;
23+
try {
24+
features = createFeatureList(5, 0, 31.03823, -1.214348, "test_property", "Point", false, new String[]{"property1", "property2", "property3"}, 0.001);
25+
} catch (Exception e) {
26+
27+
}
28+
assertNotNull(features);
29+
assertEquals(features.size(), 5);
30+
}
31+
32+
@Test
33+
public void testCreateFeatureJsonArrayShouldNotBeEmpty() {
34+
JSONArray features = null;
35+
try {
36+
features = createFeatureJsonArray(5, 31.03823, -1.214348, "test_property", new String[]{"property1", "property2", "property3"});
37+
} catch (Exception e) {
38+
39+
}
40+
assertNotNull(features);
41+
assertEquals(features.length(), 5);
42+
}
43+
}

sample/src/main/java/io/ona/kujaku/sample/utils/TestDataUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ public static List<Feature> createFeatureList(int numFeatures, int startingIndex
116116
double newLatitude = latitude;
117117

118118
int featureNumber = startingIndex;
119-
int prevFeatureNumber = startingIndex;
119+
int prevFeatureNumber = -1;
120120

121121
List<Feature> features = new ArrayList<>();
122122
final int FEATURE_GROUP_SIZE = featureGroup.length;
123-
while (featureNumber < numFeatures + startingIndex + 1) {
123+
while (featureNumber < numFeatures + startingIndex) {
124124
if (prevFeatureNumber != featureNumber) {
125125
JSONObject feature = new JSONObject();
126126
feature.put("id", "feature_" + UUID.randomUUID());

0 commit comments

Comments
 (0)