Unit test fixes

This commit is contained in:
Petr Pokorny
2021-01-25 21:04:02 +01:00
parent 0e88c4b198
commit 7de95ca888
6 changed files with 39 additions and 97 deletions

View File

@@ -21,7 +21,6 @@ import java.util.Set;
*/
public class AttributionParser {
private static final String IMPROVE_THIS_MAP = "Improve this map";
private final WeakReference<Context> context;
private final Set<Attribution> attributions = new LinkedHashSet<>();
private final String attributionData;
@@ -120,16 +119,6 @@ public class AttributionParser {
return isValidForImproveThisMap(url) && isValidForMapbox(url);
}
/**
* Invoked to validate if an anchor is equal to Improve this map coming from tilesets.
*
* @param anchor the anchor to be validated
* @return if the url is valid
*/
private boolean isImproveThisMapAnchor(String anchor) {
return anchor.equals(IMPROVE_THIS_MAP);
}
/**
* Invoked to validate if an url is valid for the improve map configuration.
*

View File

@@ -10,6 +10,7 @@ import android.util.Log;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.os.BuildCompat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -55,7 +56,7 @@ public class PermissionsManager {
}
public static boolean isBackgroundLocationPermissionGranted(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= 29) {
return isPermissionGranted(context, BACKGROUND_LOCATION_PERMISSION);
}
@@ -106,7 +107,7 @@ public class PermissionsManager {
permissions.add(COARSE_LOCATION_PERMISSION);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && requestBackgroundLocation) {
if (Build.VERSION.SDK_INT >= 29 && requestBackgroundLocation) {
permissions.add(BACKGROUND_LOCATION_PERMISSION);
}

View File

@@ -12,8 +12,8 @@ import static junit.framework.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
public class AttributionParseTest {
private static final String STREETS_ATTRIBUTION = "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">&copy; Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">&copy; OpenStreetMap</a> <a class=\"mapbox-improve-map\" href=\"https://apps.mapbox.com/feedback/\" target=\"_blank\">Improve this map</a>\n";
private static final String SATELLITE_ATTRIBUTION = "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">&copy; Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">&copy; OpenStreetMap</a> <a class=\"mapbox-improve-map\" href=\"https://apps.mapbox.com/feedback/\" target=\"_blank\">Improve this map</a> <a href=\"https://www.digitalglobe.com/\" target=\"_blank\">&copy; DigitalGlobe</a>\n";
private static final String STREETS_ATTRIBUTION = "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">&copy; Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">&copy; OpenStreetMap</a> \n";
private static final String SATELLITE_ATTRIBUTION = "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">&copy; Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">&copy; OpenStreetMap</a> <a href=\"https://www.digitalglobe.com/\" target=\"_blank\">&copy; DigitalGlobe</a>\n";
@Test
public void testParseAttributionStringSatellite() throws Exception {
@@ -21,39 +21,6 @@ public class AttributionParseTest {
.withAttributionData(SATELLITE_ATTRIBUTION)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 4, attributionList.size());
int counter = 0;
for (Attribution attribution : attributionList) {
switch (counter) {
case 0:
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
break;
case 1:
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
break;
case 2:
assertEquals("URL improve map should match", "https://apps.mapbox.com/feedback/", attribution.getUrl());
assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
break;
case 3:
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
break;
}
counter++;
}
}
@Test
public void testParseAttributionStringStreets() throws Exception {
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 3, attributionList.size());
@@ -69,8 +36,33 @@ public class AttributionParseTest {
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
break;
case 2:
assertEquals("URL improve map should match", "https://apps.mapbox.com/feedback/", attribution.getUrl());
assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
break;
}
counter++;
}
}
@Test
public void testParseAttributionStringStreets() throws Exception {
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 2, attributionList.size());
int counter = 0;
for (Attribution attribution : attributionList) {
switch (counter) {
case 0:
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
break;
case 1:
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
break;
}
counter++;
@@ -85,7 +77,7 @@ public class AttributionParseTest {
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 2, attributionList.size());
assertEquals("Size of list should match", 1, attributionList.size());
int counter = 0;
for (Attribution attribution : attributionList) {
@@ -94,10 +86,6 @@ public class AttributionParseTest {
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
break;
case 1:
assertEquals("URL improve map should match", "https://apps.mapbox.com/feedback/", attribution.getUrl());
assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
break;
}
counter++;
}
@@ -109,7 +97,7 @@ public class AttributionParseTest {
.withAttributionData(new String[] {STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION})
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 4, attributionList.size());
assertEquals("Size of list should match", 3, attributionList.size());
int counter = 0;
for (Attribution attribution : attributionList) {
@@ -123,10 +111,6 @@ public class AttributionParseTest {
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
break;
case 2:
assertEquals("URL improve map should match", "https://apps.mapbox.com/feedback/", attribution.getUrl());
assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
break;
case 3:
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
break;
@@ -171,7 +155,7 @@ public class AttributionParseTest {
.withCopyrightSign(false)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 4, attributionList.size());
assertEquals("Size of list should match", 3, attributionList.size());
int counter = 0;
for (Attribution attribution : attributionList) {
@@ -185,10 +169,6 @@ public class AttributionParseTest {
assertEquals("Title openstreetmap should match", "OpenStreetMap", attribution.getTitle());
break;
case 2:
assertEquals("URL improve map should match", "https://apps.mapbox.com/feedback/", attribution.getUrl());
assertEquals("Title improve map should match", "Improve This Map", attribution.getTitle());
break;
case 3:
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
assertEquals("Title digital globe should match", "DigitalGlobe", attribution.getTitle());
break;
@@ -304,19 +284,5 @@ public class AttributionParseTest {
attributionParser.createAttributionString(true)
);
}
@Test
public void testWithImproveThisMapString() throws Exception {
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
.withAttributionData(STREETS_ATTRIBUTION, "blabla", "")
.withImproveMap(true)
.withCopyrightSign(false)
.build();
assertEquals(
"Attribution string should match",
"© Mapbox / OSM / Improve This Map",
attributionParser.createAttributionString(true)
);
}
}

View File

@@ -39,20 +39,6 @@ class HttpRequestUrlTest {
assertEquals(expected, actual)
}
@Test
fun testOnlineMapboxCom() {
val expected = "http://mapbox.com/path/of/no/return.pbf?sku=foobar"
val actual = HttpRequestUrl.buildResourceUrl("mapbox.com", "http://mapbox.com/path/of/no/return.pbf", 0, false)
assertEquals(expected, actual)
}
@Test
fun testOnlineMapboxCn() {
val expected = "http://mapbox.cn/path/of/no/return.pbf?sku=foobar"
val actual = HttpRequestUrl.buildResourceUrl("mapbox.cn", "http://mapbox.cn/path/of/no/return.pbf", 0, false)
assertEquals(expected, actual)
}
@Test
fun testOnlineInvalidHost() {
val expected = "http://foobar.com/path/of/no/return.pbf"

View File

@@ -21,7 +21,7 @@ RUN set -eu \
&& apt-get update \
&& add-apt-repository -y ppa:git-core/ppa \
&& apt-get update \
&& apt-get -y install git curl make python3 python3-pip zip unzip ccache openjdk-9-jdk-headless apt-transport-https \
&& apt-get -y install git curl make python3 python3-pip zip unzip ccache openjdk-8-jdk-headless apt-transport-https \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \
&& rm -rf /var/lib/apt/lists/*

View File

@@ -2,8 +2,8 @@ ext {
androidVersions = [
minSdkVersion : 14,
targetSdkVersion : 29,
compileSdkVersion: 29,
targetSdkVersion : 28,
compileSdkVersion: 28,
]
versions = [