UIComponent component = new UIOutput();
MyCustomRenderer renderer = new MyCustomRenderer();
component.setRendererType("org.apache.myfaces.MyCustomRenderer");
renderKit.addRenderer("javax.faces.Output", "org.apache.myfaces.MyCustomRenderer", renderer);
//This case happens when @ListenerFor is attached on the renderer class like h:outputScript or h:outputStylesheet
EventListenerWrapper wrapper = new EventListenerWrapper(component, renderer);
wrapper.markInitialState();
wrapper.clearInitialState();
Object state = wrapper.saveState(facesContext);
//In this case state should not be null, because state should be saved fully
assertNotNull(state);
EventListenerWrapper wrapper2 = new EventListenerWrapper(component, renderer);
wrapper.markInitialState();
//For restore we need to setup the context first
component.pushComponentToEL(facesContext, component);
wrapper2.restoreState(facesContext, state);
component.popComponentFromEL(facesContext);
assertNotNull(wrapper2.getComponentSystemEventListener());
assertEquals(wrapper.getComponentSystemEventListener(), wrapper2.getComponentSystemEventListener());
}