diff --git a/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-default/src/test/java/org/xwiki/refactoring/internal/DefaultModelBridgeTest.java b/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-default/src/test/java/org/xwiki/refactoring/internal/DefaultModelBridgeTest.java index faf1e22b4aa..d2ed895892b 100644 --- a/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-default/src/test/java/org/xwiki/refactoring/internal/DefaultModelBridgeTest.java +++ b/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-default/src/test/java/org/xwiki/refactoring/internal/DefaultModelBridgeTest.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.Set; import javax.inject.Named; import javax.inject.Provider; @@ -34,9 +35,11 @@ import org.xwiki.job.AbstractJobStatus; import org.xwiki.job.api.AbstractCheckRightsRequest; import org.xwiki.job.event.status.JobProgressManager; +import org.xwiki.link.LinkStore; import org.xwiki.model.EntityType; import org.xwiki.model.reference.DocumentReference; import org.xwiki.model.reference.DocumentReferenceResolver; +import org.xwiki.model.reference.EntityReference; import org.xwiki.model.reference.EntityReferenceProvider; import org.xwiki.model.reference.EntityReferenceResolver; import org.xwiki.model.reference.EntityReferenceSerializer; @@ -119,6 +122,12 @@ class DefaultModelBridgeTest @Named("document") private UserReferenceResolver userReferenceResolver; + @MockComponent + private Provider linkStoreProvider; + + @MockComponent + private DocumentReferenceResolver documentReferenceResolver; + @InjectComponentManager private MockitoComponentManager componentManager; @@ -140,6 +149,9 @@ class DefaultModelBridgeTest @Mock private XWikiRightService xWikiRightService; + @Mock + private LinkStore linkStore; + @BeforeEach void configure(MockitoComponentManager componentManager) throws Exception { @@ -158,6 +170,7 @@ void configure(MockitoComponentManager componentManager) throws Exception .thenReturn(new DocumentReference("what", "ever", "WebHome")); when(entityReferenceProvider.getDefaultReference(EntityType.SPACE)) .thenReturn(new SpaceReference("whatever", "Main")); + when(this.linkStoreProvider.get()).thenReturn(this.linkStore); } private void assertLog(Level level, String message, Object... arguments) @@ -892,4 +905,23 @@ void rename() throws Exception verify(this.xwiki).renameDocument(source, target, true, List.of(), List.of(), this.xcontext); } + + @Test + void getBackLinkedDocuments() throws Exception + { + EntityReference source = mock(EntityReference.class); + EntityReference ref1 = mock(EntityReference.class, "ref1"); + EntityReference ref2 = mock(EntityReference.class, "ref2"); + EntityReference ref3 = mock(EntityReference.class, "ref3"); + when(this.linkStore.resolveBackLinkedEntities(source)).thenReturn(Set.of(ref1, ref2, ref3)); + + DocumentReference docRef1 = mock(DocumentReference.class, "docRef1"); + DocumentReference docRef2 = mock(DocumentReference.class, "docRef2"); + DocumentReference docRef3 = mock(DocumentReference.class, "docRef3"); + when(this.documentReferenceResolver.resolve(ref1, this.xcontext)).thenReturn(docRef1); + when(this.documentReferenceResolver.resolve(ref2, this.xcontext)).thenReturn(docRef2); + when(this.documentReferenceResolver.resolve(ref3, this.xcontext)).thenReturn(docRef3); + + assertEquals(Set.of(docRef1, docRef2, docRef3), this.modelBridge.getBackLinkedDocuments(source)); + } } diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/test/java/org/xwiki/rendering/internal/macro/include/IncludeMacroRefactoringTest.java b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/test/java/org/xwiki/rendering/internal/macro/include/IncludeMacroRefactoringTest.java index 93c0192c8c2..67b78ddd6e6 100644 --- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/test/java/org/xwiki/rendering/internal/macro/include/IncludeMacroRefactoringTest.java +++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/test/java/org/xwiki/rendering/internal/macro/include/IncludeMacroRefactoringTest.java @@ -226,7 +226,7 @@ void replaceDocumentReferenceWhenIncludingDocumentRenamedUsingPageParameterAndNo new EntityReference("sourcewiki", EntityType.WIKI))).thenReturn("sourcespace/foo"); Optional result = this.includeMacroRefactoring.replaceReference(block, null, - sourceReference, targetReference, false, Map.of()); + sourceReference, targetReference, false); assertFalse(result.isEmpty()); assertEquals("sourcewiki:sourcespace.foo", result.get().getParameter("page")); }