You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by jo...@apache.org on 2023/07/19 07:19:54 UTC
[sling-org-apache-sling-servlets-post] branch master updated: SLING-11972 add support for java 17 build (#23)
This is an automated email from the ASF dual-hosted git repository.
joerghoh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-post.git
The following commit(s) were added to refs/heads/master by this push:
new 7308e0c SLING-11972 add support for java 17 build (#23)
7308e0c is described below
commit 7308e0c77583d1477efd6c1a0d7c35b92ca1e76e
Author: Jörg Hoh <jo...@users.noreply.github.com>
AuthorDate: Wed Jul 19 09:19:49 2023 +0200
SLING-11972 add support for java 17 build (#23)
---
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"));