@Test
  public void resolveViewNameWithDefaultContentType() throws Exception {
    request.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");

    viewResolver.setIgnoreAcceptHeader(true);
    viewResolver.setDefaultContentType(new MediaType("application", "xml"));

    ViewResolver viewResolverMock1 = createMock("viewResolver1", ViewResolver.class);
    ViewResolver viewResolverMock2 = createMock("viewResolver2", ViewResolver.class);
    viewResolver.setViewResolvers(Arrays.asList(viewResolverMock1, viewResolverMock2));

    View viewMock1 = createMock("application_xml", View.class);
    View viewMock2 = createMock("text_html", View.class);

    String viewName = "view";
    Locale locale = Locale.ENGLISH;

    expect(viewResolverMock1.resolveViewName(viewName, locale)).andReturn(viewMock1);
    expect(viewResolverMock2.resolveViewName(viewName, locale)).andReturn(viewMock2);
    expect(viewMock1.getContentType()).andReturn("application/xml").anyTimes();
    expect(viewMock2.getContentType()).andReturn("text/html;charset=ISO-8859-1").anyTimes();

    replay(viewResolverMock1, viewResolverMock2, viewMock1, viewMock2);

    View result = viewResolver.resolveViewName(viewName, locale);
    assertSame("Invalid view", viewMock1, result);

    verify(viewResolverMock1, viewResolverMock2, viewMock1, viewMock2);
  }
 @Test
 public void getDefaultContentType() {
   request.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
   viewResolver.setIgnoreAcceptHeader(true);
   viewResolver.setDefaultContentType(new MediaType("application", "pdf"));
   List<MediaType> result = viewResolver.getMediaTypes(request);
   assertEquals("Invalid amount of media types", 1, result.size());
   assertEquals("Invalid content type", new MediaType("application", "pdf"), result.get(0));
 }
  @Test
  public void nestedViewResolverIsNotSpringBean() throws Exception {
    StaticWebApplicationContext webAppContext = new StaticWebApplicationContext();
    webAppContext.setServletContext(new MockServletContext());
    webAppContext.refresh();

    InternalResourceViewResolver nestedResolver = new InternalResourceViewResolver();
    nestedResolver.setApplicationContext(webAppContext);
    nestedResolver.setViewClass(InternalResourceView.class);
    viewResolver.setViewResolvers(new ArrayList<ViewResolver>(Arrays.asList(nestedResolver)));
    viewResolver.setDefaultContentType(MediaType.TEXT_HTML);

    String viewName = "view";
    Locale locale = Locale.ENGLISH;

    View result = viewResolver.resolveViewName(viewName, locale);
    assertNotNull("Invalid view", result);
  }