### Question:
MvcViewHandler extends ViewHandlerWrapper { @Override public UIViewRoot createView(FacesContext context, String viewId) { SpringFacesContext springFacesContext = SpringFacesContext.getCurrentInstance(); if (springFacesContext == null) { return super.createView(context, viewId); } UIViewRoot viewRoot = createViewIfInResponseToNavigation(context, viewId); if (viewRoot == null) { viewRoot = createViewIfRenderingSpringMvcView(context, viewId); } if (viewRoot == null) { viewRoot = super.createView(context, viewId); } return viewRoot; } MvcViewHandler(ViewHandler delegate, DestinationViewResolver destinationViewResolver); @Override ViewHandler getWrapped(); @Override UIViewRoot createView(FacesContext context, String viewId); @Override UIViewRoot restoreView(FacesContext context, String viewId); @Override String getActionURL(FacesContext context, String viewId); @Override ViewDeclarationLanguage getViewDeclarationLanguage(FacesContext context, String viewId); @Override void renderView(FacesContext context, UIViewRoot viewToRender); @Override String getBookmarkableURL(FacesContext context, String viewId, Map<String, List<String>> parameters,
			boolean includeViewParams); @Override String getRedirectURL(FacesContext context, String viewId, Map<String, List<String>> parameters,
			boolean includeViewParams);  }### Answer:
@Test public void shouldDelegateCreateViewIfNoSpringFacesContext() throws Exception { this.handler.createView(this.context, this.viewId); verify(this.delegate).createView(this.context, this.viewId); }
@Test public void shouldCreateViewForNavigationResponse() throws Exception { SpringFacesContextSetter.setCurrentInstance(this.springFacesContext); setupDestination("test", mock(View.class)); given(this.context.getCurrentPhaseId()).willReturn(PhaseId.INVOKE_APPLICATION); UIViewRoot view = this.handler.createView(this.context, "/test"); verify(this.delegate, never()).createView(eq(this.context), anyString()); assertThat(view, is(instanceOf(NavigationResponseUIViewRoot.class))); assertThat(view.getRenderKitId(), is(RenderKitFactory.HTML_BASIC_RENDER_KIT)); }
@Test public void shouldSetRenderKit() throws Exception { SpringFacesContextSetter.setCurrentInstance(this.springFacesContext); setupDestination("test", mock(View.class)); UIViewRoot existingViewRoot = new UIViewRoot(); String renderKitId = "EXAMPLE_RENDER_KIT"; existingViewRoot.setRenderKitId(renderKitId); given(this.context.getViewRoot()).willReturn(existingViewRoot); given(this.context.getCurrentPhaseId()).willReturn(PhaseId.INVOKE_APPLICATION); UIViewRoot view = this.handler.createView(this.context, "/test"); assertThat(view.getRenderKitId(), is(renderKitId)); }
@Test public void shouldNotCreateViewForNavigationResponseIfNotInCorrectPhase() throws Exception { SpringFacesContextSetter.setCurrentInstance(this.springFacesContext); setupDestination("test", mock(View.class)); given(this.context.getCurrentPhaseId()).willReturn(PhaseId.RENDER_RESPONSE); UIViewRoot view = this.handler.createView(this.context, "/test"); verify(this.delegate).createView(this.context, "/test"); assertThat(view, is(not(instanceOf(NavigationResponseUIViewRoot.class)))); }
@Test public void shouldCreateViewForMVCRender() throws Exception { SpringFacesContextSetter.setCurrentInstance(this.springFacesContext); UIViewRoot viewRoot = mockUIViewRootWithModelSupport(); ModelAndViewArtifact modelAndViewArtifact = mockModelAndViewArtifact(); given(this.springFacesContext.getRendering()).willReturn(modelAndViewArtifact); given(this.delegate.createView(this.context, "mvc")).willReturn(viewRoot); UIViewRoot actual = this.handler.createView(this.context, "anything"); assertThat(actual, is(sameInstance(viewRoot))); verify(this.delegate).createView(this.context, "mvc"); assertThat(SpringFacesModelHolder.getModel(viewRoot).get("mk"), is(equalTo((Object) "v"))); }