This is an automated email from the ASF dual-hosted git repository.

joerghoh pushed a commit to branch SLING-11972-java-17
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-post.git

commit 7c6351b3dff3e2d10207384afc96e13ddb32c6fd
Author: Joerg Hoh <[email protected]>
AuthorDate: Tue Jul 18 19:51:23 2023 +0200

    SLING-11972 add support for java 17 build
---
 pom.xml                                                      |  4 ++--
 .../apache/sling/servlets/post/impl/SlingPostServlet.java    | 12 +++++++++++-
 .../sling/servlets/post/impl/SlingPostServletTest.java       |  7 +++----
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/pom.xml b/pom.xml
index d6f31c8..e0f778f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -196,8 +196,8 @@
         </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
-            <artifactId>mockito-all</artifactId>
-            <version>1.9.5</version>
+            <artifactId>mockito-core</artifactId>
+            <version>5.3.1</version>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git 
a/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java 
b/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
index 24ca1a9..cc6a5a4 100644
--- a/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
+++ b/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
@@ -168,7 +168,7 @@ public class SlingPostServlet extends 
SlingAllMethodsServlet {
     /**
      * default log
      */
-    private final Logger log = LoggerFactory.getLogger(getClass());
+    private Logger log = LoggerFactory.getLogger(getClass());
 
     private static final String PARAM_CHECKIN_ON_CREATE = 
":checkinNewVersionableNodes";
 
@@ -859,4 +859,14 @@ public class SlingPostServlet extends 
SlingAllMethodsServlet {
         public PostResponseCreator creator;
         public int ranking;
     }
+    
+    // for testing
+    protected void setLog(Logger log) {
+        this.log = log;
+    }
+    
+    // for testing
+    protected void setLogStacktraceInExceptions(boolean flag) {
+        this.logStacktraceInExceptions = flag;
+    }
 }
diff --git 
a/src/test/java/org/apache/sling/servlets/post/impl/SlingPostServletTest.java 
b/src/test/java/org/apache/sling/servlets/post/impl/SlingPostServletTest.java
index 4a594b9..be025f9 100644
--- 
a/src/test/java/org/apache/sling/servlets/post/impl/SlingPostServletTest.java
+++ 
b/src/test/java/org/apache/sling/servlets/post/impl/SlingPostServletTest.java
@@ -40,7 +40,6 @@ import junit.framework.TestCase;
 
 import org.mockito.Mockito;
 import static org.mockito.Mockito.eq;
-import org.mockito.internal.util.reflection.Whitebox;
 import org.slf4j.Logger;
 
 public class SlingPostServletTest extends TestCase {
@@ -132,16 +131,16 @@ public class SlingPostServletTest extends TestCase {
         Resource mockResource = Mockito.mock(Resource.class);
         Mockito.when(mockResource.getPath()).thenReturn("/path");
         Mockito.when(mockRequest.getResource()).thenReturn(mockResource);
-        Whitebox.setInternalState(servlet, "log", log);
+        servlet.setLog(log);
         PostOperation operation = new DeleteOperation();
         Exception exception = new IOException("foo");
         
-        Whitebox.setInternalState(servlet, "logStacktraceInExceptions", true);
+        servlet.setLogStacktraceInExceptions(true);
         String expected = "Exception while handling POST on path [{}] with 
operation [{}]";
         servlet.logPersistenceException(mockRequest, operation, exception);
         
Mockito.verify(log).warn(eq(expected),eq("/path"),eq("org.apache.sling.servlets.post.impl.operations.DeleteOperation"),eq(exception));
         
-        Whitebox.setInternalState(servlet, "logStacktraceInExceptions", false);
+        servlet.setLogStacktraceInExceptions(false);
         expected = "{} while handling POST on path [{}] with operation [{}]: 
{}";
         servlet.logPersistenceException(mockRequest, operation, exception);
         
Mockito.verify(log).warn(eq(expected),eq("java.io.IOException"),eq("/path"),eq("org.apache.sling.servlets.post.impl.operations.DeleteOperation"),eq("foo"));
  

Reply via email to