diff --git a/CHANGELOG.md b/CHANGELOG.md index 5044b584a..bdff4f560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Mapbox welcomes participation and contributions from everyone. ## Mapbox Android Telemetry +## v4.6.1 +- Fix crash `setBaseUrl()` on null `TelemetryClient` [#423](https://github.com/mapbox/mapbox-events-android/pull/423) + ## v4.6.0 - Add public api to change base url for telemetry endpoint [#420](https://github.com/mapbox/mapbox-events-android/pull/420) - Telemetry metrics [#397](https://github.com/mapbox/mapbox-events-android/pull/397) diff --git a/LICENSE b/LICENSE index 695c0fccf..cb4557f34 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018 Mapbox +Copyright (c) 2018-2019 Mapbox Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/gradle.properties b/gradle.properties index 3181f1823..a9c608236 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,8 +6,8 @@ POM_SCM_URL=https://github.com/mapbox/mapbox-events-android POM_SCM_CONNECTION=scm:git@github.com:mapbox/mapbox-events-android.git POM_SCM_DEV_CONNECTION=scm:git@github.com:mapbox/mapbox-events-android.git -POM_LICENCE_NAME=The Apache Software License, Version 2.0 -POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt +POM_LICENCE_NAME=The MIT License +POM_LICENCE_URL=https://opensource.org/licenses/MIT POM_LICENCE_DIST=repo POM_DEVELOPER_ID=mapbox diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 67754f9ac..79487d92f 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -25,7 +25,7 @@ ext { checkstyle : '8.4', gradle : '3.4.1', dependencyGraph : '0.5.0', - mapboxSdkVersions: '0.1.3' + mapboxSdkVersions: '1.0.1' ] dependenciesList = [ diff --git a/libcore/src/androidTest/java/com/mapbox/android/core/UserAgentSDKInfoTest.java b/libcore/src/androidTest/java/com/mapbox/android/core/UserAgentSDKInfoTest.java new file mode 100644 index 000000000..80625c934 --- /dev/null +++ b/libcore/src/androidTest/java/com/mapbox/android/core/UserAgentSDKInfoTest.java @@ -0,0 +1,46 @@ +package com.mapbox.android.core; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Locale; + +public class UserAgentSDKInfoTest { + + private static final String SDK_UA_FORMAT = "%s/%s (%s; %s)"; + private static final String SDK_UA_VERSION_CODE_FORMAT = "v%d"; + private static final Locale LOCALE_DEFAULT = Locale.US; + private static final String NAME = "libcore"; + + @Test + public void testSDKInformation() { + Context context = InstrumentationRegistry.getContext(); + String packageName = context.getPackageName().replace(".test", ""); + String versionCode = String.format(LOCALE_DEFAULT, SDK_UA_VERSION_CODE_FORMAT, BuildConfig.VERSION_CODE); + String sdkInfo = MapboxSdkInfoForUserAgentGenerator.getInstance(context.getAssets()) + .getMapboxSdkIdentifiersForUserAgent(context.getAssets()); + Assert.assertEquals(String.format(Locale.US, SDK_UA_FORMAT, NAME, BuildConfig.VERSION_NAME, + packageName, versionCode), sdkInfo); + } + + @Test + public void testUserAgentSdkInfo() { + Context context = InstrumentationRegistry.getContext(); + String sdkInfo = MapboxSdkInfoForUserAgentGenerator.getInstance(context.getAssets()) + .getSdkInfoForUserAgent(); + String packageName = context.getPackageName().replace(".test", ""); + String versionCode = String.format(LOCALE_DEFAULT, SDK_UA_VERSION_CODE_FORMAT, BuildConfig.VERSION_CODE); + Assert.assertEquals(String.format(Locale.US, SDK_UA_FORMAT, NAME, BuildConfig.VERSION_NAME, + packageName, versionCode), sdkInfo); + } + + @Test(expected = NullPointerException.class) + public void testSDKInformationInUserAgentWithNullContext() { + MapboxSdkInfoForUserAgentGenerator.getInstance(null) + .getSdkInfoForUserAgent(); + + } +} diff --git a/libcore/src/main/java/com/mapbox/android/core/MapboxSdkInfoForUserAgentGenerator.java b/libcore/src/main/java/com/mapbox/android/core/MapboxSdkInfoForUserAgentGenerator.java new file mode 100644 index 000000000..ff60ff323 --- /dev/null +++ b/libcore/src/main/java/com/mapbox/android/core/MapboxSdkInfoForUserAgentGenerator.java @@ -0,0 +1,88 @@ +package com.mapbox.android.core; + +import android.content.res.AssetManager; +import android.support.annotation.NonNull; +import android.support.annotation.RestrictTo; +import android.support.annotation.VisibleForTesting; +import android.util.Log; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Locale; + +/** + * Generator that reads(from assets/sdk_versions folder) and constructs Mapbox SDK versions for user agent. + * Generates strings in format for each Mapbox library in the host app and concatenates them seperated by spaces. + *

User agent format for Mapbox SDK : {SDK Name}/{Version} ({packageName}; {versionCode})

