You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2022/06/01 07:09:32 UTC
[sling-org-apache-sling-testing-sling-mock] branch bugfix/sling-bindings-replaced created (now a14770a)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a change to branch bugfix/sling-bindings-replaced
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
at a14770a SLING-11362 Prevent potential ClassCastException in tearDown
This branch includes the following new commits:
new a14770a SLING-11362 Prevent potential ClassCastException in tearDown
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[sling-org-apache-sling-testing-sling-mock] 01/01: SLING-11362 Prevent potential ClassCastException in tearDown
Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch bugfix/sling-bindings-replaced
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit a14770ab2d590a2ca431bd97430cd07e4899087d
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Jun 1 09:09:27 2022 +0200
SLING-11362 Prevent potential ClassCastException in tearDown
---
.../apache/sling/testing/mock/sling/context/SlingContextImpl.java | 6 +++---
.../testing/mock/sling/context/AbstractSlingContextImplTest.java | 8 ++++++++
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/core/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java b/core/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index a8b0b48..e4c61f2 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -217,9 +217,9 @@ public class SlingContextImpl extends OsgiContextImpl {
protected void tearDown() {
if (this.request != null) {
- MockSlingBindings slingBindings = (MockSlingBindings)this.request.getAttribute(SlingBindings.class.getName());
- if (slingBindings != null) {
- slingBindings.tearDown();
+ SlingBindings slingBindings = (SlingBindings)this.request.getAttribute(SlingBindings.class.getName());
+ if (slingBindings != null && slingBindings instanceof MockSlingBindings) {
+ ((MockSlingBindings)slingBindings).tearDown();
}
}
diff --git a/core/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java b/core/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
index a40c75f..65e0b43 100644
--- a/core/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
+++ b/core/src/test/java/org/apache/sling/testing/mock/sling/context/AbstractSlingContextImplTest.java
@@ -82,6 +82,14 @@ public abstract class AbstractSlingContextImplTest {
assertSame(context.slingScriptHelper(), bindings.get(SlingBindings.SLING));
}
+ @Test
+ public void testNonMockedSlingBindings() {
+ final SlingBindings slingBindings = new SlingBindings();
+ context.request().setAttribute(SlingBindings.class.getName(), slingBindings);
+ SlingBindings bindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());
+ assertNotNull(bindings);
+ }
+
@Test
public void testSetCurrentResource() {
context.currentResource("/content/sample/en/jcr:content/par/colctrl");