@Test public void updateAnchors() throws Exception { SplittingCriterion splittingCriterion = mock(SplittingCriterion.class); when(splittingCriterion.shouldSplit(any(Block.class), anyInt())).thenReturn(false, false, true, true); when(splittingCriterion.shouldIterate(any(SectionBlock.class), anyInt())).thenReturn(false, false, false); NamingCriterion namingCriterion = mock(NamingCriterion.class); when(namingCriterion.getDocumentName(any(XDOM.class))).thenReturn("Child1", "Child2"); ResourceReference reference = new ResourceReference("", ResourceType.DOCUMENT); reference.setParameter("anchor", "chapter1"); LinkBlock link = new LinkBlock(Arrays.<Block>asList(new WordBlock("link")), reference, false); ParagraphBlock firstParagraph = new ParagraphBlock(Arrays.<Block>asList(link)); reference = new ResourceReference("", ResourceType.PATH); reference.setParameter("anchor", "chapter1"); link = new LinkBlock(Arrays.<Block>asList(new WordBlock("link")), reference, false); ParagraphBlock secondParagraph = new ParagraphBlock(Arrays.<Block>asList(link)); HeaderBlock header = new HeaderBlock(Arrays.<Block>asList(new IdBlock("chapter1"), new WordBlock("Chapter 1")), HeaderLevel.LEVEL1); SectionBlock section1 = new SectionBlock(Arrays.<Block>asList(header)); header = new HeaderBlock(Arrays.<Block>asList(new WordBlock("Chapter 2")), HeaderLevel.LEVEL1); reference = new ResourceReference("#chapter1", ResourceType.PATH); link = new LinkBlock(Arrays.<Block>asList(new WordBlock("link")), reference, false); SectionBlock section2 = new SectionBlock(Arrays.<Block>asList(header, new ParagraphBlock(Arrays.<Block>asList(link)))); XDOM xdom = new XDOM(Arrays.<Block>asList(firstParagraph, secondParagraph, section1, section2)); WikiDocument document = new WikiDocument("Space.Page", xdom, null); List<WikiDocument> result = mocker.getComponentUnderTest().split(document, splittingCriterion, namingCriterion); ClassBlockMatcher linkMatcher = new ClassBlockMatcher(LinkBlock.class); ResourceReference updatedReference = document.getXdom().<LinkBlock>getFirstBlock(linkMatcher, Axes.DESCENDANT).getReference(); assertEquals("chapter1", updatedReference.getParameter("anchor")); assertEquals(result.get(1).getFullName(), updatedReference.getReference()); updatedReference = document.getXdom().<LinkBlock>getBlocks(linkMatcher, Axes.DESCENDANT).get(1).getReference(); assertEquals("", updatedReference.getReference()); assertEquals("chapter1", updatedReference.getParameter("anchor")); updatedReference = result.get(2).getXdom().<LinkBlock>getFirstBlock(linkMatcher, Axes.DESCENDANT).getReference(); assertEquals(ResourceType.DOCUMENT, updatedReference.getType()); assertEquals("chapter1", updatedReference.getParameter("anchor")); assertEquals(result.get(1).getFullName(), updatedReference.getReference()); }
private void updateAnchors(List<WikiDocument> documents) { Map<String, String> fragments = collectDocumentFragments(documents); for (WikiDocument document : documents) { updateAnchors(document, fragments); } }
DefaultDocumentSplitter implements DocumentSplitter { private void updateAnchors(List<WikiDocument> documents) { Map<String, String> fragments = collectDocumentFragments(documents); for (WikiDocument document : documents) { updateAnchors(document, fragments); } } }
DefaultDocumentSplitter implements DocumentSplitter { private void updateAnchors(List<WikiDocument> documents) { Map<String, String> fragments = collectDocumentFragments(documents); for (WikiDocument document : documents) { updateAnchors(document, fragments); } }  }
DefaultDocumentSplitter implements DocumentSplitter { private void updateAnchors(List<WikiDocument> documents) { Map<String, String> fragments = collectDocumentFragments(documents); for (WikiDocument document : documents) { updateAnchors(document, fragments); } }  @Override List<WikiDocument> split(WikiDocument rootDoc, SplittingCriterion splittingCriterion,
        NamingCriterion namingCriterion); }
DefaultDocumentSplitter implements DocumentSplitter { private void updateAnchors(List<WikiDocument> documents) { Map<String, String> fragments = collectDocumentFragments(documents); for (WikiDocument document : documents) { updateAnchors(document, fragments); } }  @Override List<WikiDocument> split(WikiDocument rootDoc, SplittingCriterion splittingCriterion,
        NamingCriterion namingCriterion);  }