Skip to content

Commit

Permalink
Update to Robolectric 3.x snapshot.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjudd committed Feb 8, 2015
1 parent 2c2a6ef commit 2756dfc
Show file tree
Hide file tree
Showing 49 changed files with 260 additions and 250 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
buildscript {
repositories {
jcenter()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}

dependencies {
Expand All @@ -13,6 +16,9 @@ buildscript {
subprojects { project ->
repositories {
jcenter()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}

apply plugin: 'checkstyle'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ROBOLECTRIC_GRADLE_VERSION=0.14.1
COVERALLS_GRADLE_VERSION=2.0.1
JUNIT_VERSION=4.11
MOCKITO_VERSION=1.9.5
ROBOLECTRIC_VERSION=2.4
ROBOLECTRIC_VERSION=3.0-SNAPSHOT
MOCKWEBSERVER_VERSION=2.2.0
TRUTH_VERSION=0.24

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowLooper;
import org.robolectric.shadows.ShadowSystemClock;

import java.io.IOException;
Expand All @@ -48,7 +49,7 @@ public class VolleyStreamFetcherServerTest {

@Before
public void setUp() throws IOException {
requestQueue = Volley.newRequestQueue(Robolectric.application);
requestQueue = Volley.newRequestQueue(RuntimeEnvironment.application);
mockWebServer = new MockWebServer();
mockWebServer.play();
}
Expand Down Expand Up @@ -189,7 +190,7 @@ private DataFetcher<InputStream> getFetcher() {
public InputStream get() throws InterruptedException, ExecutionException {
for (int i = 0; i < 251 && !isDone(); i++) {
Thread.sleep(10);
Robolectric.runUiThreadTasks();
ShadowLooper.runUiThreadTasks();
}
if (!isDone()) {
fail("Failed to get response from Volley in time");
Expand Down
27 changes: 15 additions & 12 deletions integration/volley/volley.iml
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,33 @@
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" scope="TEST" name="commons-codec-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-annotations-2.4" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="okio-1.2.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="objenesis-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="asm-5.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-annotations-3.0-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" name="library-1.0.10" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="truth-0.24" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-3.0-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="ant-1.8.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="bcprov-jdk15on-1.50" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="mockwebserver-2.2.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="sqlite4java-0.282" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="maven-ant-tasks-2.1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="commons-codec-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="okhttp-2.2.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-2.4" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-utils-3.0-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="vtd-xml-2.11" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="asm-commons-5.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" name="library-1.0.10" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.11" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="asm-tree-5.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="asm-analysis-5.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="truth-0.24" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-resources-3.0-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="shadows-core-3.0-SNAPSHOT-21" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="icu4j-53.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="mockito-all-1.9.5" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="ant-1.8.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="bcprov-jdk15on-1.50" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="ant-launcher-1.8.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="guava-17.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="mockwebserver-2.2.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="ant-launcher-1.8.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="asm-util-5.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="maven-ant-tasks-2.1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="sqlite4java-0.282" level="project" />
<orderEntry type="module" module-name="testutil" exported="" />
<orderEntry type="module" module-name="glide" exported="" />
</component>
Expand Down
13 changes: 8 additions & 5 deletions library/library.iml
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,31 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" scope="TEST" name="okio-1.2.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="asm-5.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="objenesis-1.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-annotations-3.0-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="guava-18.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="truth-0.24" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-3.0-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="ant-1.8.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="bcprov-jdk15on-1.50" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="mockwebserver-2.2.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="sqlite4java-0.282" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="maven-ant-tasks-2.1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-annotations-2.4" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="jsr305-1.3.9" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="commons-codec-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-2.4" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="okhttp-2.2.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-utils-3.0-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="vtd-xml-2.11" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="guava-testlib-18.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="asm-commons-5.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="vtd-xml-2.11" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="asm-tree-5.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.11" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="asm-tree-5.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="asm-analysis-5.0.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="robolectric-resources-3.0-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="icu4j-53.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="mockito-all-1.9.5" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="shadows-core-3.0-SNAPSHOT-21" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="ant-launcher-1.8.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="asm-util-5.0.1" level="project" />
Expand Down
29 changes: 16 additions & 13 deletions library/src/androidTest/java/com/bumptech/glide/GlideTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
import org.robolectric.internal.ShadowExtractor;
import org.robolectric.res.builder.RobolectricPackageManager;
import org.robolectric.shadows.ShadowBitmap;

Expand Down Expand Up @@ -92,14 +94,14 @@ public class GlideTest {
public void setUp() throws Exception {
Glide.tearDown();

RobolectricPackageManager pm = (RobolectricPackageManager) Robolectric.application.getPackageManager();
ApplicationInfo info = pm.getApplicationInfo(Robolectric.application.getPackageName(), 0);
RobolectricPackageManager pm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
ApplicationInfo info = pm.getApplicationInfo(RuntimeEnvironment.application.getPackageName(), 0);
info.metaData = new Bundle();
info.metaData.putString(SetupModule.class.getName(), "GlideModule");

// Ensure that target's size ready callback will be called synchronously.
target = mock(Target.class);
imageView = new ImageView(Robolectric.application);
imageView = new ImageView(RuntimeEnvironment.application);
imageView.setLayoutParams(new ViewGroup.LayoutParams(100, 100));
doAnswer(new CallCallback()).when(target).getSize(any(SizeReadyCallback.class));

Expand Down Expand Up @@ -271,7 +273,7 @@ public void testToBytesOption() {

requestManager
.as(byte[].class)
.decode(through(Robolectric.application, Bitmap.class))
.decode(through(RuntimeEnvironment.application, Bitmap.class))
.load(uri)
.into(target);

Expand Down Expand Up @@ -478,7 +480,7 @@ public void testReceivesGifBytes() throws IOException {

requestManager
.as(byte[].class)
.decode(through(Robolectric.application, GifDrawable.class))
.decode(through(RuntimeEnvironment.application, GifDrawable.class))
.load(fakeUri)
.into(target);

Expand All @@ -491,7 +493,7 @@ public void testReceivesBitmapBytes() {
mockUri(fakeUri);
requestManager
.as(byte[].class)
.decode(through(Robolectric.application, Bitmap.class))
.decode(through(RuntimeEnvironment.application, Bitmap.class))
.load(fakeUri)
.into(target);

Expand Down Expand Up @@ -675,8 +677,9 @@ private String mockUri(Uri uri, InputStream is) {
if (is == null) {
is = new ByteArrayInputStream(new byte[0]);
}
ContentResolver contentResolver = Robolectric.application.getContentResolver();
ShadowFileDescriptorContentResolver shadowContentResolver = Robolectric.shadowOf_(contentResolver);
ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver();
ShadowFileDescriptorContentResolver shadowContentResolver =
(ShadowFileDescriptorContentResolver) ShadowExtractor.extract(contentResolver);
shadowContentResolver.registerInputStream(uri, is);

AssetFileDescriptor assetFileDescriptor = mock(AssetFileDescriptor.class);
Expand All @@ -688,7 +691,7 @@ private String mockUri(Uri uri, InputStream is) {
}

private Context getContext() {
return Robolectric.application;
return RuntimeEnvironment.application;
}

@SuppressWarnings("unchecked")
Expand All @@ -698,7 +701,7 @@ private <T> void registerMockStreamModelLoader(final Class<T> modelClass) {
when(modelLoaderFactory.build(any(Context.class), any(MultiModelLoaderFactory.class)))
.thenReturn(modelLoader);

Glide.get(Robolectric.application).getRegistry()
Glide.get(RuntimeEnvironment.application).getRegistry()
.prepend(modelClass, InputStream.class, modelLoaderFactory);
}

Expand Down Expand Up @@ -834,7 +837,7 @@ public static class MutableShadowBitmap extends ShadowBitmap {
@Implementation
public static Bitmap createBitmap(int width, int height, Bitmap.Config config) {
Bitmap bitmap = ShadowBitmap.createBitmap(width, height, config);
Robolectric.shadowOf(bitmap).setMutable(true);
Shadows.shadowOf(bitmap).setMutable(true);
return bitmap;
}
}
Expand All @@ -846,7 +849,7 @@ public static class ShadowMediaMetadataRetriever {
@SuppressWarnings("unused")
public Bitmap getFrameAtTime() {
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Robolectric.shadowOf(bitmap).appendDescription(" from MediaMetadataRetriever");
Shadows.shadowOf(bitmap).appendDescription(" from MediaMetadataRetriever");
return bitmap;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -110,7 +110,7 @@ public void testThrowsIfGivenNullView() {

@Test(expected = RuntimeException.class)
public void testThrowsIfIntoViewCalledOnBackgroundThread() throws InterruptedException {
final ImageView imageView = new ImageView(Robolectric.application);
final ImageView imageView = new ImageView(RuntimeEnvironment.application);
testInBackground(new BackgroundUtil.BackgroundTester() {
@Override
public void runTest() throws Exception {
Expand All @@ -133,7 +133,7 @@ public void runTest() throws Exception {

private RequestBuilder getNullModelRequest() {
when(glideContext.buildImageViewTarget(any(ImageView.class), any(Class.class))).thenReturn(mock(Target.class));
when(glideContext.getDecodeOptions()).thenReturn(new DecodeOptions(Robolectric.application));
when(glideContext.getDecodeOptions()).thenReturn(new DecodeOptions(RuntimeEnvironment.application));
return new RequestBuilder(glideContext, Object.class, requestTracker, lifecycle)
.load((Object) null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
Expand All @@ -51,7 +51,7 @@ public ConnectivityMonitor answer(InvocationOnMock invocation) throws Throwable
}
});
requestTracker = mock(RequestTracker.class);
manager = new RequestManager(Robolectric.application, lifecycle, requestTracker, factory);
manager = new RequestManager(RuntimeEnvironment.application, lifecycle, requestTracker, factory);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import java.io.Closeable;
Expand All @@ -29,7 +29,7 @@ public class LocalUriFetcherTest {

@Before
public void setUp() {
fetcher = new TestLocalUriFetcher(Robolectric.application, Uri.parse("content://empty"));
fetcher = new TestLocalUriFetcher(RuntimeEnvironment.application, Uri.parse("content://empty"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import java.io.ByteArrayInputStream;
Expand All @@ -37,14 +37,14 @@ public void setUp() {
MockitoAnnotations.initMocks(this);

uri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "123");
fetcher = new ThumbFetcher(Robolectric.application, uri, opener);
fetcher = new ThumbFetcher(RuntimeEnvironment.application, uri, opener);
}

@Test
public void testReturnsInputStreamFromThumbnailOpener() throws Exception {
InputStream expected = new ByteArrayInputStream(new byte[0]);

when(opener.open(eq(Robolectric.application), eq(uri))).thenReturn(expected);
when(opener.open(eq(RuntimeEnvironment.application), eq(uri))).thenReturn(expected);

InputStream result = fetcher.loadData(Priority.LOW);
assertEquals(expected, result);
Expand All @@ -54,7 +54,7 @@ public void testReturnsInputStreamFromThumbnailOpener() throws Exception {
public void testClosesInputStreamFromThumbnailOpenerOnCleanup() throws Exception {
InputStream expected = mock(InputStream.class);

when(opener.open(eq(Robolectric.application), eq(uri))).thenReturn(expected);
when(opener.open(eq(RuntimeEnvironment.application), eq(uri))).thenReturn(expected);

fetcher.loadData(Priority.HIGH);

Expand Down
Loading

0 comments on commit 2756dfc

Please sign in to comment.