Commit e76e478e by ibaker Committed by Tianyi Feng

Use TestUtil.getPublicMethods instead of getDeclaredMethods

JaCoCo introduces private synthetic methods (even on interfaces) which
have to be skipped when checking that a 'forwarding' implementation does
forward everything. Instead we can use the existing `getPublicMethods()`
method which implicitly skips these (since they're private).

PiperOrigin-RevId: 519665752
parent 652546c7
...@@ -44,6 +44,7 @@ import com.google.android.exoplayer2.metadata.Metadata; ...@@ -44,6 +44,7 @@ import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.ads.AdPlaybackState; import com.google.android.exoplayer2.source.ads.AdPlaybackState;
import com.google.android.exoplayer2.testutil.FakeMetadataEntry; import com.google.android.exoplayer2.testutil.FakeMetadataEntry;
import com.google.android.exoplayer2.testutil.TestUtil;
import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.CueGroup; import com.google.android.exoplayer2.text.CueGroup;
import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters;
...@@ -1441,7 +1442,7 @@ public class SimpleBasePlayerTest { ...@@ -1441,7 +1442,7 @@ public class SimpleBasePlayerTest {
.build())); .build()));
verifyNoMoreInteractions(listener); verifyNoMoreInteractions(listener);
// Assert that we actually called all listeners. // Assert that we actually called all listeners.
for (Method method : Player.Listener.class.getDeclaredMethods()) { for (Method method : TestUtil.getPublicMethods(Player.Listener.class)) {
if (method.getName().equals("onAudioSessionIdChanged") if (method.getName().equals("onAudioSessionIdChanged")
|| method.getName().equals("onSkipSilenceEnabledChanged")) { || method.getName().equals("onSkipSilenceEnabledChanged")) {
// Skip listeners for ExoPlayer-specific states // Skip listeners for ExoPlayer-specific states
......
...@@ -201,12 +201,7 @@ public final class DefaultAnalyticsCollectorTest { ...@@ -201,12 +201,7 @@ public final class DefaultAnalyticsCollectorTest {
*/ */
@Test @Test
public void defaultAnalyticsCollector_overridesAllPlayerListenerMethods() throws Exception { public void defaultAnalyticsCollector_overridesAllPlayerListenerMethods() throws Exception {
for (Method method : Player.Listener.class.getDeclaredMethods()) { for (Method method : TestUtil.getPublicMethods(Player.Listener.class)) {
if (method.isSynthetic()) {
// JaCoCo inserts synthetic methods. See "My code uses reflection. Why does it fail when I
// execute it with JaCoCo?": https://www.eclemma.org/jacoco/trunk/doc/faq.html
continue;
}
assertThat( assertThat(
DefaultAnalyticsCollector.class DefaultAnalyticsCollector.class
.getMethod(method.getName(), method.getParameterTypes()) .getMethod(method.getName(), method.getParameterTypes())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment