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 ad8350e  SLING-13066: [Sling Models] Migrate implpicker and basic root 
tests to JUnit 5 (#73)
ad8350e is described below

commit ad8350e563d011f14a8434ec5bdef52c42b60da4
Author: Bhavik Kothari <[email protected]>
AuthorDate: Fri Jan 23 14:05:31 2026 +0530

    SLING-13066: [Sling Models] Migrate implpicker and basic root tests to 
JUnit 5 (#73)
---
 .../sling/models/impl/AdapterFactoryTest.java      | 49 +++++++++++---------
 .../models/impl/AdapterImplementationsTest.java    | 44 +++++++++---------
 .../sling/models/impl/AnnotationConflictsTest.java | 49 ++++++++++----------
 .../org/apache/sling/models/impl/CachingTest.java  | 46 +++++++++---------
 .../apache/sling/models/impl/ConstructorTest.java  | 54 +++++++++++-----------
 .../models/impl/ConstructorVisibilityTest.java     | 24 +++++-----
 .../sling/models/impl/CustomInjectorTest.java      | 24 +++++-----
 .../implpicker/FirstImplementationPickerTest.java  | 16 +++----
 8 files changed, 156 insertions(+), 150 deletions(-)

diff --git a/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java 
b/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
index 94dbb7a..003dd5f 100644
--- a/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
+++ b/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
@@ -44,7 +44,6 @@ import 
org.apache.sling.models.testmodels.classes.InvalidModelWithMissingAnnotat
 import 
org.apache.sling.models.testmodels.classes.ResourceModelWithRequiredField;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -56,6 +55,12 @@ import org.osgi.service.component.ComponentContext;
 import org.osgi.util.converter.Converter;
 import org.osgi.util.converter.Converters;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -109,39 +114,37 @@ public class AdapterFactoryTest {
 
     @Test
     void testIsModelClass() {
-        Assertions.assertTrue(factory.isModelClass(DefaultStringModel.class));
-        
Assertions.assertFalse(factory.isModelClass(InvalidModelWithMissingAnnotation.class));
+        assertTrue(factory.isModelClass(DefaultStringModel.class));
+        
assertFalse(factory.isModelClass(InvalidModelWithMissingAnnotation.class));
     }
 
     @Test
     void testCanCreateFromAdaptable() {
-        Assertions.assertTrue(factory.canCreateFromAdaptable(resource, 
DefaultStringModel.class));
-        Assertions.assertFalse(factory.canCreateFromAdaptable(request, 
DefaultStringModel.class));
+        assertTrue(factory.canCreateFromAdaptable(resource, 
DefaultStringModel.class));
+        assertFalse(factory.canCreateFromAdaptable(request, 
DefaultStringModel.class));
     }
 
     @Test
     void testCanCreateFromAdaptableWithInvalidModel() {
-        Assertions.assertFalse(factory.canCreateFromAdaptable(resource, 
InvalidModelWithMissingAnnotation.class));
+        assertFalse(factory.canCreateFromAdaptable(resource, 
InvalidModelWithMissingAnnotation.class));
     }
 
     @Test
     void testCreateFromNonModelClass() {
-        Assertions.assertThrows(
+        assertThrows(
                 ModelClassException.class,
                 () -> factory.createModel(resource, 
InvalidModelWithMissingAnnotation.class));
     }
 
     @Test
     void testCreateFromInvalidAdaptable() {
-        Assertions.assertThrows(
-                InvalidAdaptableException.class, () -> 
factory.createModel(request, DefaultStringModel.class));
+        assertThrows(InvalidAdaptableException.class, () -> 
factory.createModel(request, DefaultStringModel.class));
     }
 
     @Test
     void testCreateWithConstructorException() {
         // Internally all exceptions are wrapped within RuntimeExceptions
-        Assertions.assertThrows(
-                RuntimeException.class, () -> factory.createModel(resource, 
ConstructorWithExceptionModel.class));
+        assertThrows(RuntimeException.class, () -> 
factory.createModel(resource, ConstructorWithExceptionModel.class));
     }
 
     @Model(adaptables = SlingJakartaHttpServletRequest.class)
@@ -153,7 +156,7 @@ public class AdapterFactoryTest {
     @Test
     void testCreatedNestedModelWithInvalidAdaptable() {
         // nested model can only be adapted from another adaptable
-        Assertions.assertThrows(
+        assertThrows(
                 MissingElementsException.class,
                 () -> factory.createModel(request, 
NestedModelWithInvalidAdaptable.class));
     }
@@ -167,7 +170,7 @@ public class AdapterFactoryTest {
     @Test
     void testCreatedNestedModelWithInvalidAdaptable2() {
         // nested model is in fact no valid model
-        Assertions.assertThrows(
+        assertThrows(
                 MissingElementsException.class,
                 () -> factory.createModel(request, 
NestedModelWithInvalidAdaptable2.class));
     }
@@ -190,8 +193,8 @@ public class AdapterFactoryTest {
         when(resource.adaptTo(ValueMap.class)).thenReturn(vm);
 
         NestedModel model = factory.createModel(resource, NestedModel.class);
-        Assertions.assertNotNull(model);
-        Assertions.assertEquals("required", 
model.getNestedModel().getRequired());
+        assertNotNull(model);
+        assertEquals("required", model.getNestedModel().getRequired());
     }
 
     @Test
@@ -201,7 +204,7 @@ public class AdapterFactoryTest {
         ValueMap vm = new ValueMapDecorator(map);
         when(resource.adaptTo(ValueMap.class)).thenReturn(vm);
 
-        Assertions.assertThrows(MissingElementsException.class, () -> 
factory.createModel(resource, NestedModel.class));
+        assertThrows(MissingElementsException.class, () -> 
factory.createModel(resource, NestedModel.class));
     }
 
     @Test
@@ -211,9 +214,9 @@ public class AdapterFactoryTest {
         when(result.wasSuccessful()).thenReturn(true);
         when(result.getValue()).thenReturn(new Object());
 
-        String exported = Assertions.assertDoesNotThrow(() ->
+        String exported = assertDoesNotThrow(() ->
                 factory.handleAndExportResult(result, "second", String.class, 
Collections.<String, String>emptyMap()));
-        Assertions.assertEquals("Export from second", exported);
+        assertEquals("Export from second", exported);
     }
 
     @Test
@@ -223,9 +226,9 @@ public class AdapterFactoryTest {
         when(result.wasSuccessful()).thenReturn(true);
         when(result.getValue()).thenReturn(new Object());
 
-        Integer exported = Assertions.assertDoesNotThrow(() ->
+        Integer exported = assertDoesNotThrow(() ->
                 factory.handleAndExportResult(result, "first", Integer.class, 
Collections.<String, String>emptyMap()));
-        Assertions.assertEquals(Integer.valueOf(42), exported);
+        assertEquals(Integer.valueOf(42), exported);
     }
 
     @Test
@@ -235,7 +238,7 @@ public class AdapterFactoryTest {
         when(result.wasSuccessful()).thenReturn(true);
         when(result.getValue()).thenReturn(new Object());
 
-        Assertions.assertThrows(
+        assertThrows(
                 MissingExporterException.class,
                 () -> factory.handleAndExportResult(
                         result, "second", Integer.class, Collections.<String, 
String>emptyMap()));
@@ -339,7 +342,7 @@ public class AdapterFactoryTest {
         long maxHeapSize = Runtime.getRuntime().maxMemory();
         long maxInstances = (long) ((maxHeapSize / instanceSize) * 
LOAD_FACTOR);
 
-        Assertions.assertDoesNotThrow(() -> {
+        assertDoesNotThrow(() -> {
             for (long i = 0; i < maxInstances; i++) {
                 CachedModelWithSelfReference model = factory.createModel(
                         mock(SlingJakartaHttpServletRequest.class), 
CachedModelWithSelfReference.class);
@@ -349,6 +352,6 @@ public class AdapterFactoryTest {
             }
         });
         // Guard against silent failure: ensure heap is sufficient to run the 
test loop at least once
-        Assertions.assertTrue(maxInstances > 0);
+        assertTrue(maxInstances > 0);
     }
 }
diff --git 
a/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java 
b/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java
index 46cf836..e1a6261 100644
--- a/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java
+++ b/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java
@@ -27,20 +27,20 @@ import 
org.apache.sling.api.wrappers.JakartaToJavaxRequestWrapper;
 import org.apache.sling.models.spi.ImplementationPicker;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.jetbrains.annotations.NotNull;
-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 org.osgi.framework.BundleContext;
 
-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.lenient;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
-public class AdapterImplementationsTest {
+@ExtendWith(MockitoExtension.class)
+class AdapterImplementationsTest {
 
     private static final Class<?> SAMPLE_ADAPTER = Comparable.class;
     private static final Object SAMPLE_ADAPTABLE = new Object();
@@ -59,13 +59,13 @@ public class AdapterImplementationsTest {
     @Mock
     private ResourceResolver resourceResolver;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         underTest = new AdapterImplementations();
     }
 
     @Test
-    public void testNoMapping() {
+    void testNoMapping() {
         assertNull(underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE, 
Arrays.asList(new FirstImplementationPicker())));
 
         // make sure this raises no exception
@@ -73,7 +73,7 @@ public class AdapterImplementationsTest {
     }
 
     @Test
-    public void testSingleMapping() {
+    void testSingleMapping() {
         underTest.addAll(String.class, SAMPLE_ADAPTER);
 
         assertEquals(
@@ -88,7 +88,7 @@ public class AdapterImplementationsTest {
     }
 
     @Test
-    public void testMultipleMappings() {
+    void testMultipleMappings() {
         underTest.addAll(String.class, SAMPLE_ADAPTER);
         underTest.addAll(Integer.class, SAMPLE_ADAPTER);
         underTest.addAll(Long.class, SAMPLE_ADAPTER);
@@ -114,7 +114,7 @@ public class AdapterImplementationsTest {
     }
 
     @Test
-    public void testRemoveAll() {
+    void testRemoveAll() {
         underTest.addAll(String.class, SAMPLE_ADAPTER);
         underTest.addAll(Integer.class, SAMPLE_ADAPTER);
         underTest.addAll(Long.class, SAMPLE_ADAPTER);
@@ -125,7 +125,7 @@ public class AdapterImplementationsTest {
     }
 
     @Test
-    public void testMultipleImplementationPickers() {
+    void testMultipleImplementationPickers() {
         underTest.addAll(String.class, SAMPLE_ADAPTER);
         underTest.addAll(Integer.class, SAMPLE_ADAPTER);
         underTest.addAll(Long.class, SAMPLE_ADAPTER);
@@ -144,7 +144,7 @@ public class AdapterImplementationsTest {
     }
 
     @Test
-    public void testSimpleModel() {
+    void testSimpleModel() {
         underTest.addAll(SAMPLE_ADAPTER, SAMPLE_ADAPTER);
 
         assertEquals(
@@ -155,7 +155,7 @@ public class AdapterImplementationsTest {
     }
 
     @Test
-    public void testResourceTypeRegistrationForResource() {
+    void testResourceTypeRegistrationForResource() {
         when(resource.getResourceType()).thenReturn("sling/rt/one");
         when(resource.getResourceResolver()).thenReturn(resourceResolver);
         when(childResource.getResourceType()).thenReturn("sling/rt/child");
@@ -187,7 +187,7 @@ public class AdapterImplementationsTest {
     }
 
     @Test
-    public void testResourceTypeRegistrationForAbsolutePath() {
+    void testResourceTypeRegistrationForAbsolutePath() {
         when(resource.getResourceType()).thenReturn("sling/rt/one");
         when(resource.getResourceResolver()).thenReturn(resourceResolver);
         when(childResource.getResourceType()).thenReturn("sling/rt/child");
@@ -213,7 +213,7 @@ public class AdapterImplementationsTest {
     }
 
     @Test
-    public void testResourceTypeRegistrationForResourceHavingAbsolutePath() {
+    void testResourceTypeRegistrationForResourceHavingAbsolutePath() {
         when(resource.getResourceType()).thenReturn("/apps/sling/rt/one");
         when(resource.getResourceResolver()).thenReturn(resourceResolver);
         
when(childResource.getResourceType()).thenReturn("/apps/sling/rt/child");
@@ -238,7 +238,7 @@ public class AdapterImplementationsTest {
     }
 
     @Test
-    public void testResourceTypeRegistrationForJakartaRequest() {
+    void testResourceTypeRegistrationForJakartaRequest() {
         when(resource.getResourceType()).thenReturn("sling/rt/one");
         when(resource.getResourceResolver()).thenReturn(resourceResolver);
         
when(resourceResolver.getParentResourceType(resource)).thenReturn(null);
@@ -273,7 +273,7 @@ public class AdapterImplementationsTest {
      */
     @Deprecated
     @Test
-    public void testResourceTypeRegistrationForJavaxRequest() {
+    void testResourceTypeRegistrationForJavaxRequest() {
         org.apache.sling.api.SlingHttpServletRequest javaxRequest =
                 JakartaToJavaxRequestWrapper.toJavaxRequest(request);
 
@@ -313,7 +313,7 @@ public class AdapterImplementationsTest {
     }
 
     @Test
-    public void testResourceTypeRegistrationForResourceWithoutResourceType() {
+    void testResourceTypeRegistrationForResourceWithoutResourceType() {
         lenient().when(resource.getResourceType()).thenReturn(null);
         
lenient().when(resource.getResourceResolver()).thenReturn(resourceResolver);
         lenient().when(resourceResolver.getSearchPath()).thenReturn(new 
String[] {"/apps/", "/libs/"});
diff --git 
a/src/test/java/org/apache/sling/models/impl/AnnotationConflictsTest.java 
b/src/test/java/org/apache/sling/models/impl/AnnotationConflictsTest.java
index 2d65150..1740dec 100644
--- a/src/test/java/org/apache/sling/models/impl/AnnotationConflictsTest.java
+++ b/src/test/java/org/apache/sling/models/impl/AnnotationConflictsTest.java
@@ -34,29 +34,29 @@ import 
org.apache.sling.models.factory.MissingElementException;
 import org.apache.sling.models.factory.MissingElementsException;
 import org.apache.sling.models.impl.injectors.ValueMapInjector;
 import 
org.apache.sling.models.spi.injectorspecific.InjectAnnotationProcessorFactory;
-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.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.when;
 
 @SuppressWarnings("deprecation")
-@RunWith(MockitoJUnitRunner.class)
-public class AnnotationConflictsTest {
+@ExtendWith(MockitoExtension.class)
+class AnnotationConflictsTest {
 
     private ModelAdapterFactory factory;
 
     @Mock
     private Resource resource;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         factory = AdapterFactoryTest.createModelAdapterFactory();
         ValueMapInjector injector = new ValueMapInjector();
         factory.injectors = Arrays.asList(injector);
@@ -72,7 +72,7 @@ public class AnnotationConflictsTest {
 
     @Test
     @SuppressWarnings("unchecked")
-    public void testSucessfulAdaptations() {
+    void testSucessfulAdaptations() {
         for (Class<?> clazz : this.getClass().getDeclaredClasses()) {
             if (!clazz.isInterface() && 
clazz.getSimpleName().startsWith("Successful")) {
                 successful((Class<Methods>) clazz);
@@ -82,7 +82,7 @@ public class AnnotationConflictsTest {
 
     @Test
     @SuppressWarnings("unchecked")
-    public void testFailingAdaptations() {
+    void testFailingAdaptations() {
         for (Class<?> clazz : this.getClass().getDeclaredClasses()) {
             if (!clazz.isInterface() && 
clazz.getSimpleName().startsWith("Failing")) {
                 failing((Class<Methods>) clazz);
@@ -274,14 +274,14 @@ public class AnnotationConflictsTest {
         when(resource.adaptTo(ValueMap.class)).thenReturn(map);
 
         Methods model = factory.createModel(resource, modelClass);
-        assertNotNull("Adaptation to " + modelClass.getSimpleName() + " was 
not null.", model);
+        assertNotNull(model, "Adaptation to " + modelClass.getSimpleName() + " 
was not null.");
         assertNull(
-                "Adaptation to " + modelClass.getSimpleName() + " had a 
non-null emptyText value.",
-                model.getEmptyText());
+                model.getEmptyText(),
+                "Adaptation to " + modelClass.getSimpleName() + " had a 
non-null emptyText value.");
         assertEquals(
-                "Adaptation to " + modelClass.getSimpleName() + " had an 
unexpected value in the otherText value.",
                 "hello",
-                model.getOtherText());
+                model.getOtherText(),
+                "Adaptation to " + modelClass.getSimpleName() + " had an 
unexpected value in the otherText value.");
     }
 
     private <T extends Methods> void failing(Class<T> modelClass) {
@@ -294,15 +294,16 @@ public class AnnotationConflictsTest {
             factory.createModel(resource, modelClass);
         } catch (MissingElementsException e) {
             assertEquals(
-                    "Adaptation to " + modelClass.getSimpleName() + " failed, 
but with the wrong number of exceptions.",
                     1,
-                    e.getMissingElements().size());
+                    e.getMissingElements().size(),
+                    "Adaptation to " + modelClass.getSimpleName()
+                            + " failed, but with the wrong number of 
exceptions.");
             MissingElementException me = 
e.getMissingElements().iterator().next();
             assertTrue(
-                    "Adaptation to " + modelClass.getSimpleName() + " didn't 
fail due to emptyText.",
-                    me.getElement().toString().endsWith("emptyText"));
+                    me.getElement().toString().endsWith("emptyText"),
+                    "Adaptation to " + modelClass.getSimpleName() + " didn't 
fail due to emptyText.");
             thrown = true;
         }
-        assertTrue("Adaptation to " + modelClass.getSimpleName() + " was 
successful.", thrown);
+        assertTrue(thrown, "Adaptation to " + modelClass.getSimpleName() + " 
was successful.");
     }
 }
diff --git a/src/test/java/org/apache/sling/models/impl/CachingTest.java 
b/src/test/java/org/apache/sling/models/impl/CachingTest.java
index 259591c..b9217f3 100644
--- a/src/test/java/org/apache/sling/models/impl/CachingTest.java
+++ b/src/test/java/org/apache/sling/models/impl/CachingTest.java
@@ -36,22 +36,22 @@ import 
org.apache.sling.models.testmodels.interfaces.AdapterType1;
 import org.apache.sling.models.testmodels.interfaces.AdapterType2;
 import org.apache.sling.models.testmodels.interfaces.AdapterType3;
 import org.apache.sling.servlethelpers.MockSlingJakartaHttpServletRequest;
-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.Spy;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
-public class CachingTest {
+@ExtendWith(MockitoExtension.class)
+class CachingTest {
 
     @Spy
     private MockSlingJakartaHttpServletRequest request = new 
MockSlingJakartaHttpServletRequest(null);
@@ -63,8 +63,8 @@ public class CachingTest {
 
     private ModelAdapterFactory factory;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         factory = AdapterFactoryTest.createModelAdapterFactory();
         factory.injectors = Arrays.asList(new RequestAttributeInjector(), new 
ValueMapInjector());
         factory.adapterImplementations.addClassesAsAdapterAndImplementation(
@@ -83,15 +83,15 @@ public class CachingTest {
                 AdapterType2.class,
                 AdapterType3.class);
 
-        when(request.getAttribute("testValue")).thenReturn("test");
+        lenient().when(request.getAttribute("testValue")).thenReturn("test");
         requestWrapper = new SlingJakartaHttpServletRequestWrapper(request);
 
         ValueMap vm = new 
ValueMapDecorator(Collections.singletonMap("testValue", "test"));
-        when(resource.adaptTo(ValueMap.class)).thenReturn(vm);
+        lenient().when(resource.adaptTo(ValueMap.class)).thenReturn(vm);
     }
 
     @Test
-    public void testCachedClass() {
+    void testCachedClass() {
         CachedModel cached1 = factory.getAdapter(request, CachedModel.class);
         CachedModel cached2 = factory.getAdapter(request, CachedModel.class);
 
@@ -103,7 +103,7 @@ public class CachingTest {
     }
 
     @Test
-    public void testCachedClassWithResource() {
+    void testCachedClassWithResource() {
         CachedModel cached1 = factory.getAdapter(resource, CachedModel.class);
         CachedModel cached2 = factory.getAdapter(resource, CachedModel.class);
 
@@ -115,7 +115,7 @@ public class CachingTest {
     }
 
     @Test
-    public void testNoCachedClass() {
+    void testNoCachedClass() {
         UncachedModel uncached1 = factory.getAdapter(request, 
UncachedModel.class);
         UncachedModel uncached2 = factory.getAdapter(request, 
UncachedModel.class);
 
@@ -127,7 +127,7 @@ public class CachingTest {
     }
 
     @Test
-    public void testNoCachedClassWithResource() {
+    void testNoCachedClassWithResource() {
         UncachedModel uncached1 = factory.getAdapter(resource, 
UncachedModel.class);
         UncachedModel uncached2 = factory.getAdapter(resource, 
UncachedModel.class);
 
@@ -139,7 +139,7 @@ public class CachingTest {
     }
 
     @Test
-    public void testCachedInterface() {
+    void testCachedInterface() {
         org.apache.sling.models.testmodels.interfaces.CachedModel cached1 =
                 factory.getAdapter(request, 
org.apache.sling.models.testmodels.interfaces.CachedModel.class);
         org.apache.sling.models.testmodels.interfaces.CachedModel cached2 =
@@ -153,7 +153,7 @@ public class CachingTest {
     }
 
     @Test
-    public void testNoCachedInterface() {
+    void testNoCachedInterface() {
         org.apache.sling.models.testmodels.interfaces.UncachedModel uncached1 =
                 factory.getAdapter(request, 
org.apache.sling.models.testmodels.interfaces.UncachedModel.class);
         org.apache.sling.models.testmodels.interfaces.UncachedModel uncached2 =
@@ -167,7 +167,7 @@ public class CachingTest {
     }
 
     @Test
-    public void testCachedClassWithRequestWrapper() {
+    void testCachedClassWithRequestWrapper() {
         CachedModel cached1 = factory.getAdapter(request, CachedModel.class);
         CachedModel cached2 = factory.getAdapter(requestWrapper, 
CachedModel.class);
 
@@ -187,7 +187,7 @@ public class CachingTest {
     }
 
     @Test
-    public void testCachedInterfaceWithRequestWrapper() {
+    void testCachedInterfaceWithRequestWrapper() {
         org.apache.sling.models.testmodels.interfaces.CachedModel cached1 =
                 factory.getAdapter(request, 
org.apache.sling.models.testmodels.interfaces.CachedModel.class);
         org.apache.sling.models.testmodels.interfaces.CachedModel cached2 =
@@ -201,7 +201,7 @@ public class CachingTest {
     }
 
     @Test
-    public void testCachedModelWithAdapterTypes() {
+    void testCachedModelWithAdapterTypes() {
         // test 2 model implementations that share a common adapter type, with 
an implementation picker that selects
         // exactly one of the
         // implementations for the common adapter type. verify that the models 
are cached accordingly
diff --git a/src/test/java/org/apache/sling/models/impl/ConstructorTest.java 
b/src/test/java/org/apache/sling/models/impl/ConstructorTest.java
index 2645254..1d6362b 100644
--- a/src/test/java/org/apache/sling/models/impl/ConstructorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ConstructorTest.java
@@ -43,22 +43,24 @@ import 
org.apache.sling.models.testmodels.classes.constructorinjection.NoNameMod
 import 
org.apache.sling.models.testmodels.classes.constructorinjection.ViaRequestSuffixModel;
 import 
org.apache.sling.models.testmodels.classes.constructorinjection.WithThreeConstructorsOneInjectModel;
 import org.hamcrest.Matchers;
-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.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
-public class ConstructorTest {
+@ExtendWith(MockitoExtension.class)
+class ConstructorTest {
 
     private ModelAdapterFactory factory;
 
@@ -69,11 +71,11 @@ public class ConstructorTest {
 
     private static final String STRING_VALUE = "myValue";
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
 
-        when(request.getAttribute("attribute")).thenReturn(INT_VALUE);
-        when(request.getAttribute("attribute2")).thenReturn(STRING_VALUE);
+        
lenient().when(request.getAttribute("attribute")).thenReturn(INT_VALUE);
+        
lenient().when(request.getAttribute("attribute2")).thenReturn(STRING_VALUE);
 
         factory = AdapterFactoryTest.createModelAdapterFactory();
         factory.injectors = Arrays.asList(new RequestAttributeInjector(), new 
SelfInjector());
@@ -90,7 +92,7 @@ public class ConstructorTest {
     }
 
     @Test
-    public void testConstructorInjection() {
+    void testConstructorInjection() {
         WithOneConstructorModel model = factory.getAdapter(request, 
WithOneConstructorModel.class);
         assertNotNull(model);
         assertEquals(request, model.getRequest());
@@ -98,7 +100,7 @@ public class ConstructorTest {
     }
 
     @Test
-    public void testThreeConstructorsInjection() {
+    void testThreeConstructorsInjection() {
         WithThreeConstructorsModel model = factory.getAdapter(request, 
WithThreeConstructorsModel.class);
         assertNotNull(model);
         assertEquals(request, model.getRequest());
@@ -106,7 +108,7 @@ public class ConstructorTest {
     }
 
     @Test
-    public void testTwoConstructorsInjection() {
+    void testTwoConstructorsInjection() {
         WithTwoConstructorsModel model = factory.getAdapter(request, 
WithTwoConstructorsModel.class);
         assertNotNull(model);
         assertEquals(request, model.getRequest());
@@ -114,7 +116,7 @@ public class ConstructorTest {
     }
 
     @Test
-    public void testSuperclassConstructorsInjection() {
+    void testSuperclassConstructorsInjection() {
         SuperclassConstructorModel model = factory.getAdapter(request, 
SuperclassConstructorModel.class);
         assertNotNull(model);
         assertEquals(request, model.getRequest());
@@ -122,14 +124,14 @@ public class ConstructorTest {
     }
 
     @Test
-    public void testInvalidConstructorInjector() {
+    void testInvalidConstructorInjector() {
         InvalidConstructorModel model = factory.getAdapter(request, 
InvalidConstructorModel.class);
         assertNull(model);
     }
 
-    @Test(expected = ModelClassException.class)
-    public void testInvalidConstructorInjectorException() {
-        factory.createModel(request, InvalidConstructorModel.class);
+    @Test
+    void testInvalidConstructorInjectorException() {
+        assertThrows(ModelClassException.class, () -> 
factory.createModel(request, InvalidConstructorModel.class));
     }
 
     /**
@@ -137,7 +139,7 @@ public class ConstructorTest {
      * Test mixing of constructor injection and field injection as well.
      */
     @Test
-    public void testThreeConstructorsOneInjectInjection() {
+    void testThreeConstructorsOneInjectInjection() {
         WithThreeConstructorsOneInjectModel model =
                 factory.getAdapter(request, 
WithThreeConstructorsOneInjectModel.class);
         assertNotNull(model);
@@ -147,7 +149,7 @@ public class ConstructorTest {
     }
 
     @Test
-    public void testMultiThreadedConstructorInjection() throws 
InterruptedException, ExecutionException {
+    void testMultiThreadedConstructorInjection() throws InterruptedException, 
ExecutionException {
 
         class ModelCreator implements Callable<String> {
             @Override
@@ -191,14 +193,14 @@ public class ConstructorTest {
     }
 
     @Test
-    public void testNoNameModel() {
+    void testNoNameModel() {
         NoNameModel model = factory.getAdapter(request, NoNameModel.class);
         assertNull(model);
     }
 
     @Test
     @SuppressWarnings("null")
-    public void testViaInjectionModel() throws Exception {
+    void testViaInjectionModel() {
         Resource suffixResource = mock(Resource.class);
         when(suffixResource.getPath()).thenReturn("/the/suffix");
 
diff --git 
a/src/test/java/org/apache/sling/models/impl/ConstructorVisibilityTest.java 
b/src/test/java/org/apache/sling/models/impl/ConstructorVisibilityTest.java
index d8bf1a3..168adb4 100644
--- a/src/test/java/org/apache/sling/models/impl/ConstructorVisibilityTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ConstructorVisibilityTest.java
@@ -26,23 +26,23 @@ import org.apache.sling.models.impl.injectors.SelfInjector;
 import 
org.apache.sling.models.testmodels.classes.constructorvisibility.PackagePrivateConstructorModel;
 import 
org.apache.sling.models.testmodels.classes.constructorvisibility.PrivateConstructorModel;
 import 
org.apache.sling.models.testmodels.classes.constructorvisibility.ProtectedConstructorModel;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
-@RunWith(MockitoJUnitRunner.class)
-public class ConstructorVisibilityTest {
+@ExtendWith(MockitoExtension.class)
+class ConstructorVisibilityTest {
     private ModelAdapterFactory factory;
 
     @Mock
     private SlingJakartaHttpServletRequest request;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         factory = AdapterFactoryTest.createModelAdapterFactory();
         factory.injectors = Arrays.asList(new RequestAttributeInjector(), new 
SelfInjector());
         factory.adapterImplementations.addClassesAsAdapterAndImplementation(
@@ -50,19 +50,19 @@ public class ConstructorVisibilityTest {
     }
 
     @Test
-    public void testNonPublicConstructorProtectedModel() {
+    void testNonPublicConstructorProtectedModel() {
         ProtectedConstructorModel model = factory.createModel(request, 
ProtectedConstructorModel.class);
         assertNotNull(model);
     }
 
     @Test
-    public void testNonPublicConstructorPackagePrivateModel() {
+    void testNonPublicConstructorPackagePrivateModel() {
         PackagePrivateConstructorModel model = factory.createModel(request, 
PackagePrivateConstructorModel.class);
         assertNotNull(model);
     }
 
     @Test
-    public void testNonPublicConstructorPrivateModel() {
+    void testNonPublicConstructorPrivateModel() {
         PrivateConstructorModel model = factory.createModel(request, 
PrivateConstructorModel.class);
         assertNotNull(model);
     }
diff --git a/src/test/java/org/apache/sling/models/impl/CustomInjectorTest.java 
b/src/test/java/org/apache/sling/models/impl/CustomInjectorTest.java
index 8a7c0e8..ce6f06e 100644
--- a/src/test/java/org/apache/sling/models/impl/CustomInjectorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/CustomInjectorTest.java
@@ -28,29 +28,29 @@ import 
org.apache.sling.models.impl.injector.CustomAnnotation;
 import org.apache.sling.models.impl.injector.CustomAnnotationInjector;
 import org.apache.sling.models.impl.injector.SimpleInjector;
 import 
org.apache.sling.models.spi.injectorspecific.InjectAnnotationProcessorFactory;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 @SuppressWarnings("deprecation")
-@RunWith(MockitoJUnitRunner.class)
-public class CustomInjectorTest {
+@ExtendWith(MockitoExtension.class)
+class CustomInjectorTest {
 
     private ModelAdapterFactory factory;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         factory = AdapterFactoryTest.createModelAdapterFactory();
         factory.adapterImplementations.addClassesAsAdapterAndImplementation(
                 TestModel.class, CustomAnnotationModel.class);
     }
 
     @Test
-    public void testInjectorWhichDoesNotImplementAnnotationProcessor() {
+    void testInjectorWhichDoesNotImplementAnnotationProcessor() {
         factory.injectors = Arrays.asList(new SimpleInjector());
 
         TestModel model = factory.getAdapter(new Object(), TestModel.class);
@@ -59,7 +59,7 @@ public class CustomInjectorTest {
     }
 
     @Test
-    public void testInjectorWithCustomAnnotation() {
+    void testInjectorWithCustomAnnotation() {
         CustomAnnotationInjector injector = new CustomAnnotationInjector();
 
         factory.injectors = Arrays.asList(new SimpleInjector(), injector);
diff --git 
a/src/test/java/org/apache/sling/models/impl/implpicker/FirstImplementationPickerTest.java
 
b/src/test/java/org/apache/sling/models/impl/implpicker/FirstImplementationPickerTest.java
index 6cdf3db..0e74d68 100644
--- 
a/src/test/java/org/apache/sling/models/impl/implpicker/FirstImplementationPickerTest.java
+++ 
b/src/test/java/org/apache/sling/models/impl/implpicker/FirstImplementationPickerTest.java
@@ -20,31 +20,31 @@ package org.apache.sling.models.impl.implpicker;
 
 import org.apache.sling.models.impl.FirstImplementationPicker;
 import org.apache.sling.models.spi.ImplementationPicker;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
-public class FirstImplementationPickerTest {
+class FirstImplementationPickerTest {
 
     private static final Class<?> SAMPLE_ADAPTER = Comparable.class;
     private static final Object SAMPLE_ADAPTABLE = new Object();
 
     private ImplementationPicker underTest;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         underTest = new FirstImplementationPicker();
     }
 
     @Test
-    public void testPickOneImplementation() {
+    void testPickOneImplementation() {
         Class<?>[] implementations = new Class<?>[] {String.class};
         assertEquals(String.class, underTest.pick(SAMPLE_ADAPTER, 
implementations, SAMPLE_ADAPTABLE));
     }
 
     @Test
-    public void testPickMultipleImplementations() {
+    void testPickMultipleImplementations() {
         Class<?>[] implementations = new Class<?>[] {Integer.class, 
Long.class, String.class};
         assertEquals(Integer.class, underTest.pick(SAMPLE_ADAPTER, 
implementations, SAMPLE_ADAPTABLE));
     }


Reply via email to