ViewScope implements Scope { private UIViewRoot getViewRoot() { UIViewRoot viewRoot = getFacesContext().getViewRoot(); if (viewRoot == null) { throw new IllegalStateException("No ViewRoot found"); } return viewRoot; }  @Override Object get(String name, ObjectFactory objectFactory); @Override @Nullable Object remove(String name); @Override @Nullable String getConversationId(); @Override void registerDestructionCallback(String name, Runnable callback); @Override @Nullable Object resolveContextualObject(String key); static final String SCOPE_VIEW; static final String DESTRUCTION_CALLBACK_NAME_PREFIX; }
@Test public void processEvent() { PreDestroyViewMapEvent event = mock(PreDestroyViewMapEvent.class); UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); when(event.getSource()).thenReturn(viewRoot); this.viewScope.getPreDestroyViewMapListener().processEvent(event); }