Source:
public void ContentFallbackFalse_PageFallbackTrue_PageEnglish_ViewEnglishContent1And2_ViewSpanishContent2And3( final Container container, final Template template) throws Exception{ Config.setProperty("DEFAULT_CONTENT_TO_DEFAULT_LANGUAGE", true); Config.setProperty(contentFallbackProperty,false); Config.setProperty(pageFallbackProperty,true); final String pageName = "test1Page-"+System.currentTimeMillis(); final HTMLPageAsset pageEnglishVersion = createHtmlPageAsset(template, pageName, 1); createMultiTree(pageEnglishVersion.getIdentifier(), container.getIdentifier()); HttpServletRequest mockRequest = new MockSessionRequest( new MockAttributeRequest(new MockHttpRequest("localhost", "/").request()).request()) .request(); Mockito.when(mockRequest.getParameter("host_id")).thenReturn(site.getIdentifier()); mockRequest.setAttribute(WebKeys.HTMLPAGE_LANGUAGE, "1"); HttpServletRequestThreadLocal.INSTANCE.setRequest(mockRequest); final HttpServletResponse mockResponse = mock(HttpServletResponse.class); String html = APILocator.getHTMLPageAssetRenderedAPI().getPageHtml( PageContextBuilder.builder() .setUser(systemUser) .setPageUri(pageEnglishVersion.getURI()) .setPageMode(PageMode.LIVE) .build(), mockRequest, mockResponse); Assert.assertTrue("ENG = "+html , html.contains("content2content1")); mockRequest = new MockSessionRequest( new MockAttributeRequest(new MockHttpRequest("localhost", "/").request()).request()) .request(); Mockito.when(mockRequest.getParameter("host_id")).thenReturn(site.getIdentifier()); mockRequest .setAttribute(WebKeys.HTMLPAGE_LANGUAGE, String.valueOf(spanishLanguage.getId())); HttpServletRequestThreadLocal.INSTANCE.setRequest(mockRequest); html = APILocator.getHTMLPageAssetRenderedAPI().getPageHtml( PageContextBuilder.builder() .setUser(systemUser) .setPageUri(pageEnglishVersion.getURI()) .setPageMode(PageMode.LIVE) .build(), mockRequest, mockResponse); Assert.assertTrue("ESP = "+html , html.contains("content3Spacontent2Spa")); }

Target:
public void ContentFallbackFalse_PageFallbackTrue_PageEnglish_ViewEnglishContent1And2_ViewSpanishContent2And3( final Container container, final Template template) throws Exception{ Config.setProperty(contentFallbackProperty,false); Config.setProperty(pageFallbackProperty,true); final String pageName = "test1Page-"+System.currentTimeMillis(); final HTMLPageAsset pageEnglishVersion = createHtmlPageAsset(template, pageName, 1); createMultiTree(pageEnglishVersion.getIdentifier(), container.getIdentifier()); final List<MultiTree> multiTrees = APILocator.getMultiTreeAPI().getContainerMultiTrees(container.getIdentifier()); Assert.assertNotNull(multiTrees); Assert.assertEquals(4, multiTrees.size()); int contentletSpaCount = 0; for (final MultiTree multiTree : multiTrees) { try { final Contentlet contentletSpa = APILocator.getContentletAPI().findContentletByIdentifier( multiTree.getContentlet(), true, spanishLanguage.getId(), systemUser, false); if (null != contentletSpa) { contentletSpaCount += 1; } } catch (DotContentletStateException e) } Assert.assertEquals(2, contentletSpaCount); HttpServletRequest mockRequest = new MockSessionRequest( new MockAttributeRequest(new MockHttpRequest("localhost", "/").request()).request()) .request(); Mockito.when(mockRequest.getParameter("host_id")).thenReturn(site.getIdentifier()); mockRequest.setAttribute(WebKeys.HTMLPAGE_LANGUAGE, "1"); HttpServletRequestThreadLocal.INSTANCE.setRequest(mockRequest); final HttpServletResponse mockResponse = mock(HttpServletResponse.class); String html = APILocator.getHTMLPageAssetRenderedAPI().getPageHtml( PageContextBuilder.builder() .setUser(systemUser) .setPageUri(pageEnglishVersion.getURI()) .setPageMode(PageMode.LIVE) .build(), mockRequest, mockResponse); Assert.assertTrue("ENG = "+html , html.contains("content1") && html.contains("content2")); }