Commit 2c05a9af 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 b9790e69
......@@ -41,6 +41,7 @@ import androidx.media3.common.text.Cue;
import androidx.media3.common.text.CueGroup;
import androidx.media3.common.util.Size;
import androidx.media3.test.utils.FakeMetadataEntry;
import androidx.media3.test.utils.TestUtil;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.ImmutableList;
......@@ -1434,7 +1435,7 @@ public class SimpleBasePlayerTest {
.build()));
verifyNoMoreInteractions(listener);
// 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")
|| method.getName().equals("onSkipSilenceEnabledChanged")) {
// Skip listeners for ExoPlayer-specific states
......
......@@ -201,12 +201,7 @@ public final class DefaultAnalyticsCollectorTest {
*/
@Test
public void defaultAnalyticsCollector_overridesAllPlayerListenerMethods() throws Exception {
for (Method method : Player.Listener.class.getDeclaredMethods()) {
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;
}
for (Method method : TestUtil.getPublicMethods(Player.Listener.class)) {
assertThat(
DefaultAnalyticsCollector.class
.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