### Question:
DefaultMentionXDOMService implements MentionXDOMService { @Override public Map<DocumentReference, List<String>> groupAnchorsByUserReference(List<MacroBlock> mentions, WikiReference wikiReference) { Map<DocumentReference, List<String>> ret = new HashMap<>(); for (MacroBlock block : mentions) { String serializedUserReference = block.getParameter(REFERENCE_PARAM_NAME); DocumentReference reference = this.documentReferenceResolver.resolve(serializedUserReference, wikiReference); String anchor = block.getParameter(ANCHORID_PARAM_NAME); ret.merge(reference, new ArrayList<>(Collections.singletonList(anchor)), (l1, l2) -> { l1.addAll(l2); return l1; }); } return ret; }  @Override List<MacroBlock> listMentionMacros(XDOM xdom); @Override Map<DocumentReference, List<String>> groupAnchorsByUserReference(List<MacroBlock> mentions,
        WikiReference wikiReference); @Override Optional<XDOM> parse(String payload, Syntax syntax);  }### Answer:
@Test void groupAnchorsByUserReferenceEmpty() { Map<DocumentReference, List<String>> actual = this.xdomService.groupAnchorsByUserReference(emptyList(), new WikiReference("xwiki")); assertTrue(actual.isEmpty()); }
@Test void groupAnchorsByUserReferenceOne() { Map<DocumentReference, List<String>> actual = this.xdomService.groupAnchorsByUserReference(singletonList(initMentionMacro("A", "A1")), new WikiReference("xwiki")); Map<DocumentReference, List<String>> expected = new HashMap<>(); expected.put(this.documentReferenceA, Collections.singletonList("A1")); assertEquals(expected, actual); }
@Test void groupAnchorsByUserReferenceTwo() { Map<DocumentReference, List<String>> actual = this.xdomService.groupAnchorsByUserReference(asList( initMentionMacro("A", "A1"), initMentionMacro("A", "A2") ), new WikiReference("xwiki")); Map<DocumentReference, List<String>> expected = new HashMap<>(); expected.put(this.documentReferenceA, Arrays.asList("A1", "A2")); assertEquals(expected, actual); }
@Test void groupAnchorsByUserReferenceThree() { Map<DocumentReference, List<String>> actual = this.xdomService.groupAnchorsByUserReference(asList( initMentionMacro("A", "A1"), initMentionMacro("B", "B1"), initMentionMacro("A", "A2") ), new WikiReference("xwiki")); Map<DocumentReference, List<String>> expected = new HashMap<>(); expected.put(this.documentReferenceB, Collections.singletonList("B1")); expected.put(this.documentReferenceA, Arrays.asList("A1", "A2")); assertEquals(expected, actual); }
@Test void groupAnchorsByUserReferenceWithEmptyValues() { Map<DocumentReference, List<String>> actual = this.xdomService.groupAnchorsByUserReference(asList( initMentionMacro("A", null), initMentionMacro("A", "A1"), initMentionMacro("A", ""), initMentionMacro("B", "B1"), initMentionMacro("A", "A2"), initMentionMacro("C", "") ), new WikiReference("xwiki")); Map<DocumentReference, List<String>> expected = new HashMap<>(); expected.put(this.documentReferenceB, Collections.singletonList("B1")); expected.put(this.documentReferenceA, Arrays.asList(null, "A1", "", "A2")); expected.put(this.documentReferenceC, Collections.singletonList("")); assertEquals(expected, actual); }