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;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.ads.AdPlaybackState;
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.CueGroup;
import com.google.android.exoplayer2.trackselection.TrackSelectionParameters;
......@@ -1441,7 +1442,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