@Test
 public void configureStylesheetUrls() {
   markupToEclipseHelp.stylesheetUrls = Arrays.asList("test/foo.css", "bar.css");
   HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
   markupToEclipseHelp.configureStylesheets(builder, "");
   verify(builder, times(2)).addCssStylesheet(any(Stylesheet.class));
 }
  @Test
  public void createMarkupToEclipseTocCopyrightNotice() {
    File file = mock(File.class);
    doReturn("Test.html").when(file).getName();

    markupToEclipseHelp.copyrightNotice = "Test Copyright";
    MarkupToEclipseToc toc = markupToEclipseHelp.createMarkupToEclipseToc("", file, "Test");
    assertEquals("Test Copyright", toc.getCopyrightNotice());
  }
 @Test
 public void configureStylesheetUrlsWithRelativePath() {
   markupToEclipseHelp.stylesheetUrls = Arrays.asList("bar.css");
   HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
   markupToEclipseHelp.configureStylesheets(builder, "one/two");
   ArgumentCaptor<Stylesheet> captor = ArgumentCaptor.forClass(Stylesheet.class);
   verify(builder).addCssStylesheet(captor.capture());
   assertEquals("../../bar.css", captor.getValue().getUrl());
 }
 @Test
 public void createBuilder() {
   markupToEclipseHelp.copyrightNotice = UUID.randomUUID().toString();
   markupToEclipseHelp.title = UUID.randomUUID().toString();
   markupToEclipseHelp.htmlFilenameFormat = "$1.test.html";
   HtmlDocumentBuilder builder =
       markupToEclipseHelp.createRootBuilder(new StringWriter(), "test", "");
   assertEquals(markupToEclipseHelp.copyrightNotice, builder.getCopyrightNotice());
   assertEquals(markupToEclipseHelp.title, builder.getTitle());
   assertEquals(markupToEclipseHelp.htmlFilenameFormat, builder.getHtmlFilenameFormat());
 }
  @Test
  public void createMarkupToEclipseTocAnchorLevel() {
    File file = mock(File.class);
    doReturn("Test.html").when(file).getName();

    MarkupToEclipseToc toc = markupToEclipseHelp.createMarkupToEclipseToc("", file, "Test");
    assertEquals(0, toc.getAnchorLevel());
    markupToEclipseHelp.tocAnchorLevel = 3;
    toc = markupToEclipseHelp.createMarkupToEclipseToc("", file, "Test");
    assertEquals(3, toc.getAnchorLevel());
  }
 @Test
 public void embeddedTableOfContents() {
   HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
   SplitOutlineItem item = mock(SplitOutlineItem.class);
   File htmlOutputFile = mock(File.class);
   SplittingHtmlDocumentBuilder splittingBuilder =
       markupToEclipseHelp.createSplittingBuilder(builder, item, htmlOutputFile, "");
   assertFalse(splittingBuilder.isEmbeddedTableOfContents());
   markupToEclipseHelp.embeddedTableOfContents = true;
   splittingBuilder =
       markupToEclipseHelp.createSplittingBuilder(builder, item, htmlOutputFile, "");
   assertTrue(splittingBuilder.isEmbeddedTableOfContents());
 }
 @Test
 public void computeResourcePath() {
   assertEquals("styles/main.css", markupToEclipseHelp.computeResourcePath("styles/main.css", ""));
   assertEquals(
       "../styles/main.css", markupToEclipseHelp.computeResourcePath("styles/main.css", "one"));
   assertEquals(
       "../../styles/main.css",
       markupToEclipseHelp.computeResourcePath("styles/main.css", "one/two"));
   assertEquals(
       "/styles/main.css", markupToEclipseHelp.computeResourcePath("/styles/main.css", "prefix"));
   assertEquals(
       "http://example.com/main.css",
       markupToEclipseHelp.computeResourcePath("http://example.com/main.css", "prefix"));
 }
 @Test
 public void ensureFolderExistsMissingCreateFails() {
   File folder = mock(File.class);
   thrown.expect(BuildFailureException.class);
   thrown.expectMessage("Cannot create");
   markupToEclipseHelp.ensureFolderExists("test", folder, true);
 }
 private void assertNavigationImagesPath(String expected, String relativePath) {
   HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
   SplitOutlineItem item = mock(SplitOutlineItem.class);
   SplittingHtmlDocumentBuilder splittingBuilder =
       markupToEclipseHelp.createSplittingBuilder(builder, item, mock(File.class), relativePath);
   assertEquals(expected, splittingBuilder.getNavigationImagePath());
 }
 @Test
 public void ensureFolderExistsMissingNoCreate() {
   File folder = mock(File.class);
   thrown.expect(BuildFailureException.class);
   thrown.expectMessage("test does not exist");
   markupToEclipseHelp.ensureFolderExists("test", folder, false);
 }
 @Test
 public void ensureFolderExistsNotFolder() {
   File folder = mock(File.class);
   doReturn(true).when(folder).exists();
   doReturn(false).when(folder).isDirectory();
   thrown.expect(BuildFailureException.class);
   thrown.expectMessage("test exists but is not a folder");
   markupToEclipseHelp.ensureFolderExists("test", folder, false);
 }
 @Test
 public void ensureFolderExistsMissingCreate() {
   File folder = mock(File.class);
   doReturn(true).when(folder).mkdirs();
   markupToEclipseHelp.ensureFolderExists("test", folder, true);
   verify(folder).exists();
   verify(folder).mkdirs();
   verifyNoMoreInteractions(folder);
 }
 @Test
 public void ensureFolderExistsNothingToDo() {
   File folder = mock(File.class);
   doReturn(true).when(folder).exists();
   doReturn(true).when(folder).isDirectory();
   markupToEclipseHelp.ensureFolderExists("test", folder, false);
   verify(folder).exists();
   verify(folder).isDirectory();
   verifyNoMoreInteractions(folder);
 }
  @Test
  public void execute() throws MojoExecutionException, MojoFailureException {
    markupToEclipseHelp.multipleOutputFiles = true;
    markupToEclipseHelp.title = "Test This";
    markupToEclipseHelp.execute();

    assertTrue(computeOutputFile("test.html").exists());
    assertTrue(computeOutputFile("test-toc.xml").exists());
    assertTrue(computeOutputFile("Top-Level-Heading-2.html").exists());
    assertTrue(computeOutputFile("Top-Level-Heading-3.html").exists());
    assertTrue(computeOutputFile("images/wikitext-32.gif").exists());
    assertFalse(computeOutputFile("test.textile").exists());

    assertHasContent("test.html", "<title>Test This</title>");
    assertHasContent("test.html", "<h1 id=\"TestFile\">Test File</h1>");
    assertHasContent("test-toc.xml", "<toc topic=\"test.html\" label=\"Test This\">");
    assertHasContent(
        "test-toc.xml", "<topic href=\"Top-Level-Heading-2.html\" label=\"Top Level Heading 2\">");
    assertHasContent(
        "Top-Level-Heading-2.html", "<h1 id=\"TopLevelHeading2\">Top Level Heading 2</h1>");
    assertHasContent(
        "Top-Level-Heading-3.html", "<h1 id=\"TopLevelHeading3\">Top Level Heading 3</h1>");
  }
 @Test
 public void calculateHelpPrefixWindowsSeparator() {
   assertEquals("test/one", markupToEclipseHelp.calculateHelpPrefix("test\\one"));
 }
 @Test
 public void calculateHelpPrefixRoot() {
   assertNull(markupToEclipseHelp.calculateHelpPrefix(""));
 }
 @Before
 public void setup() {
   markupToEclipseHelp = new MarkupToEclipseHelpMojo();
   markupToEclipseHelp.outputFolder = temporaryFolder.getRoot();
   markupToEclipseHelp.sourceFolder = calculateSourceFolder();
 }
 @Test
 public void calculateHelpPrefix() {
   assertEquals("test/one", markupToEclipseHelp.calculateHelpPrefix("test/one"));
 }
 @Test
 public void calculateHelpPrefixRootWithHelpPrefix() {
   markupToEclipseHelp.helpPrefix = "help";
   assertEquals("help", markupToEclipseHelp.calculateHelpPrefix(""));
 }
 @Test
 public void computeResourcePathInvalidUri() {
   thrown.expect(BuildFailureException.class);
   thrown.expectMessage("\":not valid\" is not a valid URI");
   markupToEclipseHelp.computeResourcePath(":not valid", "");
 }
 @Test
 public void calculateHelpPrefixWithHelpPrefix() {
   markupToEclipseHelp.helpPrefix = "help";
   assertEquals("help/test/one", markupToEclipseHelp.calculateHelpPrefix("test/one"));
 }