### Question:
SerializationListeners { public static ISerializationListener listOf(final ISerializationListener... listener) { return new ISerializationListener() { @Override public void begin(Object object) { for (ISerializationListener l : listener) { l.begin(object); } } @Override public void before(int position, Object object) { for (ISerializationListener l : listener) { l.before(position, object); } } @Override public void after(int position, Object object) { for (ISerializationListener l : listener) { l.after(position, object); } } @Override public void end(Object object, Exception exceptionIfAny) { for (ISerializationListener l : listener) { l.end(object, exceptionIfAny); } } }; } private  SerializationListeners(); static ISerializationListener listOf(final ISerializationListener... listener);  }### Answer:
@Test public void listenerDelegation() { CountingListener first = new CountingListener(); CountingListener second = new CountingListener(); ISerializationListener proxy = SerializationListeners.listOf(first, second); proxy.begin(null); proxy.begin("HA"); proxy.begin("HE"); proxy.before(1, null); proxy.before(2, "HAaaa"); proxy.before(3, "HEeee"); proxy.before(4, "HEeeee"); proxy.after(6, "HEeee"); proxy.after(7, "HAaaa"); proxy.after(8, null); proxy.after(9, null); proxy.end("HE", null); proxy.end(null, null); proxy.end("HE", new RuntimeException()); proxy.end("HA", new RuntimeException()); proxy.end(null, new RuntimeException()); assertEquals(first, second); checkCounter("begin",first.beginCounter, 1, 2); checkCounter("before",first.beforeCounter, 1, 3); checkCounter("after",first.afterCounter, 2, 2); checkCounter("end",first.endCounter, 2, 3); checkCounter("exception",first.exceptionCounter, 2, 3); assertEquals(new Counter(40), first.positionCounter, "pos"); }