@Override public int render(Renderer renderer, ContentStore db, JBakeConfiguration config) throws RenderingException { if (config.getRenderTags()) { try { //TODO: refactor this. the renderer has a reference to the configuration return renderer.renderTags(config.getTagPathName()); } catch (Exception e) { throw new RenderingException(e); } } else { return 0; } }
@Test(expected = RenderingException.class) public void propogatesRenderingException() throws Exception { TagsRenderer renderer = new TagsRenderer(); JBakeConfiguration configuration = mock(DefaultJBakeConfiguration.class); when(configuration.getRenderTags()).thenReturn(true); when(configuration.getTagPathName()).thenReturn("mocktagpath/tag"); ContentStore contentStore = mock(ContentStore.class); Renderer mockRenderer = mock(Renderer.class); doThrow(new Exception()).when(mockRenderer).renderTags(anyString()); renderer.render(mockRenderer, contentStore, configuration); verify(mockRenderer, never()).renderTags(anyString()); } }
@Test public void renderTags() throws Exception { renderer.renderTags("tags"); // verify File outputFile = new File(destinationFolder + File.separator + "tags" + File.separator + "blog.html"); Assert.assertTrue(outputFile.exists()); String output = FileUtils.readFileToString(outputFile, Charset.defaultCharset()); for (String string : getOutputStrings("tags")) { assertThat(output).contains(string); } }
@Test public void doesNotRenderWhenConfigDoesNotRenderTags() throws Exception { TagsRenderer renderer = new TagsRenderer(); JBakeConfiguration configuration = mock(DefaultJBakeConfiguration.class); when(configuration.getRenderTags()).thenReturn(false); ContentStore contentStore = mock(ContentStore.class); Renderer mockRenderer = mock(Renderer.class); renderer.render(mockRenderer, contentStore, configuration); verify(mockRenderer, never()).renderTags(anyString()); }
@Test public void returnsOneWhenConfigRendersIndices() throws Exception { TagsRenderer renderer = new TagsRenderer(); JBakeConfiguration configuration = mock(DefaultJBakeConfiguration.class); when(configuration.getRenderTags()).thenReturn(true); when(configuration.getTagPathName()).thenReturn("mocktagpath"); ContentStore contentStore = mock(ContentStore.class); Renderer mockRenderer = mock(Renderer.class); Set<String> tags = new HashSet<String>(Arrays.asList("tag1", "tags2")); when(contentStore.getTags()).thenReturn(tags); when(mockRenderer.renderTags(anyString())).thenReturn(1); int renderResponse = renderer.render(mockRenderer, contentStore, configuration); assertThat(renderResponse).isEqualTo(1); }
@Test public void doesRenderWhenConfigDoesRenderIndices() throws Exception { TagsRenderer renderer = new TagsRenderer(); JBakeConfiguration configuration = mock(DefaultJBakeConfiguration.class); when(configuration.getRenderTags()).thenReturn(true); ContentStore contentStore = mock(ContentStore.class); Renderer mockRenderer = mock(Renderer.class); Set<String> tags = new HashSet<String>(Arrays.asList("tag1", "tags2")); when(contentStore.getTags()).thenReturn(tags); when(configuration.getTagPathName()).thenReturn("mockTagfile.html"); renderer.render(mockRenderer, contentStore, configuration); verify(mockRenderer, times(1)).renderTags(anyString()); }
@Test public void renderTagsIndex() throws Exception { config.setRenderTagsIndex(true); renderer.renderTags("tags"); File outputFile = new File(destinationFolder + File.separator + "tags" + File.separator + "index.html"); Assert.assertTrue(outputFile.exists()); String output = FileUtils.readFileToString(outputFile, Charset.defaultCharset()); for (String string : getOutputStrings("tags-index")) { assertThat(output).contains(string); } }
@Override public int render(Renderer renderer, ContentStore db, JBakeConfiguration config) throws RenderingException { if (config.getRenderTags()) { try { //TODO: refactor this. the renderer has a reference to the configuration return renderer.renderTags(config.getTagPathName()); } catch (Exception e) { throw new RenderingException(e); } } else { return 0; } }