mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-09 04:34:49 +00:00
HHH-13831 Test listener keep original replacement strategy
This commit is contained in:
parent
6670d03493
commit
e38d2be431
@ -136,6 +136,39 @@ public void testFireEventOnEachListenerWithMultipleListenersAndReplacementStrate
|
|||||||
assertThat( tracker.callers ).containsExactly( ExpectedListener.class, ExtraListener.class );
|
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.
|
* Keep track of which listener is called and how many listeners are called.
|
||||||
*/
|
*/
|
||||||
@ -167,7 +200,6 @@ public void onClear(ClearEvent event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The expected listener to be called if everything goes well
|
* The expected listener to be called if everything goes well
|
||||||
*/
|
*/
|
||||||
@ -215,4 +247,20 @@ public Action getAction() {
|
|||||||
return Action.REPLACE_ORIGINAL;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user