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

sseifert pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git


The following commit(s) were added to refs/heads/master by this push:
     new e20a483  SLING-13063: [Sling Models] Migrate SlingObject, Self, and 
legacy Injector tests to JUnit 5 (#71)
e20a483 is described below

commit e20a483d4c2b377f9eb7d8da9b91e4454d9fcf0d
Author: Bhavik Kothari <[email protected]>
AuthorDate: Tue Jan 20 19:16:12 2026 +0530

    SLING-13063: [Sling Models] Migrate SlingObject, Self, and legacy Injector 
tests to JUnit 5 (#71)
    
    Co-authored-by: Bhavik Kothari <[email protected]>
---
 .../injectors/ResourceResolverInjectorTest.java    | 22 +++++-----
 .../models/impl/injectors/SelfInjectorTest.java    | 40 ++++++++---------
 .../injectors/SlingObjectInjectorRequestTest.java  | 51 ++++++++++++----------
 .../SlingObjectInjectorResourceResolverTest.java   | 26 +++++------
 .../injectors/SlingObjectInjectorResourceTest.java | 39 +++++++++--------
 5 files changed, 91 insertions(+), 87 deletions(-)

diff --git 
a/src/test/java/org/apache/sling/models/impl/injectors/ResourceResolverInjectorTest.java
 
b/src/test/java/org/apache/sling/models/impl/injectors/ResourceResolverInjectorTest.java
index 0a4a016..192c473 100644
--- 
a/src/test/java/org/apache/sling/models/impl/injectors/ResourceResolverInjectorTest.java
+++ 
b/src/test/java/org/apache/sling/models/impl/injectors/ResourceResolverInjectorTest.java
@@ -25,13 +25,13 @@ import org.apache.sling.api.SlingJakartaHttpServletResponse;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.models.spi.DisposalCallbackRegistry;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -41,8 +41,8 @@ import static org.mockito.Mockito.when;
  * Leaving unit test to ensure the same behavior.
  *
  */
-@RunWith(MockitoJUnitRunner.class)
-public class ResourceResolverInjectorTest {
+@ExtendWith(MockitoExtension.class)
+class ResourceResolverInjectorTest {
 
     private SlingObjectInjector injector = new SlingObjectInjector();
 
@@ -53,7 +53,7 @@ public class ResourceResolverInjectorTest {
     private DisposalCallbackRegistry registry;
 
     @Test
-    public void testFromResource() {
+    void testFromResource() {
         Resource resource = mock(Resource.class);
         ResourceResolver resourceResolver = mock(ResourceResolver.class);
         when(resource.getResourceResolver()).thenReturn(resourceResolver);
@@ -63,7 +63,7 @@ public class ResourceResolverInjectorTest {
     }
 
     @Test
-    public void testFromJakartaRequest() {
+    void testFromJakartaRequest() {
         SlingJakartaHttpServletRequest jakartaRequest = 
mock(SlingJakartaHttpServletRequest.class);
         ResourceResolver resourceResolver = mock(ResourceResolver.class);
         
when(jakartaRequest.getResourceResolver()).thenReturn(resourceResolver);
@@ -78,7 +78,7 @@ public class ResourceResolverInjectorTest {
      */
     @Deprecated
     @Test
-    public void testFromJavaxRequest() {
+    void testFromJavaxRequest() {
         org.apache.sling.api.SlingHttpServletRequest javaxRequest =
                 mock(org.apache.sling.api.SlingHttpServletRequest.class);
         ResourceResolver resourceResolver = mock(ResourceResolver.class);
@@ -89,7 +89,7 @@ public class ResourceResolverInjectorTest {
     }
 
     @Test
-    public void testFromSomethingElse() {
+    void testFromSomethingElse() {
         SlingJakartaHttpServletResponse response = 
mock(SlingJakartaHttpServletResponse.class);
 
         Object result = injector.getValue(response, "resourceResolver", 
ResourceResolver.class, element, registry);
diff --git 
a/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java 
b/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java
index 33271d6..856b07e 100644
--- a/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/injectors/SelfInjectorTest.java
@@ -31,19 +31,19 @@ import 
org.apache.sling.models.annotations.injectorspecific.Self;
 import org.apache.sling.models.impl.model.ConstructorParameter;
 import org.apache.sling.models.spi.DisposalCallbackRegistry;
 import 
org.apache.sling.models.spi.injectorspecific.StaticInjectAnnotationProcessorFactory;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
-public class SelfInjectorTest {
+@ExtendWith(MockitoExtension.class)
+class SelfInjectorTest {
 
     private SelfInjector injector = new SelfInjector();
 
@@ -62,8 +62,8 @@ public class SelfInjectorTest {
     private ConstructorParameter firstConstructorParameter;
     private ConstructorParameter secondConstructorParameter;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         
lenient().when(modelAnnotation.defaultInjectionStrategy()).thenReturn(DefaultInjectionStrategy.REQUIRED);
         firstConstructorParameter = new ConstructorParameter(
                 new Annotation[0],
@@ -86,7 +86,7 @@ public class SelfInjectorTest {
     }
 
     @Test
-    public void testJakartaMatchingClass() {
+    void testJakartaMatchingClass() {
         assertSame(
                 request,
                 injector.getValue(
@@ -110,7 +110,7 @@ public class SelfInjectorTest {
      */
     @Deprecated
     @Test
-    public void testJavaxMatchingClass() {
+    void testJavaxMatchingClass() {
         org.apache.sling.api.SlingHttpServletRequest javaxRequest =
                 JakartaToJavaxRequestWrapper.toJavaxRequest(request);
         assertSame(
@@ -136,7 +136,7 @@ public class SelfInjectorTest {
     }
 
     @Test
-    public void testJakartaMatchingSubClass() {
+    void testJakartaMatchingSubClass() {
         assertSame(
                 request,
                 injector.getValue(
@@ -159,7 +159,7 @@ public class SelfInjectorTest {
      */
     @Deprecated
     @Test
-    public void testJavaxMatchingSubClass() {
+    void testJavaxMatchingSubClass() {
         org.apache.sling.api.SlingHttpServletRequest javaxRequest =
                 JakartaToJavaxRequestWrapper.toJavaxRequest(request);
         assertSame(
@@ -181,7 +181,7 @@ public class SelfInjectorTest {
     }
 
     @Test
-    public void testNotMatchingClass() {
+    void testNotMatchingClass() {
         assertNull(injector.getValue(
                 request,
                 "notRelevant",
@@ -198,7 +198,7 @@ public class SelfInjectorTest {
     }
 
     @Test
-    public void testJakartaWithNullName() {
+    void testJakartaWithNullName() {
         assertSame(
                 request,
                 injector.getValue(
@@ -221,7 +221,7 @@ public class SelfInjectorTest {
      */
     @Deprecated
     @Test
-    public void testJavaxWithNullName() {
+    void testJavaxWithNullName() {
         org.apache.sling.api.SlingHttpServletRequest javaxRequest =
                 JakartaToJavaxRequestWrapper.toJavaxRequest(request);
         assertSame(
@@ -243,7 +243,7 @@ public class SelfInjectorTest {
     }
 
     @Test
-    public void testJakartaMatchingClassWithSelfAnnotation() {
+    void testJakartaMatchingClassWithSelfAnnotation() {
         
when(annotatedElement.isAnnotationPresent(Self.class)).thenReturn(true);
         Object result = injector.getValue(
                 request, "notRelevant", SlingJakartaHttpServletRequest.class, 
annotatedElement, registry);
@@ -255,7 +255,7 @@ public class SelfInjectorTest {
      */
     @Deprecated
     @Test
-    public void testJavaxMatchingClassWithSelfAnnotation() {
+    void testJavaxMatchingClassWithSelfAnnotation() {
         org.apache.sling.api.SlingHttpServletRequest javaxRequest =
                 JakartaToJavaxRequestWrapper.toJavaxRequest(request);
         
when(annotatedElement.isAnnotationPresent(Self.class)).thenReturn(true);
@@ -269,7 +269,7 @@ public class SelfInjectorTest {
     }
 
     @Test
-    public void testNotMatchingClassWithSelfAnnotation() {
+    void testNotMatchingClassWithSelfAnnotation() {
         
when(annotatedElement.isAnnotationPresent(Self.class)).thenReturn(true);
         Object result = injector.getValue(request, "notRelevant", 
ResourceResolver.class, annotatedElement, registry);
         assertSame(request, result);
diff --git 
a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorRequestTest.java
 
b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorRequestTest.java
index ae104f3..f373223 100644
--- 
a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorRequestTest.java
+++ 
b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorRequestTest.java
@@ -33,19 +33,20 @@ import org.apache.sling.api.scripting.SlingScriptHelper;
 import org.apache.sling.api.wrappers.JakartaToJavaxResponseWrapper;
 import org.apache.sling.models.annotations.injectorspecific.SlingObject;
 import org.apache.sling.models.spi.DisposalCallbackRegistry;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
-public class SlingObjectInjectorRequestTest {
+@ExtendWith(MockitoExtension.class)
+class SlingObjectInjectorRequestTest {
 
     private final SlingObjectInjector injector = new SlingObjectInjector();
 
@@ -71,26 +72,28 @@ public class SlingObjectInjectorRequestTest {
     private DisposalCallbackRegistry registry;
 
     @SuppressWarnings("deprecation")
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         SlingBindings bindings = new SlingBindings();
         bindings.put(SlingBindings.SLING, this.scriptHelper);
-        
when(this.request.getResourceResolver()).thenReturn(this.resourceResolver);
-        when(this.request.getResource()).thenReturn(this.resource);
-        
when(this.request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);
-        
when(this.scriptHelper.getResponse()).thenReturn(JakartaToJavaxResponseWrapper.toJavaxResponse(this.response));
-        when(this.scriptHelper.getJakartaResponse()).thenReturn(this.response);
+        
lenient().when(this.request.getResourceResolver()).thenReturn(this.resourceResolver);
+        lenient().when(this.request.getResource()).thenReturn(this.resource);
+        
lenient().when(this.request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);
+        lenient()
+                .when(this.scriptHelper.getResponse())
+                
.thenReturn(JakartaToJavaxResponseWrapper.toJavaxResponse(this.response));
+        
lenient().when(this.scriptHelper.getJakartaResponse()).thenReturn(this.response);
     }
 
     @Test
-    public void testResourceResolver() {
+    void testResourceResolver() {
         Object result =
                 this.injector.getValue(this.request, null, 
ResourceResolver.class, this.annotatedElement, registry);
         assertSame(this.resourceResolver, result);
     }
 
     @Test
-    public void testResource() {
+    void testResource() {
         Object result = this.injector.getValue(this.request, null, 
Resource.class, this.annotatedElement, registry);
         assertNull(result);
 
@@ -100,7 +103,7 @@ public class SlingObjectInjectorRequestTest {
     }
 
     @Test
-    public void testJakartaRequest() {
+    void testJakartaRequest() {
         Object result = this.injector.getValue(
                 this.request, null, SlingJakartaHttpServletRequest.class, 
this.annotatedElement, registry);
         assertSame(this.request, result);
@@ -114,7 +117,7 @@ public class SlingObjectInjectorRequestTest {
      */
     @Deprecated(since = "2.0.0")
     @Test
-    public void testJavaxResponse() {
+    void testJavaxResponse() {
         Object result = this.injector.getValue(
                 this.request,
                 null,
@@ -135,7 +138,7 @@ public class SlingObjectInjectorRequestTest {
      */
     @Deprecated(since = "2.0.0")
     @Test
-    public void testJavaxRequest() {
+    void testJavaxRequest() {
         Object result = this.injector.getValue(
                 this.request,
                 null,
@@ -152,7 +155,7 @@ public class SlingObjectInjectorRequestTest {
     }
 
     @Test
-    public void testJakartaResponse() {
+    void testJakartaResponse() {
         Object result = this.injector.getValue(
                 this.request, null, SlingJakartaHttpServletResponse.class, 
this.annotatedElement, registry);
         assertSame(this.response, result);
@@ -162,14 +165,14 @@ public class SlingObjectInjectorRequestTest {
     }
 
     @Test
-    public void testScriptHelper() {
+    void testScriptHelper() {
         Object result =
                 this.injector.getValue(this.request, null, 
SlingScriptHelper.class, this.annotatedElement, registry);
         assertSame(this.scriptHelper, result);
     }
 
     @Test
-    public void testInvalid() {
+    void testInvalid() {
         Object result = this.injector.getValue(this, null, 
SlingScriptHelper.class, this.annotatedElement, registry);
         assertNull(result);
     }
diff --git 
a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceResolverTest.java
 
b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceResolverTest.java
index 6519dc9..a066af8 100644
--- 
a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceResolverTest.java
+++ 
b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceResolverTest.java
@@ -26,16 +26,16 @@ import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.scripting.SlingScriptHelper;
 import org.apache.sling.models.spi.DisposalCallbackRegistry;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 
-@RunWith(MockitoJUnitRunner.class)
-public class SlingObjectInjectorResourceResolverTest {
+@ExtendWith(MockitoExtension.class)
+class SlingObjectInjectorResourceResolverTest {
 
     private final SlingObjectInjector injector = new SlingObjectInjector();
 
@@ -49,14 +49,14 @@ public class SlingObjectInjectorResourceResolverTest {
     private DisposalCallbackRegistry registry;
 
     @Test
-    public void testResourceResolver() {
+    void testResourceResolver() {
         Object result = this.injector.getValue(
                 this.resourceResolver, null, ResourceResolver.class, 
this.annotatedElement, registry);
         assertSame(this.resourceResolver, result);
     }
 
     @Test
-    public void testResource() {
+    void testResource() {
         Object result =
                 this.injector.getValue(this.resourceResolver, null, 
Resource.class, this.annotatedElement, registry);
         assertNull(result);
@@ -67,7 +67,7 @@ public class SlingObjectInjectorResourceResolverTest {
      */
     @Deprecated(since = "2.0.0")
     @Test
-    public void testJavaxRequest() {
+    void testJavaxRequest() {
         Object result = this.injector.getValue(
                 this.resourceResolver,
                 null,
@@ -82,7 +82,7 @@ public class SlingObjectInjectorResourceResolverTest {
      */
     @Deprecated(since = "2.0.0")
     @Test
-    public void testJavaxResponse() {
+    void testJavaxResponse() {
         Object result = this.injector.getValue(
                 this.resourceResolver,
                 null,
@@ -93,28 +93,28 @@ public class SlingObjectInjectorResourceResolverTest {
     }
 
     @Test
-    public void testJakartaRequest() {
+    void testJakartaRequest() {
         Object result = this.injector.getValue(
                 this.resourceResolver, null, 
SlingJakartaHttpServletRequest.class, this.annotatedElement, registry);
         assertNull(result);
     }
 
     @Test
-    public void testJakartaResponse() {
+    void testJakartaResponse() {
         Object result = this.injector.getValue(
                 this.resourceResolver, null, 
SlingJakartaHttpServletResponse.class, this.annotatedElement, registry);
         assertNull(result);
     }
 
     @Test
-    public void testScriptHelper() {
+    void testScriptHelper() {
         Object result = this.injector.getValue(
                 this.resourceResolver, null, SlingScriptHelper.class, 
this.annotatedElement, registry);
         assertNull(result);
     }
 
     @Test
-    public void testInvalid() {
+    void testInvalid() {
         Object result = this.injector.getValue(this, null, 
SlingScriptHelper.class, this.annotatedElement, registry);
         assertNull(result);
     }
diff --git 
a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceTest.java
 
b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceTest.java
index cd192ed..b803377 100644
--- 
a/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceTest.java
+++ 
b/src/test/java/org/apache/sling/models/impl/injectors/SlingObjectInjectorResourceTest.java
@@ -27,18 +27,19 @@ import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.scripting.SlingScriptHelper;
 import org.apache.sling.models.annotations.injectorspecific.SlingObject;
 import org.apache.sling.models.spi.DisposalCallbackRegistry;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
-public class SlingObjectInjectorResourceTest {
+@ExtendWith(MockitoExtension.class)
+class SlingObjectInjectorResourceTest {
 
     private final SlingObjectInjector injector = new SlingObjectInjector();
 
@@ -54,20 +55,20 @@ public class SlingObjectInjectorResourceTest {
     @Mock
     private DisposalCallbackRegistry registry;
 
-    @Before
-    public void setUp() {
-        
when(this.resource.getResourceResolver()).thenReturn(this.resourceResolver);
+    @BeforeEach
+    void setUp() {
+        
lenient().when(this.resource.getResourceResolver()).thenReturn(this.resourceResolver);
     }
 
     @Test
-    public void testResourceResolver() {
+    void testResourceResolver() {
         Object result =
                 this.injector.getValue(this.resource, null, 
ResourceResolver.class, this.annotatedElement, registry);
         assertSame(this.resourceResolver, result);
     }
 
     @Test
-    public void testResource() {
+    void testResource() {
         Object result = this.injector.getValue(this.resource, null, 
Resource.class, this.annotatedElement, registry);
         assertNull(result);
 
@@ -81,7 +82,7 @@ public class SlingObjectInjectorResourceTest {
      */
     @Deprecated(since = "2.0.0")
     @Test
-    public void testJavaxRequest() {
+    void testJavaxRequest() {
         Object result = this.injector.getValue(
                 this.resource,
                 null,
@@ -96,7 +97,7 @@ public class SlingObjectInjectorResourceTest {
      */
     @Deprecated(since = "2.0.0")
     @Test
-    public void testJavaxResponse() {
+    void testJavaxResponse() {
         Object result = this.injector.getValue(
                 this.resource,
                 null,
@@ -107,28 +108,28 @@ public class SlingObjectInjectorResourceTest {
     }
 
     @Test
-    public void testJakartaRequest() {
+    void testJakartaRequest() {
         Object result = this.injector.getValue(
                 this.resource, null, SlingJakartaHttpServletRequest.class, 
this.annotatedElement, registry);
         assertNull(result);
     }
 
     @Test
-    public void testJakartaResponse() {
+    void testJakartaResponse() {
         Object result = this.injector.getValue(
                 this.resource, null, SlingJakartaHttpServletResponse.class, 
this.annotatedElement, registry);
         assertNull(result);
     }
 
     @Test
-    public void testScriptHelper() {
+    void testScriptHelper() {
         Object result =
                 this.injector.getValue(this.resource, null, 
SlingScriptHelper.class, this.annotatedElement, registry);
         assertNull(result);
     }
 
     @Test
-    public void testInvalid() {
+    void testInvalid() {
         Object result = this.injector.getValue(this, null, 
SlingScriptHelper.class, this.annotatedElement, registry);
         assertNull(result);
     }

Reply via email to