Skip to content

Commit

Permalink
Merge pull request #16 from mapzen/chuck/robolectric-3.0
Browse files Browse the repository at this point in the history
Robolectric 3.0
  • Loading branch information
kingofirony committed Jul 14, 2015
2 parents d518cd2 + 2f52501 commit f9d60cb
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
28 changes: 6 additions & 22 deletions app/src/test/java/com/mapzen/erasermap/PrivateMapsTestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> CUSTOM_SHADOW_TARGETS =
Collections.unmodifiableList(Arrays.asList(
"com.mapzen.tangram.MapView",
"com.mapzen.tangram.MapController"
));

public PrivateMapsTestRunner(Class<?> klass) throws InitializationError {
super(klass);
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand All @@ -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);
}

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit f9d60cb

Please sign in to comment.