From 2f52501296d683f220f831128de04ab1117e09d2 Mon Sep 17 00:00:00 2001 From: Chuck Greb Date: Tue, 14 Jul 2015 14:41:58 -0400 Subject: [PATCH] Robolectric 3.0 Minor API changes. Simplifies custom shadow config. --- app/build.gradle | 2 +- .../erasermap/PrivateMapsTestRunner.java | 28 ++++--------------- .../erasermap/view/DistanceViewTest.java | 2 +- .../view/InstructionListActivityTest.java | 2 +- .../erasermap/view/MainActivityTest.java | 8 +++--- .../erasermap/view/RouteModeViewTest.java | 2 +- .../erasermap/view/RoutePreviewViewTest.java | 2 +- .../view/SearchResultsAdapterTest.java | 2 +- .../view/SearchResultsListActivityTest.java | 2 +- .../erasermap/view/SearchResultsViewTest.java | 2 +- 10 files changed, 18 insertions(+), 34 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 461a990c..bdb01201 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -83,7 +83,7 @@ dependencies { testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.9.5' testCompile 'org.assertj:assertj-core:1.7.0' - testCompile('org.robolectric:robolectric:3.0-rc2') { + testCompile('org.robolectric:robolectric:3.0') { exclude group: 'commons-logging', module: 'commons-logging' exclude group: 'org.apache.httpcomponents', module: 'httpclient' } diff --git a/app/src/test/java/com/mapzen/erasermap/PrivateMapsTestRunner.java b/app/src/test/java/com/mapzen/erasermap/PrivateMapsTestRunner.java index d785e235..6777f6fb 100644 --- a/app/src/test/java/com/mapzen/erasermap/PrivateMapsTestRunner.java +++ b/app/src/test/java/com/mapzen/erasermap/PrivateMapsTestRunner.java @@ -2,25 +2,15 @@ import com.mapzen.erasermap.shadows.ShadowGLSurfaceView; import com.mapzen.erasermap.shadows.ShadowMapController; -import com.mapzen.erasermap.shadows.ShadowPorterDuffColorFilter; import com.mapzen.erasermap.shadows.ShadowMapView; +import com.mapzen.erasermap.shadows.ShadowPorterDuffColorFilter; import org.junit.runners.model.InitializationError; import org.robolectric.RobolectricGradleTestRunner; -import org.robolectric.internal.bytecode.ClassInfo; -import org.robolectric.internal.bytecode.InstrumentingClassLoaderConfig; +import org.robolectric.internal.bytecode.InstrumentationConfiguration; import org.robolectric.internal.bytecode.ShadowMap; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - public class PrivateMapsTestRunner extends RobolectricGradleTestRunner { - private static final List CUSTOM_SHADOW_TARGETS = - Collections.unmodifiableList(Arrays.asList( - "com.mapzen.tangram.MapView", - "com.mapzen.tangram.MapController" - )); public PrivateMapsTestRunner(Class klass) throws InitializationError { super(klass); @@ -38,15 +28,9 @@ protected ShadowMap createShadowMap() { } @Override - public InstrumentingClassLoaderConfig createSetup() { - return new PrivateMapsInstrumentingClassLoaderConfig(); - } - - public class PrivateMapsInstrumentingClassLoaderConfig extends InstrumentingClassLoaderConfig { - @Override - public boolean shouldInstrument(ClassInfo classInfo) { - return CUSTOM_SHADOW_TARGETS.contains(classInfo.getName()) - || super.shouldInstrument(classInfo); - } + public InstrumentationConfiguration createClassLoaderConfig() { + return InstrumentationConfiguration.newBuilder() + .addInstrumentedPackage("com.mapzen.tangram") + .build(); } } diff --git a/app/src/test/java/com/mapzen/erasermap/view/DistanceViewTest.java b/app/src/test/java/com/mapzen/erasermap/view/DistanceViewTest.java index 34c9ad45..e417dcd3 100644 --- a/app/src/test/java/com/mapzen/erasermap/view/DistanceViewTest.java +++ b/app/src/test/java/com/mapzen/erasermap/view/DistanceViewTest.java @@ -14,7 +14,7 @@ import static org.robolectric.RuntimeEnvironment.application; @RunWith(PrivateMapsTestRunner.class) -@Config(constants = BuildConfig.class, emulateSdk = 21) +@Config(constants = BuildConfig.class, sdk = 21) public class DistanceViewTest { private DistanceView distanceView; diff --git a/app/src/test/java/com/mapzen/erasermap/view/InstructionListActivityTest.java b/app/src/test/java/com/mapzen/erasermap/view/InstructionListActivityTest.java index 1b3e36ea..c8893dc6 100644 --- a/app/src/test/java/com/mapzen/erasermap/view/InstructionListActivityTest.java +++ b/app/src/test/java/com/mapzen/erasermap/view/InstructionListActivityTest.java @@ -27,7 +27,7 @@ import static org.robolectric.Shadows.shadowOf; @RunWith(PrivateMapsTestRunner.class) -@Config(constants = BuildConfig.class, emulateSdk = 21) +@Config(constants = BuildConfig.class, sdk = 21) public class InstructionListActivityTest { private static MainActivity startActivity = Robolectric.setupActivity(MainActivity.class); private InstructionListActivity activity; diff --git a/app/src/test/java/com/mapzen/erasermap/view/MainActivityTest.java b/app/src/test/java/com/mapzen/erasermap/view/MainActivityTest.java index 5a7df12c..53d46df8 100644 --- a/app/src/test/java/com/mapzen/erasermap/view/MainActivityTest.java +++ b/app/src/test/java/com/mapzen/erasermap/view/MainActivityTest.java @@ -42,7 +42,7 @@ import static org.robolectric.Shadows.shadowOf; @RunWith(PrivateMapsTestRunner.class) -@Config(constants = BuildConfig.class, emulateSdk = 21) +@Config(constants = BuildConfig.class, sdk = 21) public class MainActivityTest { private MainActivity activity; private LocationManager locationManager; @@ -236,7 +236,7 @@ public void showRoutePreview_shouldHideActionBar() throws Exception { activity.getSupportActionBar().show(); activity.showRoutePreview(getTestFeature()); activity.success(new Route(new JSONObject())); - Robolectric.flushForegroundScheduler(); + Robolectric.flushForegroundThreadScheduler(); assertThat(activity.getSupportActionBar().isShowing()).isFalse(); } @@ -245,7 +245,7 @@ public void showRoutePreview_shouldShowRoutePreviewView() throws Exception { activity.findViewById(R.id.route_preview).setVisibility(GONE); activity.showRoutePreview(getTestFeature()); activity.success(new Route(new JSONObject())); - Robolectric.flushForegroundScheduler(); + Robolectric.flushForegroundThreadScheduler(); assertThat(activity.findViewById(R.id.route_preview).getVisibility()).isEqualTo(VISIBLE); } @@ -254,7 +254,7 @@ public void onRestoreViewState_shouldRestoreRoutingPreview() { activity.findViewById(R.id.route_preview).setVisibility(GONE); activity.showRoutePreview(getTestFeature()); activity.success(new Route(new JSONObject())); - Robolectric.flushForegroundScheduler(); + Robolectric.flushForegroundThreadScheduler(); activity.getPresenter().onRestoreViewState(); assertThat(activity.findViewById(R.id.route_preview).getVisibility()).isEqualTo(VISIBLE); } diff --git a/app/src/test/java/com/mapzen/erasermap/view/RouteModeViewTest.java b/app/src/test/java/com/mapzen/erasermap/view/RouteModeViewTest.java index 2f4947b6..0e49e6a3 100644 --- a/app/src/test/java/com/mapzen/erasermap/view/RouteModeViewTest.java +++ b/app/src/test/java/com/mapzen/erasermap/view/RouteModeViewTest.java @@ -27,7 +27,7 @@ import static org.robolectric.RuntimeEnvironment.application; @RunWith(PrivateMapsTestRunner.class) -@Config(constants = BuildConfig.class, emulateSdk = 21) +@Config(constants = BuildConfig.class, sdk = 21) public class RouteModeViewTest { InstructionAdapter adapter; RouteModeView routeModeView; diff --git a/app/src/test/java/com/mapzen/erasermap/view/RoutePreviewViewTest.java b/app/src/test/java/com/mapzen/erasermap/view/RoutePreviewViewTest.java index 4c4f3c0c..57aa8731 100644 --- a/app/src/test/java/com/mapzen/erasermap/view/RoutePreviewViewTest.java +++ b/app/src/test/java/com/mapzen/erasermap/view/RoutePreviewViewTest.java @@ -19,7 +19,7 @@ import static org.robolectric.RuntimeEnvironment.application; @RunWith(PrivateMapsTestRunner.class) -@Config(constants = BuildConfig.class, emulateSdk = 21) +@Config(constants = BuildConfig.class, sdk = 21) public class RoutePreviewViewTest { private RoutePreviewView routePreview; diff --git a/app/src/test/java/com/mapzen/erasermap/view/SearchResultsAdapterTest.java b/app/src/test/java/com/mapzen/erasermap/view/SearchResultsAdapterTest.java index a4e6b76b..f14bc39c 100644 --- a/app/src/test/java/com/mapzen/erasermap/view/SearchResultsAdapterTest.java +++ b/app/src/test/java/com/mapzen/erasermap/view/SearchResultsAdapterTest.java @@ -27,7 +27,7 @@ import static org.robolectric.RuntimeEnvironment.application; @RunWith(PrivateMapsTestRunner.class) -@Config(constants = BuildConfig.class, emulateSdk = 21) +@Config(constants = BuildConfig.class, sdk = 21) public class SearchResultsAdapterTest { private SearchResultsAdapter adapter; private Feature feature; diff --git a/app/src/test/java/com/mapzen/erasermap/view/SearchResultsListActivityTest.java b/app/src/test/java/com/mapzen/erasermap/view/SearchResultsListActivityTest.java index 585083be..63305634 100644 --- a/app/src/test/java/com/mapzen/erasermap/view/SearchResultsListActivityTest.java +++ b/app/src/test/java/com/mapzen/erasermap/view/SearchResultsListActivityTest.java @@ -15,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(PrivateMapsTestRunner.class) -@Config(constants = BuildConfig.class, emulateSdk = 21) +@Config(constants = BuildConfig.class, sdk = 21) public class SearchResultsListActivityTest { private SearchResultsListActivity activity; diff --git a/app/src/test/java/com/mapzen/erasermap/view/SearchResultsViewTest.java b/app/src/test/java/com/mapzen/erasermap/view/SearchResultsViewTest.java index 18f9c03b..70e42346 100644 --- a/app/src/test/java/com/mapzen/erasermap/view/SearchResultsViewTest.java +++ b/app/src/test/java/com/mapzen/erasermap/view/SearchResultsViewTest.java @@ -23,7 +23,7 @@ import static org.robolectric.RuntimeEnvironment.application; @RunWith(PrivateMapsTestRunner.class) -@Config(constants = BuildConfig.class, emulateSdk = 21) +@Config(constants = BuildConfig.class, sdk = 21) public class SearchResultsViewTest { private SearchResultsView searchResultsView;