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 b6cd6bc  SLING-13072: [Sling Models] Migrate defaults and inheritance 
root tests to JUnit 5 (#76)
b6cd6bc is described below

commit b6cd6bcfebb6e60e77ade9f6899441b438e7e673
Author: Bhavik Kothari <[email protected]>
AuthorDate: Mon Jan 26 19:13:58 2026 +0530

    SLING-13072: [Sling Models] Migrate defaults and inheritance root tests to 
JUnit 5 (#76)
---
 .../models/impl/DefaultInterfaceMethodTest.java    | 18 ++---
 .../org/apache/sling/models/impl/DefaultTest.java  | 55 ++++++--------
 .../sling/models/impl/ExtraDefaultTests.java       | 32 +++++---
 .../sling/models/impl/ImplementsExtendsTest.java   | 86 +++++++++++-----------
 .../impl/InjectorSpecificAnnotationTest.java       | 61 +++++++--------
 .../models/impl/InterfaceInheritanceTest.java      | 22 +++---
 .../sling/models/impl/InvalidAdaptationsTest.java  | 35 ++++-----
 7 files changed, 157 insertions(+), 152 deletions(-)

diff --git 
a/src/test/java/org/apache/sling/models/impl/DefaultInterfaceMethodTest.java 
b/src/test/java/org/apache/sling/models/impl/DefaultInterfaceMethodTest.java
index 3bb6591..a4442cf 100644
--- a/src/test/java/org/apache/sling/models/impl/DefaultInterfaceMethodTest.java
+++ b/src/test/java/org/apache/sling/models/impl/DefaultInterfaceMethodTest.java
@@ -25,27 +25,27 @@ import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.wrappers.ValueMapDecorator;
 import org.apache.sling.models.impl.injectors.ValueMapInjector;
 import org.apache.sling.models.testmodels.interfaces.ModelWithDefaultMethods;
-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.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.mock;
 
-public class DefaultInterfaceMethodTest {
+class DefaultInterfaceMethodTest {
 
     private ModelAdapterFactory factory;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         factory = AdapterFactoryTest.createModelAdapterFactory();
         factory.injectors = Collections.singletonList(new ValueMapInjector());
         
factory.adapterImplementations.addClassesAsAdapterAndImplementation(ModelWithDefaultMethods.class);
     }
 
     @Test
-    public void testDefaultInterfaceMethodsCanBeInjected() {
+    void testDefaultInterfaceMethodsCanBeInjected() {
         ValueMap vm = new ValueMapDecorator(Collections.singletonMap("prop", 
"the prop"));
         Resource res = mock(Resource.class);
         lenient().when(res.adaptTo(ValueMap.class)).thenReturn(vm);
@@ -56,7 +56,7 @@ public class DefaultInterfaceMethodTest {
     }
 
     @Test
-    public void testDefaultInterfaceMethodsDefaultImplementationsAreIgnored() {
+    void testDefaultInterfaceMethodsDefaultImplementationsAreIgnored() {
         ValueMap vm = new ValueMapDecorator(Collections.<String, 
Object>emptyMap());
         Resource res = mock(Resource.class);
         lenient().when(res.adaptTo(ValueMap.class)).thenReturn(vm);
diff --git a/src/test/java/org/apache/sling/models/impl/DefaultTest.java 
b/src/test/java/org/apache/sling/models/impl/DefaultTest.java
index 49e19e4..0a70dd7 100644
--- a/src/test/java/org/apache/sling/models/impl/DefaultTest.java
+++ b/src/test/java/org/apache/sling/models/impl/DefaultTest.java
@@ -29,26 +29,25 @@ import 
org.apache.sling.models.testmodels.classes.DefaultPrimitivesModel;
 import org.apache.sling.models.testmodels.classes.DefaultStringModel;
 import org.apache.sling.models.testmodels.classes.DefaultWrappersModel;
 import org.apache.sling.models.testmodels.interfaces.PropertyModelWithDefaults;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+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.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
-public class DefaultTest {
+@ExtendWith(MockitoExtension.class)
+class DefaultTest {
 
     private ModelAdapterFactory factory;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         factory = AdapterFactoryTest.createModelAdapterFactory();
         factory.injectors = Arrays.asList(new ValueMapInjector());
         factory.implementationPickers = Collections.emptyList();
@@ -63,7 +62,7 @@ public class DefaultTest {
     }
 
     @Test
-    public void testDefaultStringValueField() {
+    void testDefaultStringValueField() {
         ValueMap vm = new ValueMapDecorator(Collections.<String, 
Object>emptyMap());
 
         Resource res = mock(Resource.class);
@@ -76,7 +75,7 @@ public class DefaultTest {
     }
 
     @Test
-    public void testDefaultStringValueOnInterfaceField() {
+    void testDefaultStringValueOnInterfaceField() {
         ValueMap vm = new ValueMapDecorator(Collections.<String, 
Object>singletonMap("first", "first value"));
 
         Resource res = mock(Resource.class);
@@ -89,7 +88,7 @@ public class DefaultTest {
     }
 
     @Test
-    public void testDefaultPrimitivesField() {
+    void testDefaultPrimitivesField() {
         ValueMap vm = new ValueMapDecorator(Collections.<String, 
Object>emptyMap());
 
         Resource res = mock(Resource.class);
@@ -99,16 +98,14 @@ public class DefaultTest {
         assertNotNull(model);
 
         assertEquals(true, model.getBooleanProperty());
-        // we need to wait for JUnit 4.12 for this assertArrayEquals to be 
working on primitive boolean arrays,
-        // https://github.com/junit-team/junit/issues/86!
-        assertTrue(Arrays.equals(new boolean[] {true, true}, 
model.getBooleanArrayProperty()));
+        assertArrayEquals(new boolean[] {true, true}, 
model.getBooleanArrayProperty());
 
         assertEquals(1L, model.getLongProperty());
         assertArrayEquals(new long[] {1L, 1L}, model.getLongArrayProperty());
     }
 
     @Test
-    public void testDefaultWrappersField() {
+    void testDefaultWrappersField() {
         ValueMap vm = new ValueMapDecorator(Collections.<String, 
Object>emptyMap());
 
         Resource res = mock(Resource.class);
@@ -118,16 +115,14 @@ public class DefaultTest {
         assertNotNull(model);
 
         assertEquals(Boolean.valueOf(true), model.getBooleanWrapperProperty());
-        // we need to wait for JUnit 4.12 for this assertArrayEquals to be 
working on primitive boolean arrays,
-        // https://github.com/junit-team/junit/issues/86!
-        assertTrue(Arrays.equals(new Boolean[] {Boolean.TRUE, Boolean.TRUE}, 
model.getBooleanWrapperArrayProperty()));
+        assertArrayEquals(new Boolean[] {Boolean.TRUE, Boolean.TRUE}, 
model.getBooleanWrapperArrayProperty());
 
         assertEquals(Long.valueOf(1L), model.getLongWrapperProperty());
         assertArrayEquals(new Long[] {Long.valueOf(1L), Long.valueOf(1L)}, 
model.getLongWrapperArrayProperty());
     }
 
     @Test
-    public void testDefaultStringValueConstructor() {
+    void testDefaultStringValueConstructor() {
         ValueMap vm = new ValueMapDecorator(Collections.<String, 
Object>emptyMap());
 
         Resource res = mock(Resource.class);
@@ -141,7 +136,7 @@ public class DefaultTest {
     }
 
     @Test
-    public void testDefaultPrimitivesConstructor() {
+    void testDefaultPrimitivesConstructor() {
         ValueMap vm = new ValueMapDecorator(Collections.<String, 
Object>emptyMap());
 
         Resource res = mock(Resource.class);
@@ -154,16 +149,14 @@ public class DefaultTest {
         assertNotNull(model);
 
         assertEquals(true, model.getBooleanProperty());
-        // we need to wait for JUnit 4.12 for this assertArrayEquals to be 
working on primitive boolean arrays,
-        // https://github.com/junit-team/junit/issues/86!
-        assertTrue(Arrays.equals(new boolean[] {true, true}, 
model.getBooleanArrayProperty()));
+        assertArrayEquals(new boolean[] {true, true}, 
model.getBooleanArrayProperty());
 
         assertEquals(1L, model.getLongProperty());
         assertArrayEquals(new long[] {1L, 1L}, model.getLongArrayProperty());
     }
 
     @Test
-    public void testDefaultWrappersConstructor() {
+    void testDefaultWrappersConstructor() {
         ValueMap vm = new ValueMapDecorator(Collections.<String, 
Object>emptyMap());
 
         Resource res = mock(Resource.class);
@@ -174,9 +167,7 @@ public class DefaultTest {
         assertNotNull(model);
 
         assertEquals(Boolean.valueOf(true), model.getBooleanWrapperProperty());
-        // we need to wait for JUnit 4.12 for this assertArrayEquals to be 
working on primitive boolean arrays,
-        // https://github.com/junit-team/junit/issues/86!
-        assertTrue(Arrays.equals(new Boolean[] {Boolean.TRUE, Boolean.TRUE}, 
model.getBooleanWrapperArrayProperty()));
+        assertArrayEquals(new Boolean[] {Boolean.TRUE, Boolean.TRUE}, 
model.getBooleanWrapperArrayProperty());
 
         assertEquals(Long.valueOf(1L), model.getLongWrapperProperty());
         assertArrayEquals(new Long[] {Long.valueOf(1L), Long.valueOf(1L)}, 
model.getLongWrapperArrayProperty());
diff --git a/src/test/java/org/apache/sling/models/impl/ExtraDefaultTests.java 
b/src/test/java/org/apache/sling/models/impl/ExtraDefaultTests.java
index a72ec4c..8c9b515 100644
--- a/src/test/java/org/apache/sling/models/impl/ExtraDefaultTests.java
+++ b/src/test/java/org/apache/sling/models/impl/ExtraDefaultTests.java
@@ -23,32 +23,32 @@ import javax.inject.Inject;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.models.annotations.Default;
 import org.apache.sling.models.annotations.Model;
-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;
 
-@RunWith(MockitoJUnitRunner.class)
-public class ExtraDefaultTests {
+@ExtendWith(MockitoExtension.class)
+class ExtraDefaultTests {
 
     @Mock
     private Resource resource;
 
     private ModelAdapterFactory factory;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         factory = AdapterFactoryTest.createModelAdapterFactory();
         factory.adapterImplementations.addClassesAsAdapterAndImplementation(
                 EmptyDefaultsModel.class, WrongTypeDefaultsModel.class);
     }
 
     @Test
-    public void testEmptyDefaults() {
+    void testEmptyDefaultsPrimitiveArrays() {
         EmptyDefaultsModel model = factory.getAdapter(resource, 
EmptyDefaultsModel.class);
         assertNotNull(model);
         assertNotNull(model.booleanArray);
@@ -63,6 +63,12 @@ public class ExtraDefaultTests {
         assertEquals(0, model.longArray.length);
         assertNotNull(model.shortArray);
         assertEquals(0, model.shortArray.length);
+    }
+
+    @Test
+    void testEmptyDefaultsWrapperArrays() {
+        EmptyDefaultsModel model = factory.getAdapter(resource, 
EmptyDefaultsModel.class);
+        assertNotNull(model);
         assertNotNull(model.booleanWrapperArray);
         assertEquals(0, model.booleanWrapperArray.length);
         assertNotNull(model.doubleWrapperArray);
@@ -77,6 +83,12 @@ public class ExtraDefaultTests {
         assertEquals(0, model.shortWrapperArray.length);
         assertNotNull(model.stringArray);
         assertEquals(0, model.stringArray.length);
+    }
+
+    @Test
+    void testEmptyDefaultsScalars() {
+        EmptyDefaultsModel model = factory.getAdapter(resource, 
EmptyDefaultsModel.class);
+        assertNotNull(model);
         assertEquals(false, model.singleBoolean);
         assertEquals(0d, model.singleDouble, 0.0001);
         assertEquals(0f, model.singleFloat, 0.0001);
@@ -93,7 +105,7 @@ public class ExtraDefaultTests {
     }
 
     @Test
-    public void testWrongDefaultValues() {
+    void testWrongDefaultValues() {
         WrongTypeDefaultsModel model = factory.getAdapter(resource, 
WrongTypeDefaultsModel.class);
         assertNotNull(model);
         assertNotNull(model.booleanArray);
diff --git 
a/src/test/java/org/apache/sling/models/impl/ImplementsExtendsTest.java 
b/src/test/java/org/apache/sling/models/impl/ImplementsExtendsTest.java
index 1b80283..fe70e0a 100644
--- a/src/test/java/org/apache/sling/models/impl/ImplementsExtendsTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ImplementsExtendsTest.java
@@ -43,14 +43,13 @@ import 
org.apache.sling.models.testmodels.classes.implextend.InvalidImplementsIn
 import 
org.apache.sling.models.testmodels.classes.implextend.InvalidSampleServiceInterface;
 import 
org.apache.sling.models.testmodels.classes.implextend.SampleServiceInterface;
 import 
org.apache.sling.models.testmodels.classes.implextend.SimplePropertyModel;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+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.invocation.InvocationOnMock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.mockito.stubbing.Answer;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -58,17 +57,18 @@ import org.osgi.framework.BundleEvent;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
-public class ImplementsExtendsTest {
+@ExtendWith(MockitoExtension.class)
+class ImplementsExtendsTest {
 
     @Mock
     private BundleContext bundleContext;
@@ -86,18 +86,19 @@ public class ImplementsExtendsTest {
     private ImplementationPicker firstImplementationPicker = new 
FirstImplementationPicker();
 
     @SuppressWarnings("unchecked")
-    @Before
-    public void setup() throws ClassNotFoundException, MalformedURLException {
-        when(bundleContext.registerService(anyString(), any(), 
any(Dictionary.class)))
-                .then(new Answer<ServiceRegistration>() {
+    @BeforeEach
+    void setup() throws ClassNotFoundException, MalformedURLException {
+        lenient()
+                .when(bundleContext.registerService(anyString(), any(), 
any(Dictionary.class)))
+                .then(new Answer<ServiceRegistration<?>>() {
                     @Override
                     public ServiceRegistration<?> answer(InvocationOnMock 
invocation) throws Throwable {
                         final Dictionary<String, Object> props =
                                 (Dictionary<String, Object>) 
invocation.getArguments()[2];
-                        ServiceRegistration reg = 
mock(ServiceRegistration.class);
-                        ServiceReference ref = mock(ServiceReference.class);
-                        when(reg.getReference()).thenReturn(ref);
-                        when(ref.getProperty(anyString())).thenAnswer(new 
Answer<Object>() {
+                        ServiceRegistration<?> reg = 
mock(ServiceRegistration.class);
+                        ServiceReference<?> ref = mock(ServiceReference.class);
+                        lenient().doReturn(ref).when(reg).getReference();
+                        
lenient().when(ref.getProperty(anyString())).thenAnswer(new Answer<Object>() {
                             @Override
                             public Object answer(InvocationOnMock invocation) 
throws Throwable {
                                 String key = (String) 
invocation.getArguments()[0];
@@ -115,7 +116,7 @@ public class ImplementsExtendsTest {
         // simulate bundle add for ModelPackageBundleListener
         Dictionary<String, String> headers = new Hashtable<String, String>();
         headers.put(ModelPackageBundleListener.PACKAGE_HEADER, 
"org.apache.sling.models.testmodels.classes.implextend");
-        when(bundle.getHeaders()).thenReturn(headers);
+        lenient().when(bundle.getHeaders()).thenReturn(headers);
 
         Vector<URL> classUrls = new Vector<URL>();
         classUrls.add(getClassUrl(ExtendsClassPropertyModel.class));
@@ -125,9 +126,11 @@ public class ImplementsExtendsTest {
         classUrls.add(getClassUrl(InvalidSampleServiceInterface.class));
         classUrls.add(getClassUrl(SampleServiceInterface.class));
         classUrls.add(getClassUrl(SimplePropertyModel.class));
-        when(bundle.findEntries(anyString(), anyString(), 
anyBoolean())).thenReturn(classUrls.elements());
+        lenient()
+                .when(bundle.findEntries(anyString(), anyString(), 
anyBoolean()))
+                .thenReturn(classUrls.elements());
 
-        when(bundle.loadClass(anyString())).then(new Answer<Class<?>>() {
+        lenient().when(bundle.loadClass(anyString())).then(new 
Answer<Class<?>>() {
             @Override
             public Class<?> answer(InvocationOnMock invocation) throws 
ClassNotFoundException {
                 String className = (String) invocation.getArguments()[0];
@@ -143,27 +146,24 @@ public class ImplementsExtendsTest {
         return new URL(path);
     }
 
-    @After
-    public void tearDown() {
+    @AfterEach
+    void tearDown() {
         // simulate bundle remove for ModelPackageBundleListener
         factory.listener.removedBundle(bundle, bundleEvent, 
registeredAdapterFactories);
 
         // make sure adaption is not longer possible: implementation class 
mapping is removed
         Resource res = getMockResourceWithProps();
-        try {
-            factory.getAdapter(res, SampleServiceInterface.class);
-            Assert.fail(
-                    "Getting the model for interface 'SampleServiceInterface' 
should fail after the accroding adapter factory has been unregistered");
-        } catch (ModelClassException e) {
-
-        }
+        assertThrows(
+                ModelClassException.class,
+                () -> factory.getAdapter(res, SampleServiceInterface.class),
+                "Getting the model for interface 'SampleServiceInterface' 
should fail after the accroding adapter factory has been unregistered");
     }
 
     /**
      * Try to adapt to interface, with an different implementation class that 
has the @Model annotation
      */
     @Test
-    public void testImplementsInterfaceModel() {
+    void testImplementsInterfaceModel() {
         Resource res = getMockResourceWithProps();
         SampleServiceInterface model = factory.getAdapter(res, 
SampleServiceInterface.class);
         assertNotNull(model);
@@ -177,7 +177,7 @@ public class ImplementsExtendsTest {
      * This causes the extend adaptation to fail.
      */
     @Test
-    public void testImplementsNoPickerWithAdapterEqualsImplementation() {
+    void testImplementsNoPickerWithAdapterEqualsImplementation() {
         factory.implementationPickers = Collections.emptyList();
 
         Resource res = getMockResourceWithProps();
@@ -192,12 +192,12 @@ public class ImplementsExtendsTest {
      * Try to adapt in a case where there is no picker available.
      * The case where the class is the adapter still works.
      */
-    @Test(expected = ModelClassException.class)
-    public void testImplementsNoPickerWithDifferentImplementations() {
+    @Test
+    void testImplementsNoPickerWithDifferentImplementations() {
         factory.implementationPickers = Collections.emptyList();
 
         Resource res = getMockResourceWithProps();
-        factory.getAdapter(res, SampleServiceInterface.class);
+        assertThrows(ModelClassException.class, () -> factory.getAdapter(res, 
SampleServiceInterface.class));
     }
 
     /**
@@ -217,17 +217,17 @@ public class ImplementsExtendsTest {
     /**
      * Test implementation class with a mapping that is not valid (an 
interface that is not implemented).
      */
-    @Test(expected = ModelClassException.class)
-    public void testInvalidImplementsInterfaceModel() {
+    @Test
+    void testInvalidImplementsInterfaceModel() {
         Resource res = getMockResourceWithProps();
-        factory.getAdapter(res, InvalidSampleServiceInterface.class);
+        assertThrows(ModelClassException.class, () -> factory.getAdapter(res, 
InvalidSampleServiceInterface.class));
     }
 
     /**
      * Test to adapt to a superclass of the implementation class with the 
appropriate mapping in the @Model annotation.
      */
     @Test
-    public void testExtendsClassModel() {
+    void testExtendsClassModel() {
         Resource res = getMockResourceWithProps();
 
         // this is not having a model annotation nor does implement an 
interface/extend a class with a model annotation
@@ -246,7 +246,7 @@ public class ImplementsExtendsTest {
      * Try to adapt to interface, with an different implementation class that 
has the @Model annotation
      */
     @Test
-    public void testImplementsInterfaceModelWithPickLastImplementationPicker() 
{
+    void testImplementsInterfaceModelWithPickLastImplementationPicker() {
         factory.implementationPickers =
                 Arrays.asList(new 
AdapterImplementationsTest.LastImplementationPicker(), 
firstImplementationPicker);
 
@@ -265,7 +265,7 @@ public class ImplementsExtendsTest {
         ValueMap vm = new ValueMapDecorator(map);
 
         Resource res = mock(Resource.class);
-        when(res.adaptTo(ValueMap.class)).thenReturn(vm);
+        lenient().when(res.adaptTo(ValueMap.class)).thenReturn(vm);
         return res;
     }
 }
diff --git 
a/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
 
b/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
index 69eefcd..2f43a91 100644
--- 
a/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
+++ 
b/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
@@ -38,12 +38,12 @@ import 
org.apache.sling.models.impl.via.BeanPropertyViaProvider;
 import 
org.apache.sling.models.spi.injectorspecific.InjectAnnotationProcessorFactory;
 import 
org.apache.sling.models.spi.injectorspecific.InjectAnnotationProcessorFactory2;
 import 
org.apache.sling.models.testmodels.classes.InjectorSpecificAnnotationModel;
-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.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
@@ -52,12 +52,13 @@ import org.slf4j.LoggerFactory;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
 @SuppressWarnings("deprecation")
-public class InjectorSpecificAnnotationTest {
+@ExtendWith(MockitoExtension.class)
+class InjectorSpecificAnnotationTest {
 
     @Mock
     private BundleContext bundleContext;
@@ -72,8 +73,8 @@ public class InjectorSpecificAnnotationTest {
 
     private OSGiServiceInjector osgiInjector;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         factory = AdapterFactoryTest.createModelAdapterFactory();
 
         osgiInjector = new OSGiServiceInjector();
@@ -106,7 +107,7 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
-    public void testSimpleValueModelField() {
+    void testSimpleValueModelField() {
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("first", "first-value");
         map.put("second", "second-value");
@@ -123,7 +124,7 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
-    public void testOrderForValueAnnotationField() {
+    void testOrderForValueAnnotationField() {
         // make sure that that the correct injection is used
         // make sure that log is adapted from value map
         // and not coming from request attribute
@@ -145,20 +146,20 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
-    @SuppressWarnings({"unchecked", "null"})
-    public void testOSGiServiceField() throws InvalidSyntaxException {
-        ServiceReference ref = mock(ServiceReference.class);
-        Logger log = mock(Logger.class);
+    @SuppressWarnings({"null"})
+    void testOSGiServiceField() throws InvalidSyntaxException {
+        ServiceReference<?> ref = mock(ServiceReference.class);
+        Logger logger = mock(Logger.class);
         when(bundleContext.getServiceReferences(Logger.class.getName(), 
null)).thenReturn(new ServiceReference[] {ref});
-        when(bundleContext.getService(ref)).thenReturn(log);
+        doReturn(logger).when(bundleContext).getService(ref);
 
         InjectorSpecificAnnotationModel model = factory.getAdapter(request, 
InjectorSpecificAnnotationModel.class);
         assertNotNull("Could not instanciate model", model);
-        assertEquals(log, model.getService());
+        assertEquals(logger, model.getService());
     }
 
     @Test
-    public void testScriptVariableField() throws InvalidSyntaxException {
+    void testScriptVariableField() {
         SlingBindings bindings = new SlingBindings();
         SlingScriptHelper helper = mock(SlingScriptHelper.class);
         bindings.setSling(helper);
@@ -170,7 +171,7 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
-    public void testRequestAttributeField() throws InvalidSyntaxException {
+    void testRequestAttributeField() {
         Object attribute = new Object();
         when(request.getAttribute("attribute")).thenReturn(attribute);
 
@@ -180,7 +181,7 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
-    public void testChildResourceField() {
+    void testChildResourceField() {
         Resource res = mock(Resource.class);
         Resource child = mock(Resource.class);
         when(res.getChild("child1")).thenReturn(child);
@@ -192,7 +193,7 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
-    public void testSimpleValueModelConstructor() {
+    void testSimpleValueModelConstructor() {
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("first", "first-value");
         map.put("second", "second-value");
@@ -213,7 +214,7 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
-    public void testOrderForValueAnnotationConstructor() {
+    void testOrderForValueAnnotationConstructor() {
         // make sure that that the correct injection is used
         // make sure that log is adapted from value map
         // and not coming from request attribute
@@ -239,12 +240,12 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
-    @SuppressWarnings({"unchecked", "null"})
-    public void testOSGiServiceConstructor() throws InvalidSyntaxException {
-        ServiceReference ref = mock(ServiceReference.class);
-        Logger log = mock(Logger.class);
+    @SuppressWarnings({"null"})
+    void testOSGiServiceConstructor() throws InvalidSyntaxException {
+        ServiceReference<?> ref = mock(ServiceReference.class);
+        Logger logger = mock(Logger.class);
         when(bundleContext.getServiceReferences(Logger.class.getName(), 
null)).thenReturn(new ServiceReference[] {ref});
-        when(bundleContext.getService(ref)).thenReturn(log);
+        doReturn(logger).when(bundleContext).getService(ref);
 
         
org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel
 model =
                 factory.getAdapter(
@@ -252,11 +253,11 @@ public class InjectorSpecificAnnotationTest {
                         
org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel
                                 .class);
         assertNotNull("Could not instanciate model", model);
-        assertEquals(log, model.getService());
+        assertEquals(logger, model.getService());
     }
 
     @Test
-    public void testScriptVariableConstructor() throws InvalidSyntaxException {
+    void testScriptVariableConstructor() {
         SlingBindings bindings = new SlingBindings();
         SlingScriptHelper helper = mock(SlingScriptHelper.class);
         bindings.setSling(helper);
@@ -272,7 +273,7 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
-    public void testRequestAttributeConstructor() throws 
InvalidSyntaxException {
+    void testRequestAttributeConstructor() {
         Object attribute = new Object();
         when(request.getAttribute("attribute")).thenReturn(attribute);
 
@@ -286,7 +287,7 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
-    public void testChildResourceConstructor() {
+    void testChildResourceConstructor() {
         Resource res = mock(Resource.class);
         Resource child = mock(Resource.class);
         when(res.getChild("child1")).thenReturn(child);
diff --git 
a/src/test/java/org/apache/sling/models/impl/InterfaceInheritanceTest.java 
b/src/test/java/org/apache/sling/models/impl/InterfaceInheritanceTest.java
index 03edea3..9af774a 100644
--- a/src/test/java/org/apache/sling/models/impl/InterfaceInheritanceTest.java
+++ b/src/test/java/org/apache/sling/models/impl/InterfaceInheritanceTest.java
@@ -29,23 +29,23 @@ import 
org.apache.sling.models.impl.injectors.ValueMapInjector;
 import 
org.apache.sling.models.spi.injectorspecific.InjectAnnotationProcessorFactory;
 import org.apache.sling.models.testmodels.interfaces.SubClassModel;
 import org.apache.sling.models.testmodels.interfaces.SuperClassModel;
-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;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 @SuppressWarnings("deprecation")
-@RunWith(MockitoJUnitRunner.class)
-public class InterfaceInheritanceTest {
+@ExtendWith(MockitoExtension.class)
+class InterfaceInheritanceTest {
     private ModelAdapterFactory factory;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
 
         factory = AdapterFactoryTest.createModelAdapterFactory();
         ValueMapInjector valueMapInjector = new ValueMapInjector();
@@ -57,7 +57,7 @@ public class InterfaceInheritanceTest {
     }
 
     @Test
-    public void testSimplePropertyModel() {
+    void testSimplePropertyModel() {
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("superClassString", "first-value");
         map.put("subClassString", "second-value");
diff --git 
a/src/test/java/org/apache/sling/models/impl/InvalidAdaptationsTest.java 
b/src/test/java/org/apache/sling/models/impl/InvalidAdaptationsTest.java
index a8d3f3c..f6be95c 100644
--- a/src/test/java/org/apache/sling/models/impl/InvalidAdaptationsTest.java
+++ b/src/test/java/org/apache/sling/models/impl/InvalidAdaptationsTest.java
@@ -31,28 +31,29 @@ import 
org.apache.sling.models.factory.InvalidAdaptableException;
 import org.apache.sling.models.factory.ModelClassException;
 import org.apache.sling.models.impl.injectors.ChildResourceInjector;
 import org.apache.sling.models.impl.injectors.ValueMapInjector;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.mock;
 
-@RunWith(MockitoJUnitRunner.class)
-public class InvalidAdaptationsTest {
+@ExtendWith(MockitoExtension.class)
+class InvalidAdaptationsTest {
     private ModelAdapterFactory factory;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         factory = AdapterFactoryTest.createModelAdapterFactory();
         factory.injectors = Arrays.asList(new ValueMapInjector(), new 
ChildResourceInjector());
         
factory.adapterImplementations.addClassesAsAdapterAndImplementation(NonModel.class,
 RequestModel.class);
     }
 
     @Test
-    public void testNonModelClass() {
+    void testNonModelClass() {
         Map<String, Object> emptyMap = Collections.<String, Object>emptyMap();
 
         Resource res = mock(Resource.class);
@@ -61,18 +62,18 @@ public class InvalidAdaptationsTest {
         assertNull(factory.getAdapter(res, NonModel.class));
     }
 
-    @Test(expected = ModelClassException.class)
-    public void testNonModelClassException() {
+    @Test
+    void testNonModelClassException() {
         Map<String, Object> emptyMap = Collections.<String, Object>emptyMap();
 
         Resource res = mock(Resource.class);
         lenient().when(res.adaptTo(ValueMap.class)).thenReturn(new 
ValueMapDecorator(emptyMap));
 
-        assertNull(factory.createModel(res, NonModel.class));
+        assertThrows(ModelClassException.class, () -> factory.createModel(res, 
NonModel.class));
     }
 
     @Test
-    public void testWrongAdaptableClass() {
+    void testWrongAdaptableClass() {
         Map<String, Object> emptyMap = Collections.<String, Object>emptyMap();
 
         Resource res = mock(Resource.class);
@@ -81,14 +82,14 @@ public class InvalidAdaptationsTest {
         assertNull(factory.getAdapter(res, RequestModel.class));
     }
 
-    @Test(expected = InvalidAdaptableException.class)
-    public void testWrongAdaptableClassException() {
+    @Test
+    void testWrongAdaptableClassException() {
         Map<String, Object> emptyMap = Collections.<String, Object>emptyMap();
 
         Resource res = mock(Resource.class);
         lenient().when(res.adaptTo(ValueMap.class)).thenReturn(new 
ValueMapDecorator(emptyMap));
 
-        assertNull(factory.createModel(res, RequestModel.class));
+        assertThrows(InvalidAdaptableException.class, () -> 
factory.createModel(res, RequestModel.class));
     }
 
     private class NonModel {}


Reply via email to