use of androidx.media3.common.FlagSet in project media by androidx.
the class ListenerSetTest method flushEvents_calledFromIterationFinishedCallback_restartsIterationFinishedEvents.
@Test
public void flushEvents_calledFromIterationFinishedCallback_restartsIterationFinishedEvents() {
ListenerSet<TestListener> listenerSet = new ListenerSet<>(Looper.myLooper(), Clock.DEFAULT, TestListener::iterationFinished);
// Listener2 sends callback1 recursively when receiving the iteration finished event.
TestListener listener2 = spy(new TestListener() {
boolean eventSent;
@Override
public void iterationFinished(FlagSet flags) {
if (!eventSent) {
listenerSet.sendEvent(EVENT_ID_1, TestListener::callback1);
eventSent = true;
}
}
});
TestListener listener1 = mock(TestListener.class);
TestListener listener3 = mock(TestListener.class);
listenerSet.add(listener1);
listenerSet.add(listener2);
listenerSet.add(listener3);
listenerSet.sendEvent(EVENT_ID_2, TestListener::callback2);
ShadowLooper.runMainLooperToNextTask();
InOrder inOrder = Mockito.inOrder(listener1, listener2, listener3);
inOrder.verify(listener1).callback2();
inOrder.verify(listener2).callback2();
inOrder.verify(listener3).callback2();
inOrder.verify(listener1).iterationFinished(createFlagSet(EVENT_ID_2));
inOrder.verify(listener2).iterationFinished(createFlagSet(EVENT_ID_2));
inOrder.verify(listener1).callback1();
inOrder.verify(listener2).callback1();
inOrder.verify(listener3).callback1();
inOrder.verify(listener1).iterationFinished(createFlagSet(EVENT_ID_1));
inOrder.verify(listener2).iterationFinished(createFlagSet(EVENT_ID_1));
inOrder.verify(listener3).iterationFinished(createFlagSet(EVENT_ID_1, EVENT_ID_2));
inOrder.verifyNoMoreInteractions();
}