Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Increase SDK test coverage #8261

Merged
merged 1 commit into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions platform/android/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ dependencies {
compile rootProject.ext.dep.timber
compile rootProject.ext.dep.okhttp3
compile rootProject.ext.dep.lost
testCompile rootProject.ext.dep.junit
testCompile rootProject.ext.dep.mockito

// Mapbox Android Services (GeoJSON support)
compile(rootProject.ext.dep.mapboxJavaGeoJSON) {
Expand Down Expand Up @@ -113,6 +115,10 @@ android {
warningsAsErrors true
}

testOptions {
unitTests.returnDefaultValues = true
}

buildTypes {
debug {
jniDebuggable true
Expand Down Expand Up @@ -141,3 +147,4 @@ configurations {
apply from: 'gradle-javadoc.gradle'
apply from: 'gradle-publish.gradle'
apply from: 'gradle-checkstyle.gradle'
apply from: 'gradle-tests-staticblockremover.gradle'
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
buildscript {
repositories {
mavenCentral()
mavenLocal()
}

dependencies {
classpath 'com.darylteo.gradle:javassist-plugin:0.4.1'
}
}

import com.darylteo.gradle.javassist.tasks.TransformationTask
import com.darylteo.gradle.javassist.transformers.ClassTransformer
import javassist.CtClass
import javassist.CtConstructor

class StaticBlockRemover extends ClassTransformer {

private static final NATIVE_MAP_VIEW = "com.mapbox.mapboxsdk.maps.NativeMapView";
private static
final NATIVE_CONNECTIVITY_LISTENER = "com.mapbox.mapboxsdk.net.NativeConnectivityListener";
private static final OFFLINE_MANAGER = "com.mapbox.mapboxsdk.offline.OfflineManager";
private static final OFFLINE_REGION = "com.mapbox.mapboxsdk.offline.OfflineRegion";

public void applyTransformations(CtClass clazz) throws Exception {
if (shouldFilter(clazz)) {
CtConstructor constructor = clazz.getClassInitializer()
if (constructor != null) {
clazz.removeConstructor(constructor)
}
}
}

public boolean shouldFilter(CtClass clazz) {
return hasAStaticBlock(clazz);
}

private boolean hasAStaticBlock(CtClass clazz) {
String name = clazz.getName();
boolean isNativeMapView = name.equals(NATIVE_MAP_VIEW);
boolean isNativeConnectivityListener = name.equals(NATIVE_CONNECTIVITY_LISTENER);
boolean isOfflineManager = name.equals(OFFLINE_MANAGER);
boolean isOfflineRegion = name.equals(OFFLINE_REGION);

return isNativeMapView || isNativeConnectivityListener || isOfflineManager || isOfflineRegion;
}
}

task removeStatic(type: TransformationTask) {
// TODO Find a better way to get output classes path
String fromToDirPath = buildDir.getAbsolutePath() + "/intermediates/classes/debug"
from fromToDirPath
transformation = new StaticBlockRemover()
into fromToDirPath
}

afterEvaluate {
compileDebugUnitTestSources.dependsOn(removeStatic)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mapbox.mapboxsdk;

/**
* Centralises the knowledge about "mapbox-gl" library loading.
*/
public class LibraryLoader {

/**
* Loads "libmapbox-gl.so" native shared library.
*/
public static void load() {
System.loadLibrary("mapbox-gl");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.mapbox.mapboxsdk.maps;


import android.support.annotation.NonNull;
import android.support.v4.util.LongSparseArray;

import com.mapbox.mapboxsdk.annotations.Annotation;

import java.util.ArrayList;
import java.util.List;

/**
* Encapsulates {@link Annotation}'s functionality..
*/
class AnnotationContainer implements Annotations {

private final NativeMapView nativeMapView;
private final LongSparseArray<Annotation> annotations;

AnnotationContainer(NativeMapView nativeMapView, LongSparseArray<Annotation> annotations) {
this.nativeMapView = nativeMapView;
this.annotations = annotations;
}

@Override
public Annotation obtainBy(long id) {
return annotations.get(id);
}

@Override
public List<Annotation> obtainAll() {
List<Annotation> annotations = new ArrayList<>();
for (int i = 0; i < this.annotations.size(); i++) {
annotations.add(this.annotations.get(this.annotations.keyAt(i)));
}
return annotations;
}

@Override
public void removeBy(long id) {
if (nativeMapView != null) {
nativeMapView.removeAnnotation(id);
}
annotations.remove(id);
}

@Override
public void removeBy(@NonNull Annotation annotation) {
long id = annotation.getId();
removeBy(id);
}

@Override
public void removeBy(@NonNull List<? extends Annotation> annotationList) {
int count = annotationList.size();
long[] ids = new long[count];
for (int i = 0; i < count; i++) {
ids[i] = annotationList.get(i).getId();
}

removeNativeAnnotations(ids);

for (long id : ids) {
annotations.remove(id);
}
}

@Override
public void removeAll() {
int count = annotations.size();
long[] ids = new long[count];
for (int i = 0; i < count; i++) {
ids[i] = annotations.keyAt(i);
}

removeNativeAnnotations(ids);

annotations.clear();
}

private void removeNativeAnnotations(long[] ids) {
if (nativeMapView != null) {
nativeMapView.removeAnnotations(ids);
}
}
}
Loading