diff --git a/core_settings.gradle b/core_settings.gradle
index 20a7c87bde2..c4914e30403 100644
--- a/core_settings.gradle
+++ b/core_settings.gradle
@@ -24,6 +24,7 @@ include modulePrefix + 'library-hls'
include modulePrefix + 'library-smoothstreaming'
include modulePrefix + 'library-ui'
include modulePrefix + 'testutils'
+include modulePrefix + 'testutils-robolectric'
include modulePrefix + 'extension-ffmpeg'
include modulePrefix + 'extension-flac'
include modulePrefix + 'extension-gvr'
@@ -43,6 +44,7 @@ project(modulePrefix + 'library-hls').projectDir = new File(rootDir, 'library/hl
project(modulePrefix + 'library-smoothstreaming').projectDir = new File(rootDir, 'library/smoothstreaming')
project(modulePrefix + 'library-ui').projectDir = new File(rootDir, 'library/ui')
project(modulePrefix + 'testutils').projectDir = new File(rootDir, 'testutils')
+project(modulePrefix + 'testutils-robolectric').projectDir = new File(rootDir, 'testutils_robolectric')
project(modulePrefix + 'extension-ffmpeg').projectDir = new File(rootDir, 'extensions/ffmpeg')
project(modulePrefix + 'extension-flac').projectDir = new File(rootDir, 'extensions/flac')
project(modulePrefix + 'extension-gvr').projectDir = new File(rootDir, 'extensions/gvr')
diff --git a/extensions/cast/build.gradle b/extensions/cast/build.gradle
index d11f166c896..2f79c7a0ee6 100644
--- a/extensions/cast/build.gradle
+++ b/extensions/cast/build.gradle
@@ -38,10 +38,7 @@ dependencies {
compile 'com.google.android.gms:play-services-cast-framework:' + playServicesLibraryVersion
compile project(modulePrefix + 'library-core')
compile project(modulePrefix + 'library-ui')
- testCompile project(modulePrefix + 'testutils')
- testCompile 'junit:junit:' + junitVersion
- testCompile 'org.mockito:mockito-core:' + mockitoVersion
- testCompile 'org.robolectric:robolectric:' + robolectricVersion
+ testCompile project(modulePrefix + 'testutils-robolectric')
}
ext {
diff --git a/extensions/cast/src/test/AndroidManifest.xml b/extensions/cast/src/test/AndroidManifest.xml
new file mode 100644
index 00000000000..057efdc245e
--- /dev/null
+++ b/extensions/cast/src/test/AndroidManifest.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
diff --git a/extensions/cast/src/test/java/com/google/android/exoplayer2/ext/cast/CastTimelineTrackerTest.java b/extensions/cast/src/test/java/com/google/android/exoplayer2/ext/cast/CastTimelineTrackerTest.java
index bf4b20e1560..4c60e7c0b35 100644
--- a/extensions/cast/src/test/java/com/google/android/exoplayer2/ext/cast/CastTimelineTrackerTest.java
+++ b/extensions/cast/src/test/java/com/google/android/exoplayer2/ext/cast/CastTimelineTrackerTest.java
@@ -17,6 +17,7 @@
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.testutil.TimelineAsserts;
+import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.gms.cast.MediaInfo;
import com.google.android.gms.cast.MediaQueueItem;
import com.google.android.gms.cast.MediaStatus;
@@ -25,11 +26,9 @@
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
/** Tests for {@link CastTimelineTracker}. */
@RunWith(RobolectricTestRunner.class)
-@Config(sdk = Config.TARGET_SDK, manifest = Config.NONE)
public class CastTimelineTrackerTest {
private static final long DURATION_1_MS = 1000;
@@ -49,12 +48,12 @@ public void testGetCastTimeline() {
new long[] {DURATION_1_MS, MediaInfo.UNKNOWN_DURATION, MediaInfo.UNKNOWN_DURATION});
CastTimelineTracker tracker = new CastTimelineTracker();
- mediaInfo = mockMediaInfo("contentId1", DURATION_1_MS);
+ mediaInfo = getMediaInfo("contentId1", DURATION_1_MS);
Mockito.when(status.getMediaInfo()).thenReturn(mediaInfo);
TimelineAsserts.assertPeriodDurations(
tracker.getCastTimeline(status), C.msToUs(DURATION_1_MS), C.TIME_UNSET, C.TIME_UNSET);
- mediaInfo = mockMediaInfo("contentId3", DURATION_3_MS);
+ mediaInfo = getMediaInfo("contentId3", DURATION_3_MS);
Mockito.when(status.getMediaInfo()).thenReturn(mediaInfo);
TimelineAsserts.assertPeriodDurations(
tracker.getCastTimeline(status),
@@ -62,7 +61,7 @@ public void testGetCastTimeline() {
C.TIME_UNSET,
C.msToUs(DURATION_3_MS));
- mediaInfo = mockMediaInfo("contentId2", DURATION_2_MS);
+ mediaInfo = getMediaInfo("contentId2", DURATION_2_MS);
Mockito.when(status.getMediaInfo()).thenReturn(mediaInfo);
TimelineAsserts.assertPeriodDurations(
tracker.getCastTimeline(status),
@@ -80,7 +79,7 @@ public void testGetCastTimeline() {
DURATION_5_MS,
MediaInfo.UNKNOWN_DURATION
});
- mediaInfo = mockMediaInfo("contentId5", DURATION_5_MS);
+ mediaInfo = getMediaInfo("contentId5", DURATION_5_MS);
Mockito.when(newStatus.getMediaInfo()).thenReturn(mediaInfo);
TimelineAsserts.assertPeriodDurations(
tracker.getCastTimeline(newStatus),
@@ -89,7 +88,7 @@ public void testGetCastTimeline() {
C.msToUs(DURATION_5_MS),
C.msToUs(DURATION_3_MS));
- mediaInfo = mockMediaInfo("contentId3", DURATION_3_MS);
+ mediaInfo = getMediaInfo("contentId3", DURATION_3_MS);
Mockito.when(newStatus.getMediaInfo()).thenReturn(mediaInfo);
TimelineAsserts.assertPeriodDurations(
tracker.getCastTimeline(newStatus),
@@ -98,7 +97,7 @@ public void testGetCastTimeline() {
C.msToUs(DURATION_5_MS),
C.msToUs(DURATION_3_MS));
- mediaInfo = mockMediaInfo("contentId4", DURATION_4_MS);
+ mediaInfo = getMediaInfo("contentId4", DURATION_4_MS);
Mockito.when(newStatus.getMediaInfo()).thenReturn(mediaInfo);
TimelineAsserts.assertPeriodDurations(
tracker.getCastTimeline(newStatus),
@@ -112,7 +111,7 @@ private static MediaStatus mockMediaStatus(
int[] itemIds, String[] contentIds, long[] durationsMs) {
ArrayList items = new ArrayList<>();
for (int i = 0; i < contentIds.length; i++) {
- MediaInfo mediaInfo = mockMediaInfo(contentIds[i], durationsMs[i]);
+ MediaInfo mediaInfo = getMediaInfo(contentIds[i], durationsMs[i]);
MediaQueueItem item = Mockito.mock(MediaQueueItem.class);
Mockito.when(item.getMedia()).thenReturn(mediaInfo);
Mockito.when(item.getItemId()).thenReturn(itemIds[i]);
@@ -123,10 +122,11 @@ private static MediaStatus mockMediaStatus(
return status;
}
- private static MediaInfo mockMediaInfo(String contentId, long durationMs) {
- MediaInfo mediaInfo = Mockito.mock(MediaInfo.class);
- Mockito.when(mediaInfo.getContentId()).thenReturn(contentId);
- Mockito.when(mediaInfo.getStreamDuration()).thenReturn(durationMs);
- return mediaInfo;
+ private static MediaInfo getMediaInfo(String contentId, long durationMs) {
+ return new MediaInfo.Builder(contentId)
+ .setStreamDuration(durationMs)
+ .setContentType(MimeTypes.APPLICATION_MP4)
+ .setStreamType(MediaInfo.STREAM_TYPE_NONE)
+ .build();
}
}
diff --git a/extensions/cast/src/test/resources/robolectric.properties b/extensions/cast/src/test/resources/robolectric.properties
new file mode 100644
index 00000000000..2f3210368ec
--- /dev/null
+++ b/extensions/cast/src/test/resources/robolectric.properties
@@ -0,0 +1 @@
+manifest=src/test/AndroidManifest.xml
diff --git a/extensions/cronet/build.gradle b/extensions/cronet/build.gradle
index 0b6f9a587c0..2d25c7299ce 100644
--- a/extensions/cronet/build.gradle
+++ b/extensions/cronet/build.gradle
@@ -39,12 +39,8 @@ dependencies {
compile files('libs/cronet_api.jar')
compile files('libs/cronet_impl_common_java.jar')
compile files('libs/cronet_impl_native_java.jar')
- androidTestCompile project(modulePrefix + 'library')
- androidTestCompile project(modulePrefix + 'testutils')
- androidTestCompile 'com.google.dexmaker:dexmaker:' + dexmakerVersion
- androidTestCompile 'com.google.dexmaker:dexmaker-mockito:' + dexmakerVersion
- androidTestCompile 'org.mockito:mockito-core:' + mockitoVersion
- androidTestCompile 'com.android.support.test:runner:' + testSupportLibraryVersion
+ testCompile project(modulePrefix + 'library')
+ testCompile project(modulePrefix + 'testutils-robolectric')
}
ext {
diff --git a/extensions/cronet/src/androidTest/AndroidManifest.xml b/extensions/cronet/src/test/AndroidManifest.xml
similarity index 71%
rename from extensions/cronet/src/androidTest/AndroidManifest.xml
rename to extensions/cronet/src/test/AndroidManifest.xml
index 453cc684785..52be9aa1576 100644
--- a/extensions/cronet/src/androidTest/AndroidManifest.xml
+++ b/extensions/cronet/src/test/AndroidManifest.xml
@@ -18,16 +18,6 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.google.android.exoplayer2.ext.cronet">
-
-
-
-
-
-
-
+
diff --git a/extensions/cronet/src/androidTest/java/com/google/android/exoplayer2/ext/cronet/ByteArrayUploadDataProviderTest.java b/extensions/cronet/src/test/java/com/google/android/exoplayer2/ext/cronet/ByteArrayUploadDataProviderTest.java
similarity index 90%
rename from extensions/cronet/src/androidTest/java/com/google/android/exoplayer2/ext/cronet/ByteArrayUploadDataProviderTest.java
rename to extensions/cronet/src/test/java/com/google/android/exoplayer2/ext/cronet/ByteArrayUploadDataProviderTest.java
index 28d22b91a58..291e73fcc16 100644
--- a/extensions/cronet/src/androidTest/java/com/google/android/exoplayer2/ext/cronet/ByteArrayUploadDataProviderTest.java
+++ b/extensions/cronet/src/test/java/com/google/android/exoplayer2/ext/cronet/ByteArrayUploadDataProviderTest.java
@@ -19,9 +19,6 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
-import com.google.android.exoplayer2.testutil.MockitoUtil;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;
@@ -30,11 +27,11 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
-/**
- * Tests for {@link ByteArrayUploadDataProvider}.
- */
-@RunWith(AndroidJUnit4.class)
+/** Tests for {@link ByteArrayUploadDataProvider}. */
+@RunWith(RobolectricTestRunner.class)
public final class ByteArrayUploadDataProviderTest {
private static final byte[] TEST_DATA = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
@@ -45,7 +42,7 @@ public final class ByteArrayUploadDataProviderTest {
@Before
public void setUp() {
- MockitoUtil.setUpMockito(InstrumentationRegistry.getTargetContext(), this);
+ MockitoAnnotations.initMocks(this);
byteBuffer = ByteBuffer.allocate(TEST_DATA.length);
byteArrayUploadDataProvider = new ByteArrayUploadDataProvider(TEST_DATA);
}
@@ -90,5 +87,4 @@ public void testRewind() throws IOException {
assertThat(byteBuffer.array()).isEqualTo(TEST_DATA);
verify(mockUploadDataSink).onRewindSucceeded();
}
-
}
diff --git a/extensions/cronet/src/androidTest/java/com/google/android/exoplayer2/ext/cronet/CronetDataSourceTest.java b/extensions/cronet/src/test/java/com/google/android/exoplayer2/ext/cronet/CronetDataSourceTest.java
similarity index 71%
rename from extensions/cronet/src/androidTest/java/com/google/android/exoplayer2/ext/cronet/CronetDataSourceTest.java
rename to extensions/cronet/src/test/java/com/google/android/exoplayer2/ext/cronet/CronetDataSourceTest.java
index 79be44398ed..4e990cd027a 100644
--- a/extensions/cronet/src/androidTest/java/com/google/android/exoplayer2/ext/cronet/CronetDataSourceTest.java
+++ b/extensions/cronet/src/test/java/com/google/android/exoplayer2/ext/cronet/CronetDataSourceTest.java
@@ -31,10 +31,8 @@
import android.net.Uri;
import android.os.ConditionVariable;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
+import android.os.SystemClock;
import com.google.android.exoplayer2.C;
-import com.google.android.exoplayer2.testutil.MockitoUtil;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException;
@@ -50,6 +48,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import org.chromium.net.CronetEngine;
@@ -61,13 +60,14 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.shadows.ShadowSystemClock;
-/**
- * Tests for {@link CronetDataSource}.
- */
-@RunWith(AndroidJUnit4.class)
+/** Tests for {@link CronetDataSource}. */
+@RunWith(RobolectricTestRunner.class)
public final class CronetDataSourceTest {
private static final int TEST_CONNECT_TIMEOUT_MS = 100;
@@ -85,18 +85,11 @@ public final class CronetDataSourceTest {
private UrlResponseInfo testUrlResponseInfo;
@Mock private UrlRequest.Builder mockUrlRequestBuilder;
- @Mock
- private UrlRequest mockUrlRequest;
- @Mock
- private Predicate mockContentTypePredicate;
- @Mock
- private TransferListener mockTransferListener;
- @Mock
- private Clock mockClock;
- @Mock
- private Executor mockExecutor;
- @Mock
- private NetworkException mockNetworkException;
+ @Mock private UrlRequest mockUrlRequest;
+ @Mock private Predicate mockContentTypePredicate;
+ @Mock private TransferListener mockTransferListener;
+ @Mock private Executor mockExecutor;
+ @Mock private NetworkException mockNetworkException;
@Mock private CronetEngine mockCronetEngine;
private CronetDataSource dataSourceUnderTest;
@@ -104,30 +97,31 @@ public final class CronetDataSourceTest {
@Before
public void setUp() throws Exception {
- MockitoUtil.setUpMockito(InstrumentationRegistry.getTargetContext(), this);
- dataSourceUnderTest = spy(
- new CronetDataSource(
- mockCronetEngine,
- mockExecutor,
- mockContentTypePredicate,
- mockTransferListener,
- TEST_CONNECT_TIMEOUT_MS,
- TEST_READ_TIMEOUT_MS,
- true, // resetTimeoutOnRedirects
- mockClock,
- null,
- false));
+ MockitoAnnotations.initMocks(this);
+ dataSourceUnderTest =
+ spy(
+ new CronetDataSource(
+ mockCronetEngine,
+ mockExecutor,
+ mockContentTypePredicate,
+ mockTransferListener,
+ TEST_CONNECT_TIMEOUT_MS,
+ TEST_READ_TIMEOUT_MS,
+ true, // resetTimeoutOnRedirects
+ Clock.DEFAULT,
+ null,
+ false));
when(mockContentTypePredicate.evaluate(anyString())).thenReturn(true);
when(mockCronetEngine.newUrlRequestBuilder(
- anyString(), any(UrlRequest.Callback.class), any(Executor.class)))
+ anyString(), any(UrlRequest.Callback.class), any(Executor.class)))
.thenReturn(mockUrlRequestBuilder);
when(mockUrlRequestBuilder.allowDirectExecutor()).thenReturn(mockUrlRequestBuilder);
when(mockUrlRequestBuilder.build()).thenReturn(mockUrlRequest);
mockStatusResponse();
testDataSpec = new DataSpec(Uri.parse(TEST_URL), 0, C.LENGTH_UNSET, null);
- testPostDataSpec = new DataSpec(
- Uri.parse(TEST_URL), TEST_POST_BODY, 0, 0, C.LENGTH_UNSET, null, 0);
+ testPostDataSpec =
+ new DataSpec(Uri.parse(TEST_URL), TEST_POST_BODY, 0, 0, C.LENGTH_UNSET, null, 0);
testResponseHeader = new HashMap<>();
testResponseHeader.put("Content-Type", TEST_CONTENT_TYPE);
// This value can be anything since the DataSpec is unset.
@@ -173,20 +167,19 @@ public void testCallbackFromPreviousRequest() throws HttpDataSourceException {
// Prepare a mock UrlRequest to be used in the second open() call.
final UrlRequest mockUrlRequest2 = mock(UrlRequest.class);
when(mockUrlRequestBuilder.build()).thenReturn(mockUrlRequest2);
- doAnswer(new Answer