mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Remove Forwarding
from assertForwardingClassOverridesAllMethods
And use it in a "non-forwarding" context in `DefaultAnalyticsCollectorTest`. PiperOrigin-RevId: 704331859
This commit is contained in:
parent
e017213ee8
commit
ef19740c92
@ -20,7 +20,7 @@ import static androidx.media3.common.Player.EVENT_MEDIA_ITEM_TRANSITION;
|
||||
import static androidx.media3.common.Player.EVENT_TIMELINE_CHANGED;
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static androidx.media3.test.utils.TestUtil.assertForwardingClassForwardsAllMethodsExcept;
|
||||
import static androidx.media3.test.utils.TestUtil.assertForwardingClassOverridesAllMethods;
|
||||
import static androidx.media3.test.utils.TestUtil.assertSubclassOverridesAllMethods;
|
||||
import static androidx.media3.test.utils.TestUtil.getInnerClass;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
@ -101,7 +101,7 @@ public class ForwardingPlayerTest {
|
||||
|
||||
@Test
|
||||
public void forwardingPlayer_overridesAllPlayerMethods() throws Exception {
|
||||
assertForwardingClassOverridesAllMethods(Player.class, ForwardingPlayer.class);
|
||||
assertSubclassOverridesAllMethods(Player.class, ForwardingPlayer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -122,7 +122,7 @@ public class ForwardingPlayerTest {
|
||||
Class<? extends Player.Listener> forwardingListenerClass =
|
||||
(Class<? extends Player.Listener>)
|
||||
checkNotNull(getInnerClass(ForwardingPlayer.class, "ForwardingListener"));
|
||||
assertForwardingClassOverridesAllMethods(Player.Listener.class, forwardingListenerClass);
|
||||
assertSubclassOverridesAllMethods(Player.Listener.class, forwardingListenerClass);
|
||||
}
|
||||
|
||||
private static class FakePlayer extends StubPlayer {
|
||||
|
@ -25,7 +25,7 @@ import org.junit.runner.RunWith;
|
||||
public class ForwardingRendererTest {
|
||||
@Test
|
||||
public void overridesAllMethods() throws NoSuchMethodException {
|
||||
TestUtil.assertForwardingClassOverridesAllMethods(Renderer.class, ForwardingRenderer.class);
|
||||
TestUtil.assertSubclassOverridesAllMethods(Renderer.class, ForwardingRenderer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -50,6 +50,7 @@ import static androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_
|
||||
import static androidx.media3.exoplayer.analytics.AnalyticsListener.EVENT_VIDEO_SIZE_CHANGED;
|
||||
import static androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM;
|
||||
import static androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem.oneByteSample;
|
||||
import static androidx.media3.test.utils.TestUtil.assertSubclassOverridesAllMethods;
|
||||
import static androidx.media3.test.utils.robolectric.TestPlayerRunHelper.play;
|
||||
import static androidx.media3.test.utils.robolectric.TestPlayerRunHelper.playUntilPosition;
|
||||
import static androidx.media3.test.utils.robolectric.TestPlayerRunHelper.run;
|
||||
@ -130,7 +131,6 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@ -198,14 +198,8 @@ public final class DefaultAnalyticsCollectorTest {
|
||||
* methods.
|
||||
*/
|
||||
@Test
|
||||
public void defaultAnalyticsCollector_overridesAllPlayerListenerMethods() throws Exception {
|
||||
for (Method method : TestUtil.getPublicMethods(Player.Listener.class)) {
|
||||
assertThat(
|
||||
DefaultAnalyticsCollector.class
|
||||
.getMethod(method.getName(), method.getParameterTypes())
|
||||
.getDeclaringClass())
|
||||
.isEqualTo(DefaultAnalyticsCollector.class);
|
||||
}
|
||||
public void overridesAllPlayerListenerMethods() throws Exception {
|
||||
assertSubclassOverridesAllMethods(Player.Listener.class, DefaultAnalyticsCollector.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -16,7 +16,7 @@
|
||||
package androidx.media3.exoplayer.audio;
|
||||
|
||||
import static androidx.media3.test.utils.TestUtil.assertForwardingClassForwardsAllMethods;
|
||||
import static androidx.media3.test.utils.TestUtil.assertForwardingClassOverridesAllMethods;
|
||||
import static androidx.media3.test.utils.TestUtil.assertSubclassOverridesAllMethods;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import org.junit.Test;
|
||||
@ -27,7 +27,7 @@ import org.junit.runner.RunWith;
|
||||
public final class ForwardingAudioSinkTest {
|
||||
@Test
|
||||
public void overridesAllMethods() throws NoSuchMethodException {
|
||||
assertForwardingClassOverridesAllMethods(AudioSink.class, ForwardingAudioSink.class);
|
||||
assertSubclassOverridesAllMethods(AudioSink.class, ForwardingAudioSink.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -16,7 +16,7 @@
|
||||
package androidx.media3.exoplayer.source;
|
||||
|
||||
import static androidx.media3.test.utils.TestUtil.assertForwardingClassForwardsAllMethodsExcept;
|
||||
import static androidx.media3.test.utils.TestUtil.assertForwardingClassOverridesAllMethods;
|
||||
import static androidx.media3.test.utils.TestUtil.assertSubclassOverridesAllMethods;
|
||||
|
||||
import androidx.media3.common.Timeline;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
@ -30,7 +30,7 @@ public class ForwardingTimelineTest {
|
||||
|
||||
@Test
|
||||
public void overridesAllMethods() throws Exception {
|
||||
assertForwardingClassOverridesAllMethods(Timeline.class, ForwardingTimeline.class);
|
||||
assertSubclassOverridesAllMethods(Timeline.class, ForwardingTimeline.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -26,7 +26,7 @@ public class ForwardingExtractorInputTest {
|
||||
|
||||
@Test
|
||||
public void overridesAllMethods() throws Exception {
|
||||
TestUtil.assertForwardingClassOverridesAllMethods(
|
||||
TestUtil.assertSubclassOverridesAllMethods(
|
||||
ExtractorInput.class, ForwardingExtractorInput.class);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
package androidx.media3.extractor;
|
||||
|
||||
import static androidx.media3.test.utils.TestUtil.assertForwardingClassForwardsAllMethods;
|
||||
import static androidx.media3.test.utils.TestUtil.assertForwardingClassOverridesAllMethods;
|
||||
import static androidx.media3.test.utils.TestUtil.assertSubclassOverridesAllMethods;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import org.junit.Test;
|
||||
@ -27,8 +27,7 @@ public class ForwardingExtractorOutputTest {
|
||||
|
||||
@Test
|
||||
public void overridesAllMethods() throws Exception {
|
||||
assertForwardingClassOverridesAllMethods(
|
||||
ExtractorOutput.class, ForwardingExtractorOutput.class);
|
||||
assertSubclassOverridesAllMethods(ExtractorOutput.class, ForwardingExtractorOutput.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -16,7 +16,7 @@
|
||||
package androidx.media3.extractor;
|
||||
|
||||
import static androidx.media3.test.utils.TestUtil.assertForwardingClassForwardsAllMethods;
|
||||
import static androidx.media3.test.utils.TestUtil.assertForwardingClassOverridesAllMethods;
|
||||
import static androidx.media3.test.utils.TestUtil.assertSubclassOverridesAllMethods;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import org.junit.Test;
|
||||
@ -27,7 +27,7 @@ public class ForwardingExtractorTest {
|
||||
|
||||
@Test
|
||||
public void overridesAllMethods() throws Exception {
|
||||
assertForwardingClassOverridesAllMethods(Extractor.class, ForwardingExtractor.class);
|
||||
assertSubclassOverridesAllMethods(Extractor.class, ForwardingExtractor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -26,7 +26,7 @@ public class ForwardingSeekMapTest {
|
||||
|
||||
@Test
|
||||
public void overridesAllMethods() throws Exception {
|
||||
TestUtil.assertForwardingClassOverridesAllMethods(SeekMap.class, ForwardingSeekMap.class);
|
||||
TestUtil.assertSubclassOverridesAllMethods(SeekMap.class, ForwardingSeekMap.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -25,8 +25,7 @@ import org.junit.runner.RunWith;
|
||||
public class ForwardingTrackOutputTest {
|
||||
@Test
|
||||
public void overridesAllMethods() throws Exception {
|
||||
TestUtil.assertForwardingClassOverridesAllMethods(
|
||||
TrackOutput.class, ForwardingTrackOutput.class);
|
||||
TestUtil.assertSubclassOverridesAllMethods(TrackOutput.class, ForwardingTrackOutput.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -644,29 +644,29 @@ public class TestUtil {
|
||||
|
||||
/**
|
||||
* Use reflection to assert that every non-final method declared on {@code superType} is
|
||||
* overridden by {@code forwardingType}.
|
||||
* overridden by {@code subType}.
|
||||
*/
|
||||
public static <T> void assertForwardingClassOverridesAllMethods(
|
||||
Class<T> superType, Class<? extends T> forwardingType) throws NoSuchMethodException {
|
||||
assertForwardingClassOverridesAllMethodsExcept(superType, forwardingType, ImmutableSet.of());
|
||||
public static <T> void assertSubclassOverridesAllMethods(
|
||||
Class<T> superType, Class<? extends T> subType) throws NoSuchMethodException {
|
||||
assertSubclassOverridesAllMethodsExcept(superType, subType, ImmutableSet.of());
|
||||
}
|
||||
|
||||
/**
|
||||
* Use reflection to assert that every non-final, non-excluded method declared on {@code
|
||||
* superType} is overridden by {@code forwardingType}.
|
||||
* superType} is overridden by {@code subType}.
|
||||
*/
|
||||
public static <T> void assertForwardingClassOverridesAllMethodsExcept(
|
||||
Class<T> superType, Class<? extends T> forwardingType, Set<String> excludedMethods)
|
||||
public static <T> void assertSubclassOverridesAllMethodsExcept(
|
||||
Class<T> superType, Class<? extends T> subType, Set<String> excludedMethods)
|
||||
throws NoSuchMethodException {
|
||||
for (Method method : TestUtil.getPublicOverridableMethods(superType)) {
|
||||
if (excludedMethods.contains(method.getName())) {
|
||||
continue;
|
||||
}
|
||||
assertThat(
|
||||
forwardingType
|
||||
subType
|
||||
.getDeclaredMethod(method.getName(), method.getParameterTypes())
|
||||
.getDeclaringClass())
|
||||
.isEqualTo(forwardingType);
|
||||
.isEqualTo(subType);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user