+ */ +public class MapboxSdkInfoForUserAgentGenerator { + + private static MapboxSdkInfoForUserAgentGenerator userAgentGenerator; + + private String sdkInfoForUserAgent; + private static final Object lock = new Object(); + private static final Locale DEFAULT_LOCALE = Locale.US; + private static final String USER_AGENT_SDK_VERSION_FORMAT = " %s (%s%s)"; + private static final String MAPBOX_IDENTIFIER = "mapbox"; + private static final String EMPTY_STRING = ""; + private static final String SDK_VERSIONS_FOLDER = "sdk_versions"; + private static final String LOG_TAG = "MapboxUAGenerator"; + + private MapboxSdkInfoForUserAgentGenerator(AssetManager assetManager) { + this.sdkInfoForUserAgent = getMapboxSdkIdentifiersForUserAgent(assetManager); + } + + public static MapboxSdkInfoForUserAgentGenerator getInstance(@NonNull AssetManager assetManager) { + if (userAgentGenerator == null) { + synchronized (lock) { + userAgentGenerator = new MapboxSdkInfoForUserAgentGenerator(assetManager); + } + } + return userAgentGenerator; + } + + @VisibleForTesting + @RestrictTo(RestrictTo.Scope.LIBRARY) + String getMapboxSdkIdentifiersForUserAgent(@NonNull AssetManager assetManager) { + StringBuilder stringBuilder = new StringBuilder(EMPTY_STRING); + try { + String[] files = assetManager.list(SDK_VERSIONS_FOLDER); + if (files != null) { + for (String fileName : files) { + if (fileName.contains(MAPBOX_IDENTIFIER)) { + InputStream inputStream = null; + try { + inputStream = assetManager.open(SDK_VERSIONS_FOLDER + File.separator + fileName); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + String nameAndVersion = reader.readLine(); + nameAndVersion = nameAndVersion != null ? nameAndVersion : EMPTY_STRING; + StringBuilder sdkSubInfo = new StringBuilder(EMPTY_STRING); + String subInfo; + while ((subInfo = reader.readLine()) != null) { + sdkSubInfo.append("; "); + sdkSubInfo.append(subInfo); + } + reader.close(); + stringBuilder.append(String.format(DEFAULT_LOCALE, USER_AGENT_SDK_VERSION_FORMAT, + nameAndVersion, fileName, sdkSubInfo.toString())); + } catch (IOException exception) { + Log.e(LOG_TAG, exception.toString()); + } finally { + FileUtils.closeQuietly(inputStream); + } + } + } + } + } catch (IOException exception) { + Log.e(LOG_TAG, exception.toString()); + } + return stringBuilder.toString().trim(); + } + + public String getSdkInfoForUserAgent() { + return sdkInfoForUserAgent; + } +} diff --git a/libcore/src/test/java/com/mapbox/android/core/UserAgentSDKInfoHandleExceptionsTest.java b/libcore/src/test/java/com/mapbox/android/core/UserAgentSDKInfoHandleExceptionsTest.java new file mode 100644 index 000000000..0c5c30842 --- /dev/null +++ b/libcore/src/test/java/com/mapbox/android/core/UserAgentSDKInfoHandleExceptionsTest.java @@ -0,0 +1,31 @@ +package com.mapbox.android.core; + +import android.content.res.AssetManager; + +import org.junit.Test; + +import java.io.IOException; + +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class UserAgentSDKInfoHandleExceptionsTest { + + @Test + public void testSDKInformationCatchOpenAssetsIOException() throws Exception { + AssetManager assetManager = mock(AssetManager.class); + when(assetManager.list(anyString())).thenThrow(IOException.class); + MapboxSdkInfoForUserAgentGenerator.getInstance(assetManager) + .getSdkInfoForUserAgent(); + } + + @Test + public void testSDKInformationReadInputStremIOException() throws IOException { + AssetManager assetManager = mock(AssetManager.class); + when(assetManager.list(anyString())).thenReturn(new String[] {"com.mapbox.android.core"}); + when(assetManager.open(anyString())).thenThrow(IOException.class); + MapboxSdkInfoForUserAgentGenerator.getInstance(assetManager) + .getSdkInfoForUserAgent(); + } +} diff --git a/liblocation/src/main/java/com/mapbox/android/core/location/AndroidLocationEngineImpl.java b/liblocation/src/main/java/com/mapbox/android/core/location/AndroidLocationEngineImpl.java index eeb6054eb..63f3f7a34 100644 --- a/liblocation/src/main/java/com/mapbox/android/core/location/AndroidLocationEngineImpl.java +++ b/liblocation/src/main/java/com/mapbox/android/core/location/AndroidLocationEngineImpl.java @@ -71,7 +71,7 @@ public void requestLocationUpdates(@NonNull LocationEngineRequest request, @Nullable Looper looper) throws SecurityException { // Pick best provider only if user has not explicitly chosen passive mode currentProvider = getBestProvider(request.getPriority()); - locationManager.requestLocationUpdates(currentProvider, request.getInterval(), request.getDisplacemnt(), + locationManager.requestLocationUpdates(currentProvider, request.getInterval(), request.getDisplacement(), listener, looper); } @@ -82,7 +82,7 @@ public void requestLocationUpdates(@NonNull LocationEngineRequest request, // Pick best provider only if user has not explicitly chosen passive mode currentProvider = getBestProvider(request.getPriority()); locationManager.requestLocationUpdates(currentProvider, request.getInterval(), - request.getDisplacemnt(), pendingIntent); + request.getDisplacement(), pendingIntent); } @SuppressLint("MissingPermission") @@ -171,4 +171,4 @@ public void onProviderDisabled(String s) { callback.onFailure(new Exception("Current provider disabled")); } } -} \ No newline at end of file +} diff --git a/liblocation/src/main/java/com/mapbox/android/core/location/GoogleLocationEngineImpl.java b/liblocation/src/main/java/com/mapbox/android/core/location/GoogleLocationEngineImpl.java index 7cd417d23..b75969c36 100644 --- a/liblocation/src/main/java/com/mapbox/android/core/location/GoogleLocationEngineImpl.java +++ b/liblocation/src/main/java/com/mapbox/android/core/location/GoogleLocationEngineImpl.java @@ -83,7 +83,7 @@ private static LocationRequest toGMSLocationRequest(LocationEngineRequest reques LocationRequest locationRequest = new LocationRequest(); locationRequest.setInterval(request.getInterval()); locationRequest.setFastestInterval(request.getFastestInterval()); - locationRequest.setSmallestDisplacement(request.getDisplacemnt()); + locationRequest.setSmallestDisplacement(request.getDisplacement()); locationRequest.setMaxWaitTime(request.getMaxWaitTime()); locationRequest.setPriority(toGMSLocationPriority(request.getPriority())); return locationRequest; diff --git a/liblocation/src/main/java/com/mapbox/android/core/location/LocationEngineRequest.java b/liblocation/src/main/java/com/mapbox/android/core/location/LocationEngineRequest.java index b69ea52ae..5e3b68272 100644 --- a/liblocation/src/main/java/com/mapbox/android/core/location/LocationEngineRequest.java +++ b/liblocation/src/main/java/com/mapbox/android/core/location/LocationEngineRequest.java @@ -81,7 +81,7 @@ public int getPriority() { * @return distance between location updates in meters. * @since 1.0.0 */ - public float getDisplacemnt() { + public float getDisplacement() { return displacement; } diff --git a/liblocation/src/main/java/com/mapbox/android/core/location/MapboxFusedLocationEngineImpl.java b/liblocation/src/main/java/com/mapbox/android/core/location/MapboxFusedLocationEngineImpl.java index bbb6c1e7f..6b173ab08 100644 --- a/liblocation/src/main/java/com/mapbox/android/core/location/MapboxFusedLocationEngineImpl.java +++ b/liblocation/src/main/java/com/mapbox/android/core/location/MapboxFusedLocationEngineImpl.java @@ -53,7 +53,7 @@ public void requestLocationUpdates(@NonNull LocationEngineRequest request, if (shouldStartNetworkProvider(request.getPriority())) { try { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, - request.getInterval(), request.getDisplacemnt(), + request.getInterval(), request.getDisplacement(), listener, looper); } catch (IllegalArgumentException iae) { iae.printStackTrace(); @@ -71,7 +71,7 @@ public void requestLocationUpdates(@NonNull LocationEngineRequest request, if (shouldStartNetworkProvider(request.getPriority())) { try { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, request.getInterval(), - request.getDisplacemnt(), pendingIntent); + request.getDisplacement(), pendingIntent); } catch (IllegalArgumentException iae) { iae.printStackTrace(); } diff --git a/libtelemetry/src/androidTest/java/com/mapbox/android/telemetry/TestReformedUserAgent.java b/libtelemetry/src/androidTest/java/com/mapbox/android/telemetry/TestReformedUserAgent.java new file mode 100644 index 000000000..2b6fa6202 --- /dev/null +++ b/libtelemetry/src/androidTest/java/com/mapbox/android/telemetry/TestReformedUserAgent.java @@ -0,0 +1,28 @@ +package com.mapbox.android.telemetry; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; + +import org.junit.Assert; +import org.junit.Test; + +public class TestReformedUserAgent { + + private static final String CORE_PACKAGE = "com.mapbox.android.core"; + private static final String TELEMETRY_PACKAGE = "com.mapbox.android.telemetry"; + + @Test + public void testReformedUserAgent() { + Context context = InstrumentationRegistry.getContext(); + String reformedUserAgent = TelemetryUtils.createReformedFullUserAgent(context); + Assert.assertTrue(reformedUserAgent.contains(context.getPackageName())); + Assert.assertTrue(reformedUserAgent.contains(CORE_PACKAGE)); + Assert.assertTrue(reformedUserAgent.contains(TELEMETRY_PACKAGE)); + Assert.assertFalse(reformedUserAgent.contains("null")); + } + + @Test(expected = NullPointerException.class) + public void testReformedUserAgentForNullContext() { + TelemetryUtils.createReformedFullUserAgent(null); + } +} diff --git a/libtelemetry/src/full/java/com/mapbox/android/telemetry/MapboxTelemetry.java b/libtelemetry/src/full/java/com/mapbox/android/telemetry/MapboxTelemetry.java index facf3eefa..3ba47cfe5 100644 --- a/libtelemetry/src/full/java/com/mapbox/android/telemetry/MapboxTelemetry.java +++ b/libtelemetry/src/full/java/com/mapbox/android/telemetry/MapboxTelemetry.java @@ -479,10 +479,12 @@ public Thread newThread(Runnable runnable) { } @SuppressWarnings("WeakerAccess") - public void setBaseUrl(String eventsHost) { - if (isValidUrl(eventsHost)) { + public synchronized boolean setBaseUrl(String eventsHost) { + if (isValidUrl(eventsHost) && checkNetworkAndParameters()) { telemetryClient.setBaseUrl(eventsHost); + return true; } + return false; } private static boolean isValidUrl(String eventsHost) { diff --git a/libtelemetry/src/lite/java/com/mapbox/android/telemetry/MapboxTelemetry.java b/libtelemetry/src/lite/java/com/mapbox/android/telemetry/MapboxTelemetry.java index 5da5b6de2..3d9c12004 100644 --- a/libtelemetry/src/lite/java/com/mapbox/android/telemetry/MapboxTelemetry.java +++ b/libtelemetry/src/lite/java/com/mapbox/android/telemetry/MapboxTelemetry.java @@ -1,6 +1,7 @@ package com.mapbox.android.telemetry; import android.content.Context; + import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -28,7 +29,7 @@ public MapboxTelemetry(Context context, String accessToken, String userAgent) { initializeContext(context); // FIXME: Propagate certificate blacklist changes from full version this.configurationClient = new ConfigurationClient(context, TelemetryUtils.createFullUserAgent(userAgent, - context), accessToken, new OkHttpClient()); + context), accessToken, new OkHttpClient()); this.certificateBlacklist = new CertificateBlacklist(context, configurationClient); checkRequiredParameters(accessToken, userAgent); initializeTelemetryListeners(); @@ -46,7 +47,7 @@ public MapboxTelemetry(Context context, String accessToken, String userAgent) { this.httpCallback = httpCallback; initializeTelemetryListeners(); this.configurationClient = new ConfigurationClient(context, TelemetryUtils.createFullUserAgent(userAgent, - context), accessToken, new OkHttpClient()); + context), accessToken, new OkHttpClient()); this.certificateBlacklist = new CertificateBlacklist(context, configurationClient); } @@ -165,6 +166,7 @@ private void initializeTelemetryClient() { private TelemetryClient createTelemetryClient(String accessToken, String userAgent) { String fullUserAgent = TelemetryUtils.createFullUserAgent(userAgent, applicationContext); + TelemetryClientFactory telemetryClientFactory = new TelemetryClientFactory(accessToken, fullUserAgent, new Logger(), certificateBlacklist); telemetryClient = telemetryClientFactory.obtainTelemetryClient(applicationContext); diff --git a/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryClient.java b/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryClient.java index 1116dcbc3..8ff9d5f2b 100644 --- a/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryClient.java +++ b/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryClient.java @@ -27,6 +27,7 @@ class TelemetryClient { private static final String EVENTS_ENDPOINT = "/events/v2"; private static final String ATTACHMENTS_ENDPOINT = "/attachments/v1"; private static final String USER_AGENT_REQUEST_HEADER = "User-Agent"; + private static final String MAPBOX_AGENT_REQUEST_HEADER = "X-Mapbox-Agent"; private static final String ACCESS_TOKEN_QUERY_PARAMETER = "access_token"; private static final String EXTRA_DEBUGGING_LOG = "Sending POST to %s with %d event(s) (user agent: %s) " + "with payload: %s"; @@ -34,14 +35,16 @@ class TelemetryClient { private String accessToken; private String userAgent; + private String reformedUserAgent; private TelemetryClientSettings setting; private final Logger logger; private CertificateBlacklist certificateBlacklist; - TelemetryClient(String accessToken, String userAgent, TelemetryClientSettings setting, Logger logger, - CertificateBlacklist certificateBlacklist) { + TelemetryClient(String accessToken, String userAgent, String reformedUserAgent, TelemetryClientSettings setting, + Logger logger, CertificateBlacklist certificateBlacklist) { this.accessToken = accessToken; this.userAgent = userAgent; + this.reformedUserAgent = reformedUserAgent; this.setting = setting; this.logger = logger; this.certificateBlacklist = certificateBlacklist; @@ -96,6 +99,7 @@ void sendAttachment(Attachment attachment, final CopyOnWriteArraySet batch, Callback callback, boolean serializeNu Request request = new Request.Builder() .url(url) .header(USER_AGENT_REQUEST_HEADER, userAgent) + .addHeader(MAPBOX_AGENT_REQUEST_HEADER, reformedUserAgent) .post(body) .build(); diff --git a/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryClientFactory.java b/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryClientFactory.java index 2c70cc22a..fab9765ed 100644 --- a/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryClientFactory.java +++ b/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryClientFactory.java @@ -38,9 +38,8 @@ private TelemetryClient buildTelemetryClient(Environment environment, CertificateBlacklist certificateBlacklist, Context context) { return new TelemetryClient(accessToken, userAgent, - new TelemetryClientSettings.Builder(context) - .environment(environment) - .build(), + TelemetryUtils.createReformedFullUserAgent(context), new TelemetryClientSettings.Builder(context) + .environment(environment).build(), logger, certificateBlacklist); } @@ -51,8 +50,9 @@ private TelemetryClient buildTelemetryClientCustom(ServerInformation serverInfor .environment(serverInformation.getEnvironment()) .baseUrl(TelemetryClientSettings.configureUrlHostname(serverInformation.getHostname())) .build(); - return new TelemetryClient(serverInformation.getAccessToken(), userAgent, telemetryClientSettings, logger, - certificateBlacklist); + return new TelemetryClient(serverInformation.getAccessToken(), userAgent, + TelemetryUtils.createReformedFullUserAgent(context), + telemetryClientSettings, logger, certificateBlacklist); } private TelemetryClient buildClientFrom(ServerInformation serverInformation, Context context) { diff --git a/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryUtils.java b/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryUtils.java index 7d0a66baf..d00504988 100644 --- a/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryUtils.java +++ b/libtelemetry/src/main/java/com/mapbox/android/telemetry/TelemetryUtils.java @@ -9,6 +9,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.BatteryManager; +import android.os.Build; import android.support.annotation.Nullable; import android.telephony.TelephonyManager; import android.text.TextUtils; @@ -22,6 +23,9 @@ import java.util.UUID; import android.util.Log; + +import com.mapbox.android.core.MapboxSdkInfoForUserAgentGenerator; + import okio.Buffer; import static com.mapbox.android.telemetry.MapboxTelemetryConstants.MAPBOX_SHARED_PREFERENCES; @@ -32,6 +36,8 @@ public class TelemetryUtils { private static final String KEY_META_DATA_WAKE_UP = "com.mapbox.AdjustWakeUp"; private static final String DATE_AND_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; private static final String EMPTY_STRING = ""; + private static final String USER_AGENT_APP_ID_FORMAT = "%s/%s (%s; %s; %s)"; + private static final String USER_AGENT_VERSION_CODE_FORMAT = "v%d"; private static final String TWO_STRING_FORMAT = "%s %s"; private static final String THREE_STRING_FORMAT = "%s/%s/%s"; private static final SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_AND_TIME_PATTERN, Locale.US); @@ -58,6 +64,7 @@ public class TelemetryUtils { private static final String LONG_TERM_EVOLUTION = "LTE"; private static final String UNIVERSAL_MOBILE_TELCO_SERVICE = "UMTS"; private static final String UNKNOWN = "Unknown"; + private static final String OPERATING_SYSTEM = "Android - " + Build.VERSION.RELEASE; private static final Map NETWORKS = new HashMap() { { put(TelephonyManager.NETWORK_TYPE_1xRTT, SINGLE_CARRIER_RTT); @@ -167,6 +174,13 @@ static String createFullUserAgent(String userAgent, Context context) { return fullUserAgent; } + static String createReformedFullUserAgent(Context context) { + String appIdentifier = TelemetryUtils.obtainApplicationIdentifierForReformedUserAgent(context); + String reformedUserAgent = toHumanReadableAscii(String.format(DEFAULT_LOCALE, TWO_STRING_FORMAT, appIdentifier, + MapboxSdkInfoForUserAgentGenerator.getInstance(context.getAssets()).getSdkInfoForUserAgent())); + return TextUtils.isEmpty(reformedUserAgent) ? appIdentifier : reformedUserAgent; + } + static boolean isEmpty(String string) { if (string == null || string.length() == 0) { return true; @@ -221,9 +235,36 @@ private static String obtainApplicationIdentifier(Context context) { } } + private static String obtainApplicationIdentifierForReformedUserAgent(Context context) { + try { + String packageName = context.getPackageName(); + PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName, 0); + String versionCode = String.format(DEFAULT_LOCALE, USER_AGENT_VERSION_CODE_FORMAT, packageInfo.versionCode); + String version = (packageInfo.versionName == null) ? "0" : packageInfo.versionName; + String appIdentifier = String.format(DEFAULT_LOCALE, USER_AGENT_APP_ID_FORMAT, + getApplicationName(context), version, packageName, versionCode, OPERATING_SYSTEM); + return appIdentifier; + } catch (Exception exception) { + return EMPTY_STRING; + } + } + + private static String getApplicationName(Context context) { + final PackageManager packagemanager = context.getApplicationContext().getPackageManager(); + ApplicationInfo applicationInfo; + try { + applicationInfo = packagemanager.getApplicationInfo(context.getPackageName(), 0); + } catch (final PackageManager.NameNotFoundException nameNotFoundException) { + applicationInfo = null; + } + String unknown = "(unknown)"; + return (String) (applicationInfo != null ? packagemanager.getApplicationLabel(applicationInfo) : unknown); + } + /** * This method can return null on devices without * any battery (like a TV) or because of buggy firmware. + * * @param context application context * @return intent */ @@ -233,7 +274,7 @@ private static Intent registerBatteryUpdates(Context context) { return context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); } catch (Exception exc) { // There is a weird intermittent bug that causes SecurityException in android versions <= 4.2 - Log.e(TAG, String.format("%s: Failed receiver registration for ACTION_BATTERY_CHANGED", exc.toString())); + Log.e(TAG, String.format("%s: Failed receiver registration for ACTION_BATTERY_CHANGED", exc.toString())); return null; } } diff --git a/libtelemetry/src/test/java/com/mapbox/android/telemetry/MockWebServerTest.java b/libtelemetry/src/test/java/com/mapbox/android/telemetry/MockWebServerTest.java index e0cec2565..fe8538429 100644 --- a/libtelemetry/src/test/java/com/mapbox/android/telemetry/MockWebServerTest.java +++ b/libtelemetry/src/test/java/com/mapbox/android/telemetry/MockWebServerTest.java @@ -147,11 +147,13 @@ String obtainContentFromFile(String fileName) throws IOException { return stringBuilder.toString(); } - TelemetryClient obtainATelemetryClient(String accessToken, String userAgent, Context context) { + TelemetryClient obtainATelemetryClient(String accessToken, String userAgent, + String reformedUserAgent, Context context) { TelemetryClientSettings telemetryClientSettings = provideDefaultTelemetryClientSettings(context); Logger mockedLogger = mock(Logger.class); CertificateBlacklist mockedBlacklist = mock(CertificateBlacklist.class); - return new TelemetryClient(accessToken, userAgent, telemetryClientSettings, mockedLogger, mockedBlacklist); + return new TelemetryClient(accessToken, userAgent, reformedUserAgent, + telemetryClientSettings, mockedLogger, mockedBlacklist); } List obtainAnEvent() { diff --git a/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientAppUserTurnstileEventTest.java b/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientAppUserTurnstileEventTest.java index f905d4a89..436868499 100644 --- a/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientAppUserTurnstileEventTest.java +++ b/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientAppUserTurnstileEventTest.java @@ -19,8 +19,9 @@ public class TelemetryClientAppUserTurnstileEventTest extends MockWebServerTest public void sendsTheCorrectBodyPostingAppUserTurnstileEvent() throws Exception { Context mockedContext = TelemetryClientTest.getMockedContext(); MapboxTelemetry.applicationContext = mockedContext; - TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent", - mockedContext); + String anyUserAgent = "anyUserAgent"; + TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", anyUserAgent, + anyUserAgent , mockedContext); Event anAppUserTurnstile = new AppUserTurnstile("anySdkIdentifier", "anySdkVersion", false); List theAppUserTurnstile = obtainEvents(anAppUserTurnstile); Callback mockedCallback = mock(Callback.class); diff --git a/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientFactoryTest.java b/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientFactoryTest.java index 4ab1bbde6..b42bb7460 100644 --- a/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientFactoryTest.java +++ b/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientFactoryTest.java @@ -18,14 +18,15 @@ public class TelemetryClientFactoryTest { + @Test public void checksChinaEnvironment() throws Exception { String anyAccessToken = "anyAccessToken"; String anyUserAgent = "anyUserAgent"; Logger mockedLogger = mock(Logger.class); CertificateBlacklist mockedBlacklist = mock(CertificateBlacklist.class); - TelemetryClientFactory telemetryClientFactory = new TelemetryClientFactory(anyAccessToken, anyUserAgent, - mockedLogger, mockedBlacklist); + TelemetryClientFactory telemetryClientFactory = new TelemetryClientFactory(anyAccessToken, + anyUserAgent, mockedLogger, mockedBlacklist); Bundle mockedBundle = mock(Bundle.class); when(mockedBundle .getBoolean(eq("com.mapbox.CnEventsServer"))) @@ -61,8 +62,8 @@ public void checksStagingAppInfoHostname() throws Exception { String anyUserAgent = "anyUserAgent"; Logger mockedLogger = mock(Logger.class); CertificateBlacklist mockedBlacklist = mock(CertificateBlacklist.class); - TelemetryClientFactory telemetryClientFactory = new TelemetryClientFactory(anyAccessToken, anyUserAgent, - mockedLogger, mockedBlacklist); + TelemetryClientFactory telemetryClientFactory = new TelemetryClientFactory(anyAccessToken, + anyUserAgent, mockedLogger, mockedBlacklist); String theAppInfoHostname = "the.app.info.hostname"; String anyAppInfoAccessToken = "anyAppInfoAccessToken"; Bundle mockedBundle = obtainStagingBundle(theAppInfoHostname, anyAppInfoAccessToken); diff --git a/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientLocationEventTest.java b/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientLocationEventTest.java index edf6e405c..66a7c3eae 100644 --- a/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientLocationEventTest.java +++ b/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientLocationEventTest.java @@ -26,7 +26,7 @@ public void sendsTheCorrectBodyPostingLocationEvent() throws Exception { when(mockedContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(mockedActivityManager); TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent", - mockedContext); + "reformedUserAgent", mockedContext); double aLatitude = 40.416775; double aLongitude = -3.703790; Event aLocationEvent = new LocationEvent("aSessionId", aLatitude, aLongitude, ""); diff --git a/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientTest.java b/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientTest.java index 70d86bdf2..c116c8fe9 100644 --- a/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientTest.java +++ b/libtelemetry/src/test/java/com/mapbox/android/telemetry/TelemetryClientTest.java @@ -4,6 +4,7 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; + import com.google.gson.Gson; import org.junit.Test; @@ -41,11 +42,13 @@ public class TelemetryClientTest extends MockWebServerTest { + private static final String REFORMED_USER_AGENT = "reformedUserAgent"; + @Test public void sendsContentTypeHeader() throws Exception { - MapboxTelemetry.applicationContext = getMockedContext(); + MapboxTelemetry.applicationContext = getMockedContext(); TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent", - MapboxTelemetry.applicationContext); + REFORMED_USER_AGENT, MapboxTelemetry.applicationContext); List mockedEvent = obtainAnEvent(); Callback mockedCallback = mock(Callback.class); enqueueMockResponse(); @@ -57,9 +60,9 @@ public void sendsContentTypeHeader() throws Exception { @Test public void sendsContentEncodingHeader() throws Exception { - MapboxTelemetry.applicationContext = getMockedContext(); + MapboxTelemetry.applicationContext = getMockedContext(); TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent", - MapboxTelemetry.applicationContext); + REFORMED_USER_AGENT, MapboxTelemetry.applicationContext); List mockedEvent = obtainAnEvent(); Callback mockedCallback = mock(Callback.class); enqueueMockResponse(); @@ -71,9 +74,9 @@ public void sendsContentEncodingHeader() throws Exception { @Test public void sendsPostEventRequestWithTheCorrectAccessTokenParameter() throws Exception { - MapboxTelemetry.applicationContext = getMockedContext(); + MapboxTelemetry.applicationContext = getMockedContext(); TelemetryClient telemetryClient = obtainATelemetryClient("theAccessToken", "anyUserAgent", - MapboxTelemetry.applicationContext); + REFORMED_USER_AGENT, MapboxTelemetry.applicationContext); List mockedEvent = obtainAnEvent(); Callback mockedCallback = mock(Callback.class); enqueueMockResponse(); @@ -86,8 +89,8 @@ public void sendsPostEventRequestWithTheCorrectAccessTokenParameter() throws Exc @Test public void sendsUserAgentHeader() throws Exception { MapboxTelemetry.applicationContext = getMockedContext(); - TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "theUserAgent", - MapboxTelemetry.applicationContext); + TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", + "theUserAgent", REFORMED_USER_AGENT, MapboxTelemetry.applicationContext); List mockedEvent = obtainAnEvent(); Callback mockedCallback = mock(Callback.class); enqueueMockResponse(); @@ -97,11 +100,25 @@ public void sendsUserAgentHeader() throws Exception { assertRequestContainsHeader("User-Agent", "theUserAgent"); } + @Test + public void sendsReformedUserAgentHeader() throws Exception { + MapboxTelemetry.applicationContext = getMockedContext(); + TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", + "theUserAgent", REFORMED_USER_AGENT, MapboxTelemetry.applicationContext); + List mockedEvent = obtainAnEvent(); + Callback mockedCallback = mock(Callback.class); + enqueueMockResponse(); + + telemetryClient.sendEvents(mockedEvent, mockedCallback, false); + + assertRequestContainsHeader("X-Mapbox-Agent", REFORMED_USER_AGENT); + } + @Test public void sendsPostEventRequestToTheCorrectEndpoint() throws Exception { - MapboxTelemetry.applicationContext = getMockedContext(); - TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent", - MapboxTelemetry.applicationContext); + MapboxTelemetry.applicationContext = getMockedContext(); + TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", + "anyUserAgent", REFORMED_USER_AGENT, MapboxTelemetry.applicationContext); List mockedEvent = obtainAnEvent(); Callback mockedCallback = mock(Callback.class); enqueueMockResponse(); @@ -113,9 +130,9 @@ public void sendsPostEventRequestToTheCorrectEndpoint() throws Exception { @Test public void sendsTheCorrectBodyPostingAnEvent() throws Exception { - MapboxTelemetry.applicationContext = getMockedContext(); - TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent", - MapboxTelemetry.applicationContext); + MapboxTelemetry.applicationContext = getMockedContext(); + TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", + "anyUserAgent", REFORMED_USER_AGENT, MapboxTelemetry.applicationContext); List theEvent = obtainAnEvent(); Callback mockedCallback = mock(Callback.class); enqueueMockResponse(); @@ -129,9 +146,9 @@ public void sendsTheCorrectBodyPostingAnEvent() throws Exception { @Test public void receivesNoBodyPostingAnEventSuccessfully() throws Exception { - MapboxTelemetry.applicationContext = getMockedContext(); - TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent", - MapboxTelemetry.applicationContext); + MapboxTelemetry.applicationContext = getMockedContext(); + TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", + "anyUserAgent", REFORMED_USER_AGENT, MapboxTelemetry.applicationContext); List theEvent = obtainAnEvent(); Callback mockedCallback = mock(Callback.class); enqueueMockNoResponse(204); @@ -143,9 +160,9 @@ public void receivesNoBodyPostingAnEventSuccessfully() throws Exception { @Test public void parsesUnauthorizedRequestResponseProperlyPostingAnEvent() throws Exception { - MapboxTelemetry.applicationContext = getMockedContext(); - TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent", - MapboxTelemetry.applicationContext); + MapboxTelemetry.applicationContext = getMockedContext(); + TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", + "anyUserAgent", REFORMED_USER_AGENT, MapboxTelemetry.applicationContext); List theEvent = obtainAnEvent(); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference bodyRef = new AtomicReference<>(); @@ -163,9 +180,9 @@ public void parsesUnauthorizedRequestResponseProperlyPostingAnEvent() throws Exc @Test public void parsesInvalidMessageBodyResponseProperlyPostingAnEvent() throws Exception { - MapboxTelemetry.applicationContext = getMockedContext();; - TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent", - MapboxTelemetry.applicationContext); + MapboxTelemetry.applicationContext = getMockedContext(); + TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", + "anyUserAgent", REFORMED_USER_AGENT, MapboxTelemetry.applicationContext); List theEvent = obtainAnEvent(); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference bodyRef = new AtomicReference<>(); @@ -201,7 +218,9 @@ public boolean verify(String hostname, SSLSession session) { } }) .build(); - TelemetryClient telemetryClient = new TelemetryClient("anyAccessToken", "anyUserAgent", telemetryClientSettings, + String anyUserAgent = "anyUserAgent"; + TelemetryClient telemetryClient = new TelemetryClient("anyAccessToken", anyUserAgent, anyUserAgent, + telemetryClientSettings, mock(Logger.class), mock(CertificateBlacklist.class)); List theEvent = obtainAnEvent(); final CountDownLatch latch = new CountDownLatch(1); @@ -224,9 +243,9 @@ public void checksDebugLoggingEnabledBatch() throws Exception { Logger mockedLogger = mock(Logger.class); List mockedEvent = obtainAnEvent(); Callback mockedCallback = mock(Callback.class); - - TelemetryClient telemetryClient = new TelemetryClient("anyAccessToken", "anyUserAgent", clientSettings, - mockedLogger, mock(CertificateBlacklist.class)); + String anyUserAgent = "anyUserAgent"; + TelemetryClient telemetryClient = new TelemetryClient("anyAccessToken", anyUserAgent, anyUserAgent, + clientSettings, mockedLogger, mock(CertificateBlacklist.class)); telemetryClient.updateDebugLoggingEnabled(true); telemetryClient.sendEvents(mockedEvent, mockedCallback, false); @@ -241,9 +260,9 @@ public void checksDebugLoggingEnabledAttachment() throws Exception { MapboxTelemetry.applicationContext = mockedContext; TelemetryClientSettings clientSettings = provideDefaultTelemetryClientSettings(mockedContext); Logger mockedLogger = mock(Logger.class); - - TelemetryClient telemetryClient = new TelemetryClient("anyAccessToken", "anyUserAgent", clientSettings, - mockedLogger, mock(CertificateBlacklist.class)); + String anyUserAgent = "anyUserAgent"; + TelemetryClient telemetryClient = new TelemetryClient("anyAccessToken", anyUserAgent, anyUserAgent, + clientSettings, mockedLogger, mock(CertificateBlacklist.class)); telemetryClient.updateDebugLoggingEnabled(true); AttachmentListener attachmentListener = mock(AttachmentListener.class); @@ -261,8 +280,8 @@ public void checksDebugLoggingEnabledAttachment() throws Exception { public void checksSetBaseUrl() throws Exception { TelemetryClientSettings clientSettings = provideDefaultTelemetryClientSettings(getMockedContext()); Logger mockedLogger = mock(Logger.class); - TelemetryClient telemetryClient = new TelemetryClient("", "", clientSettings, - mockedLogger, mock(CertificateBlacklist.class)); + TelemetryClient telemetryClient = new TelemetryClient("", "", "", clientSettings, + mockedLogger, mock(CertificateBlacklist.class)); String newUrl = "new-custom-url.com"; telemetryClient.setBaseUrl(newUrl); diff --git a/libtelemetry/src/testFull/java/com/mapbox/android/telemetry/MapboxTelemetryTest.java b/libtelemetry/src/testFull/java/com/mapbox/android/telemetry/MapboxTelemetryTest.java index f299d89d8..cd7efccf4 100644 --- a/libtelemetry/src/testFull/java/com/mapbox/android/telemetry/MapboxTelemetryTest.java +++ b/libtelemetry/src/testFull/java/com/mapbox/android/telemetry/MapboxTelemetryTest.java @@ -403,18 +403,32 @@ public void checkFlushIsCalled() { } @Test - public void checksSetBaseUrlWithValidHost() throws Exception { + public void checksSetBaseUrlWithValidHostAndWithConnection() throws Exception { + Context mockedContext = obtainNetworkConnectedMockedContext(); TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); - MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedTelemetryClient); - theMapboxTelemetry.setBaseUrl(DEFAULT_STAGING_EVENTS_HOST); + Callback mockedHttpCallback = mock(Callback.class); + MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedContext, mockedTelemetryClient, + mockedHttpCallback); + assertTrue(theMapboxTelemetry.setBaseUrl(DEFAULT_STAGING_EVENTS_HOST)); verify(mockedTelemetryClient, times(1)).setBaseUrl(eq(DEFAULT_STAGING_EVENTS_HOST)); } + @Test + public void checksSetBaseUrlWithValidHostAndWithoutConnection() throws Exception { + Context mockedContext = obtainNetworkNotConnectedMockedContext(); + TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); + Callback mockedHttpCallback = mock(Callback.class); + MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedContext, mockedTelemetryClient, + mockedHttpCallback); + assertFalse(theMapboxTelemetry.setBaseUrl(DEFAULT_STAGING_EVENTS_HOST)); + verify(mockedTelemetryClient, never()).setBaseUrl(eq(DEFAULT_STAGING_EVENTS_HOST)); + } + @Test public void checksSetBaseUrlWithNullHost() throws Exception { TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedTelemetryClient); - theMapboxTelemetry.setBaseUrl(null); + assertFalse(theMapboxTelemetry.setBaseUrl(null)); verify(mockedTelemetryClient, never()).setBaseUrl(any(String.class)); } @@ -422,7 +436,7 @@ public void checksSetBaseUrlWithNullHost() throws Exception { public void checksSetBaseUrlWithEmptyHost() throws Exception { TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedTelemetryClient); - theMapboxTelemetry.setBaseUrl(""); + assertFalse(theMapboxTelemetry.setBaseUrl("")); verify(mockedTelemetryClient, never()).setBaseUrl(any(String.class)); } @@ -430,7 +444,7 @@ public void checksSetBaseUrlWithEmptyHost() throws Exception { public void checksSetBaseUrlWithInvalidHostOne() throws Exception { TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedTelemetryClient); - theMapboxTelemetry.setBaseUrl("h@st.com"); + assertFalse(theMapboxTelemetry.setBaseUrl("h@st.com")); verify(mockedTelemetryClient, never()).setBaseUrl(any(String.class)); } @@ -438,7 +452,7 @@ public void checksSetBaseUrlWithInvalidHostOne() throws Exception { public void checksSetBaseUrlWithInvalidHostTwo() throws Exception { TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedTelemetryClient); - theMapboxTelemetry.setBaseUrl("new host.com"); + assertFalse(theMapboxTelemetry.setBaseUrl("new host.com")); verify(mockedTelemetryClient, never()).setBaseUrl(any(String.class)); } @@ -446,7 +460,7 @@ public void checksSetBaseUrlWithInvalidHostTwo() throws Exception { public void checksSetBaseUrlWithInvalidHostThree() throws Exception { TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedTelemetryClient); - theMapboxTelemetry.setBaseUrl("host..com"); + assertFalse(theMapboxTelemetry.setBaseUrl("host..com")); verify(mockedTelemetryClient, never()).setBaseUrl(any(String.class)); } @@ -454,7 +468,7 @@ public void checksSetBaseUrlWithInvalidHostThree() throws Exception { public void checksSetBaseUrlWithInvalidHostFour() throws Exception { TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedTelemetryClient); - theMapboxTelemetry.setBaseUrl("host.c"); + assertFalse(theMapboxTelemetry.setBaseUrl("host.c")); verify(mockedTelemetryClient, never()).setBaseUrl(any(String.class)); } @@ -462,7 +476,7 @@ public void checksSetBaseUrlWithInvalidHostFour() throws Exception { public void checksSetBaseUrlWithInvalidHostFive() throws Exception { TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedTelemetryClient); - theMapboxTelemetry.setBaseUrl("host.com."); + assertFalse(theMapboxTelemetry.setBaseUrl("host.com.")); verify(mockedTelemetryClient, never()).setBaseUrl(any(String.class)); }