HHH-13831 Test listener keep original replacement strategy

This commit is contained in:
Davide D'Alto 2020-01-30 11:51:03 +00:00 committed by Steve Ebersole
parent 6670d03493
commit e38d2be431
1 changed files with 49 additions and 1 deletions

View File

@ -136,6 +136,39 @@ public class EventListenerReplacementStrategyTest {
assertThat( tracker.callers ).containsExactly( ExpectedListener.class, ExtraListener.class );
}
@Test
public void testListenersIteratorWithMultipleListenersAndKeepOriginalStrategy() {
listenerGroup.addDuplicationStrategy( KeepOriginalStrategy.INSTANCE );
listenerGroup.appendListener( new OriginalListener( tracker ) );
listenerGroup.appendListener( new ExpectedListener( tracker ) );
listenerGroup.appendListener( new ExtraListener( tracker ) );
listenerGroup.listeners().forEach( listener -> listener.onClear( event ) );
assertThat( tracker.callers ).containsExactly( OriginalListener.class, ExtraListener.class );
}
@Test
public void testFireLazyEventOnEachListenerWithMultipleListenersAndKeepOriginalStrategy() {
listenerGroup.addDuplicationStrategy( KeepOriginalStrategy.INSTANCE );
listenerGroup.appendListener( new OriginalListener( tracker ) );
listenerGroup.appendListener( new ExpectedListener( tracker ) );
listenerGroup.appendListener( new ExtraListener( tracker ) );
listenerGroup.fireLazyEventOnEachListener( () -> event, ClearEventListener::onClear );
assertThat( tracker.callers ).containsExactly( OriginalListener.class, ExtraListener.class );
}
@Test
public void testFireEventOnEachListenerWithMultipleListenersAndKeepOriginalStrategy() {
listenerGroup.addDuplicationStrategy( KeepOriginalStrategy.INSTANCE );
listenerGroup.appendListener( new OriginalListener( tracker ) );
listenerGroup.appendListener( new ExpectedListener( tracker ) );
listenerGroup.appendListener( new ExtraListener( tracker ) );
listenerGroup.fireEventOnEachListener( event, ClearEventListener::onClear );
assertThat( tracker.callers ).containsExactly( OriginalListener.class, ExtraListener.class );
}
/**
* Keep track of which listener is called and how many listeners are called.
*/
@ -167,7 +200,6 @@ public class EventListenerReplacementStrategyTest {
}
}
/**
* The expected listener to be called if everything goes well
*/
@ -215,4 +247,20 @@ public class EventListenerReplacementStrategyTest {
return Action.REPLACE_ORIGINAL;
}
}
private static class KeepOriginalStrategy implements DuplicationStrategy {
static final KeepOriginalStrategy INSTANCE = new KeepOriginalStrategy();
@Override
public boolean areMatch(Object listener, Object original) {
// We just want this to work for original and expected listener
return original instanceof OriginalListener && listener instanceof ExpectedListener;
}
@Override
public Action getAction() {
return Action.KEEP_ORIGINAL;
}
}
}