[ https://issues.apache.org/jira/browse/SLING-5719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15322153#comment-15322153 ]
Konrad Windszus commented on SLING-5719: ---------------------------------------- [~jenslauterbach] Since you found a workaround and the exposure of the resource resolver factory is now tracked in SLING-5769 I close this issue as Won't Fix. > Missing isLive() test before closing ResourceResolver > ----------------------------------------------------- > > Key: SLING-5719 > URL: https://issues.apache.org/jira/browse/SLING-5719 > Project: Sling > Issue Type: Bug > Components: Testing > Affects Versions: Testing Sling Mock 1.6.2 > Reporter: Jens Lauterbach > Priority: Minor > Labels: easyfix > Attachments: resourceResolverIsLive.patch > > > I am currently writing tests that involve the {{SlingContext}} and its > {{ResourceResolver}}: > {code} > @Rule > public final SlingContext context = new > SlingContext(ResourceResolverType.JCR_MOCK); > [... code ...] > @Test > public void testSomething() { > ResourceResolver resolver = this.context.resourceResolver(); > someOtherMethod(resolver); > } > {code} > If the resolver is closed in {{someOtherMethod()}} the test will fail because > after the test runs the {{SlingContextImpl}} mehtod {{tearDown()}} is called > which will {{close()}} the resource resolver if it is not {{null}}. > The problem is that it won't test if the resource resolver {{isLive()}} which > will end in an exception and a failed test: > {quote} > java.lang.IllegalStateException: Resource resolver is already closed. > at > org.apache.sling.resourceresolver.impl.ResourceResolverImpl.checkClosed(ResourceResolverImpl.java:167) > at > org.apache.sling.resourceresolver.impl.ResourceResolverImpl.adaptTo(ResourceResolverImpl.java:718) > at > org.apache.sling.testing.mock.sling.context.SlingContextImpl.tearDown(SlingContextImpl.java:145) > at > org.apache.sling.testing.mock.sling.junit.SlingContext.access$300(SlingContext.java:32) > at > org.apache.sling.testing.mock.sling.junit.SlingContext$1.after(SlingContext.java:120) > at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:50) > at org.junit.rules.RunRules.evaluate(RunRules.java:20) > at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) > at > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) > at > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) > at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) > at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) > at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) > at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) > at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) > at org.junit.runners.ParentRunner.run(ParentRunner.java:309) > at org.junit.runner.JUnitCore.run(JUnitCore.java:160) > at > com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119) > at > com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) > at > com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) > at > com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74) > {quote} > Github link to the line in question: > https://github.com/apache/sling/blob/4da6392078b73f0f20d3d66e87743cf4e86f4ecb/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java#L161 -- This message was sent by Atlassian JIRA (v6.3.4#6332)