From 514e0898e27f6e5025d78d3d76e72a6362abee52 Mon Sep 17 00:00:00 2001
From: Michael Hamann <michael.hamann@xwiki.com>
Date: Tue, 16 Jan 2024 16:53:17 +0100
Subject: [PATCH] XWIKI-21553: Do not override existing documents on user
 action

* Remove mock() call not available in 14.10.x
* Use constants for user and document reference in the test

(cherry picked from commit f140102575cbdbb5a517caf51270fa669df23667)
---
 .../DocumentOverrideListenerTest.java         | 24 +++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/org/xwiki/internal/document/DocumentOverrideListenerTest.java b/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/org/xwiki/internal/document/DocumentOverrideListenerTest.java
index e5f1f45e126..37155d90d7d 100644
--- a/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/org/xwiki/internal/document/DocumentOverrideListenerTest.java
+++ b/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/org/xwiki/internal/document/DocumentOverrideListenerTest.java
@@ -46,39 +46,39 @@
 @ComponentList({ DefaultObservationManager.class, DocumentOverrideListener.class })
 class DocumentOverrideListenerTest
 {
+    private static final DocumentReference DOCUMENT_REFERENCE = new DocumentReference("wiki", "space", "page");
+
+    private static final DocumentReference USER_REFERENCE = new DocumentReference("wiki", "XWiki", "user");
+
     @InjectMockitoOldcore
     private MockitoOldcore oldcore;
 
     @Test
     void savingNewDocument() throws Exception
     {
-        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
-        XWikiDocument document = new XWikiDocument(documentReference);
-        this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext());
+        XWikiDocument document = new XWikiDocument(DOCUMENT_REFERENCE);
+        this.oldcore.getSpyXWiki().checkSavingDocument(USER_REFERENCE, document, this.oldcore.getXWikiContext());
     }
 
     @Test
     void savingExistingDocument() throws Exception
     {
-        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
-        XWikiDocument document = new XWikiDocument(documentReference);
+        XWikiDocument document = new XWikiDocument(DOCUMENT_REFERENCE);
         this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
-        document = this.oldcore.getSpyXWiki().getDocument(documentReference, this.oldcore.getXWikiContext());
+        document = this.oldcore.getSpyXWiki().getDocument(DOCUMENT_REFERENCE, this.oldcore.getXWikiContext());
         assertFalse(document.isNew());
-        this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext());
+        this.oldcore.getSpyXWiki().checkSavingDocument(USER_REFERENCE, document, this.oldcore.getXWikiContext());
     }
 
     @Test
     void savingOverridingExistingDocument() throws Exception
     {
-        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
-        DocumentReference userReference = new DocumentReference("wiki", "XWiki", "user");
-        XWikiDocument document = new XWikiDocument(documentReference);
+        XWikiDocument document = new XWikiDocument(DOCUMENT_REFERENCE);
         this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
-        XWikiDocument newDocument = new XWikiDocument(documentReference);
+        XWikiDocument newDocument = new XWikiDocument(DOCUMENT_REFERENCE);
         XWikiException exception = assertThrows(XWikiException.class,
             () -> this.oldcore.getSpyXWiki()
-                .checkSavingDocument(userReference, newDocument, this.oldcore.getXWikiContext()));
+                .checkSavingDocument(USER_REFERENCE, newDocument, this.oldcore.getXWikiContext()));
         assertEquals("Error number 9001 in 9: User [wiki:XWiki.user] has been denied the right to save the "
             + "document [wiki:space.page]. Reason: [The document already exists but the document to be saved is marked "
             + "as new.]", exception.getMessage());
-- 
GitLab