This is an automated email from the ASF dual-hosted git repository.
enapps-enorman pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-extensions-webconsolesecurityprovider.git
The following commit(s) were added to refs/heads/master by this push:
new 618aa09 SLING-13193 Migrate to junit 5 (#8)
618aa09 is described below
commit 618aa0951d86b68c95561114c91bc9ac6bb3672d
Author: Eric Norman <[email protected]>
AuthorDate: Wed May 6 12:27:53 2026 -0700
SLING-13193 Migrate to junit 5 (#8)
---
pom.xml | 13 ++++--
.../internal/ActivatorTest.java | 28 +++++++------
.../internal/ServiceListenerTest.java | 47 +++++++++++-----------
.../SlingWebConsoleSecurityProvider2Test.java | 40 +++++++++---------
.../SlingWebConsoleSecurityProviderTest.java | 30 +++++++-------
5 files changed, 86 insertions(+), 72 deletions(-)
diff --git a/pom.xml b/pom.xml
index e051149..f222ea0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -122,7 +122,7 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.testing.osgi-mock.junit4</artifactId>
+ <artifactId>org.apache.sling.testing.osgi-mock.junit5</artifactId>
<version>3.5.8</version>
<scope>test</scope>
</dependency>
@@ -136,13 +136,18 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
+ <artifactId>org.apache.sling.testing.sling-mock.junit5</artifactId>
<version>4.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git
a/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ActivatorTest.java
b/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ActivatorTest.java
index 7019bc5..50d0eed 100644
---
a/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ActivatorTest.java
+++
b/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ActivatorTest.java
@@ -18,19 +18,21 @@
*/
package org.apache.sling.extensions.webconsolesecurityprovider.internal;
-import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.apache.sling.testing.mock.osgi.junit5.OsgiContext;
+import org.apache.sling.testing.mock.osgi.junit5.OsgiContextExtension;
import org.jetbrains.annotations.NotNull;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.Test.None;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.osgi.framework.BundleContext;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
/**
*
*/
-public class ActivatorTest {
+@ExtendWith(OsgiContextExtension.class)
+class ActivatorTest {
- @Rule
public OsgiContext context = new OsgiContext();
private Activator activator = new Activator();
@@ -38,26 +40,26 @@ public class ActivatorTest {
/**
* Test method for {@link
org.apache.sling.extensions.webconsolesecurityprovider.internal.Activator#start(org.osgi.framework.BundleContext)}.
*/
- @Test(expected = None.class)
- public void testStart() throws Exception {
+ @Test
+ void testStart() {
final @NotNull BundleContext bundleContext = context.bundleContext();
- activator.start(bundleContext);
+ assertDoesNotThrow(() -> activator.start(bundleContext));
}
/**
* Test method for {@link
org.apache.sling.extensions.webconsolesecurityprovider.internal.Activator#stop(org.osgi.framework.BundleContext)}.
*/
- @Test(expected = None.class)
- public void testStop() throws Exception {
+ @Test
+ void testStop() throws Exception {
final @NotNull BundleContext bundleContext = context.bundleContext();
// start
activator.start(bundleContext);
// stop
- activator.stop(bundleContext);
+ assertDoesNotThrow(() -> activator.stop(bundleContext));
// stop one more time for code coverage
- activator.stop(bundleContext);
+ assertDoesNotThrow(() -> activator.stop(bundleContext));
}
}
diff --git
a/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServiceListenerTest.java
b/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServiceListenerTest.java
index e2df3b2..26fdb5a 100644
---
a/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServiceListenerTest.java
+++
b/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/ServiceListenerTest.java
@@ -23,21 +23,22 @@ import javax.jcr.Repository;
import org.apache.felix.webconsole.spi.SecurityProvider;
import org.apache.sling.api.auth.Authenticator;
import org.apache.sling.auth.core.AuthenticationSupport;
-import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.apache.sling.testing.mock.osgi.junit5.OsgiContext;
+import org.apache.sling.testing.mock.osgi.junit5.OsgiContextExtension;
+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.MockitoAnnotations;
-import static org.junit.Assert.assertEquals;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class ServiceListenerTest {
+@ExtendWith(OsgiContextExtension.class)
+class ServiceListenerTest {
- @Rule
public OsgiContext context = new OsgiContext();
@Mock
@@ -51,20 +52,20 @@ public class ServiceListenerTest {
ServicesListener listener;
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
MockitoAnnotations.openMocks(this);
}
- @After
- public void shutdown() {
+ @AfterEach
+ void shutdown() {
if (listener != null) {
listener.deactivate();
}
}
@Test
- public void testDefaultAuth() {
+ void testDefaultAuth() {
listener = new ServicesListener(context.bundleContext());
assertNoSecurityProviderRegistered();
@@ -82,7 +83,7 @@ public class ServiceListenerTest {
}
@Test
- public void testWithSlingAuth() {
+ void testWithSlingAuth() {
try {
System.setProperty(ServicesListener.WEBCONSOLE_AUTH_TYPE,
ServicesListener.SLING_AUTH);
listener = new ServicesListener(context.bundleContext());
@@ -105,7 +106,7 @@ public class ServiceListenerTest {
}
@Test
- public void testWithForcedJcrAuth() {
+ void testWithForcedJcrAuth() {
try {
System.setProperty(ServicesListener.WEBCONSOLE_AUTH_TYPE,
ServicesListener.JCR_AUTH);
listener = new ServicesListener(context.bundleContext());
@@ -130,7 +131,7 @@ public class ServiceListenerTest {
}
@Test
- public void testGetAuthType() {
+ void testGetAuthType() {
try {
listener = new ServicesListener(context.bundleContext());
assertEquals(ServicesListener.AuthType.DEFAULT,
listener.getAuthType());
@@ -152,7 +153,7 @@ public class ServiceListenerTest {
}
@Test
- public void testGetTargetState() {
+ void testGetTargetState() {
try {
listener = new ServicesListener(context.bundleContext());
assertEquals(ServicesListener.State.NONE,
listener.getTargetState(false, false));
@@ -182,14 +183,14 @@ public class ServiceListenerTest {
private void assertRepositoryRegistered() {
assertTrue(
- "Expected to have the repository registered",
- getSecurityProvider() instanceof
SlingWebConsoleSecurityProvider);
+ getSecurityProvider() instanceof
SlingWebConsoleSecurityProvider,
+ "Expected to have the repository registered");
}
private void assertSlingAuthRegistered() {
assertTrue(
- "Expected to have SlingAuth registered",
- getSecurityProvider() instanceof
SlingWebConsoleSecurityProvider2);
+ getSecurityProvider() instanceof
SlingWebConsoleSecurityProvider2,
+ "Expected to have SlingAuth registered");
}
private void assertNoSecurityProviderRegistered() {
diff --git
a/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/SlingWebConsoleSecurityProvider2Test.java
b/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/SlingWebConsoleSecurityProvider2Test.java
index 175d721..ea8e846 100644
---
a/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/SlingWebConsoleSecurityProvider2Test.java
+++
b/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/SlingWebConsoleSecurityProvider2Test.java
@@ -36,26 +36,30 @@ import org.apache.sling.api.auth.Authenticator;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.auth.core.AuthenticationSupport;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
-import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.apache.sling.testing.mock.sling.junit5.SlingContext;
+import org.apache.sling.testing.mock.sling.junit5.SlingContextExtension;
import
org.apache.sling.testing.mock.sling.servlet.MockSlingJakartaHttpServletRequest;
import
org.apache.sling.testing.mock.sling.servlet.MockSlingJakartaHttpServletResponse;
import org.jetbrains.annotations.NotNull;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.osgi.service.cm.ConfigurationException;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.withSettings;
/**
*
*/
-public class SlingWebConsoleSecurityProvider2Test {
+@ExtendWith(SlingContextExtension.class)
+class SlingWebConsoleSecurityProvider2Test {
- @Rule
public SlingContext context = new
SlingContext(ResourceResolverType.JCR_MOCK);
private SlingWebConsoleSecurityProvider2 provider;
@@ -63,8 +67,8 @@ public class SlingWebConsoleSecurityProvider2Test {
private AuthenticationSupport support;
private Authenticator authenticator;
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
support = Mockito.mock(AuthenticationSupport.class);
authenticator = Mockito.mock(Authenticator.class);
provider = new SlingWebConsoleSecurityProvider2(support,
authenticator, "");
@@ -74,7 +78,7 @@ public class SlingWebConsoleSecurityProvider2Test {
* Test method for {@link
org.apache.sling.extensions.webconsolesecurityprovider.internal.SlingWebConsoleSecurityProvider2#updated(java.util.Dictionary)}.
*/
@Test
- public void testUpdated() throws ConfigurationException {
+ void testUpdated() throws ConfigurationException {
provider.updated(null);
assertEquals(ConfigConstants.PROP_DEFAULT_USERS, provider.users);
assertEquals(ConfigConstants.PROP_DEFAULT_GROUPS, provider.groups);
@@ -97,7 +101,7 @@ public class SlingWebConsoleSecurityProvider2Test {
* Test method for {@link
org.apache.sling.extensions.webconsolesecurityprovider.internal.SlingWebConsoleSecurityProvider2#authenticate(jakarta.servlet.http.HttpServletRequest,
jakarta.servlet.http.HttpServletResponse)}.
*/
@Test
- public void testAuthenticate() throws RepositoryException,
ConfigurationException {
+ void testAuthenticate() throws RepositoryException, ConfigurationException
{
final @NotNull MockSlingJakartaHttpServletRequest request =
context.jakartaRequest();
final @NotNull MockSlingJakartaHttpServletResponse response =
context.jakartaResponse();
@@ -155,7 +159,7 @@ public class SlingWebConsoleSecurityProvider2Test {
}
@Test
- public void testAuthenticateWithNoSession() {
+ void testAuthenticateWithNoSession() {
final @NotNull MockSlingJakartaHttpServletRequest request =
context.jakartaRequest();
final @NotNull MockSlingJakartaHttpServletResponse response =
context.jakartaResponse();
@@ -176,7 +180,7 @@ public class SlingWebConsoleSecurityProvider2Test {
}
@Test
- public void testAuthenticateWithCaughtException() throws
RepositoryException {
+ void testAuthenticateWithCaughtException() throws RepositoryException {
final @NotNull MockSlingJakartaHttpServletRequest request =
context.jakartaRequest();
final @NotNull MockSlingJakartaHttpServletResponse response =
context.jakartaResponse();
@@ -202,7 +206,7 @@ public class SlingWebConsoleSecurityProvider2Test {
}
@Test
- public void testAuthenticateWithoutJackrabbitSession() throws
RepositoryException {
+ void testAuthenticateWithoutJackrabbitSession() throws RepositoryException
{
final Session mockSession = Mockito.mock(Session.class);
Mockito.doReturn("test1").when(mockSession).getUserID();
assertNull(provider.authenticate(mockSession));
@@ -211,18 +215,18 @@ public class SlingWebConsoleSecurityProvider2Test {
/**
* Test method for {@link
org.apache.sling.extensions.webconsolesecurityprovider.internal.SlingWebConsoleSecurityProvider2#logout(jakarta.servlet.http.HttpServletRequest,
jakarta.servlet.http.HttpServletResponse)}.
*/
- @Test(expected = org.junit.Test.None.class)
- public void testLogout() {
+ @Test
+ void testLogout() {
final @NotNull MockSlingJakartaHttpServletRequest request =
context.jakartaRequest();
final @NotNull MockSlingJakartaHttpServletResponse response =
context.jakartaResponse();
- provider.logout(request, response);
+ assertDoesNotThrow(() -> provider.logout(request, response));
}
/**
* Test method for {@link
org.apache.sling.extensions.webconsolesecurityprovider.internal.SlingWebConsoleSecurityProvider2#authorize(java.lang.Object,
java.lang.String)}.
*/
@Test
- public void testAuthorize() {
+ void testAuthorize() {
assertTrue(provider.authorize("testuser1", "role1"));
}
}
diff --git
a/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/SlingWebConsoleSecurityProviderTest.java
b/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/SlingWebConsoleSecurityProviderTest.java
index e4db003..4f18434 100644
---
a/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/SlingWebConsoleSecurityProviderTest.java
+++
b/src/test/java/org/apache/sling/extensions/webconsolesecurityprovider/internal/SlingWebConsoleSecurityProviderTest.java
@@ -33,30 +33,32 @@ import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
-import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.apache.sling.testing.mock.sling.junit5.SlingContext;
+import org.apache.sling.testing.mock.sling.junit5.SlingContextExtension;
import org.jetbrains.annotations.NotNull;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.osgi.service.cm.ConfigurationException;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
/**
*
*/
-public class SlingWebConsoleSecurityProviderTest {
+@ExtendWith(SlingContextExtension.class)
+class SlingWebConsoleSecurityProviderTest {
- @Rule
public SlingContext context = new
SlingContext(ResourceResolverType.JCR_MOCK);
private Repository mockRepo;
private SlingWebConsoleSecurityProvider provider;
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
mockRepo =
Mockito.spy(context.resourceResolver().adaptTo(Session.class).getRepository());
provider = new
SlingWebConsoleSecurityProvider(context.bundleContext(), mockRepo);
}
@@ -65,7 +67,7 @@ public class SlingWebConsoleSecurityProviderTest {
* Test method for {@link
org.apache.sling.extensions.webconsolesecurityprovider.internal.SlingWebConsoleSecurityProvider#updated(java.util.Dictionary)}.
*/
@Test
- public void testUpdated() throws ConfigurationException {
+ void testUpdated() throws ConfigurationException {
provider.updated(null);
assertEquals(ConfigConstants.PROP_DEFAULT_USERS, provider.users);
assertEquals(ConfigConstants.PROP_DEFAULT_GROUPS, provider.groups);
@@ -88,7 +90,7 @@ public class SlingWebConsoleSecurityProviderTest {
* Test method for {@link
org.apache.sling.extensions.webconsolesecurityprovider.internal.SlingWebConsoleSecurityProvider#authenticate(java.lang.String,
java.lang.String)}.
*/
@Test
- public void testAuthenticate() throws RepositoryException,
ConfigurationException {
+ void testAuthenticate() throws RepositoryException, ConfigurationException
{
// user does not exist
assertNull(provider.authenticate("test1", "test1"));
@@ -124,7 +126,7 @@ public class SlingWebConsoleSecurityProviderTest {
}
@Test
- public void testAuthenticateWithoutJackrabbitSession() throws
RepositoryException {
+ void testAuthenticateWithoutJackrabbitSession() throws RepositoryException
{
// simulate the login return some non-jackrabbit session impl
final Session mockSession = Mockito.mock(Session.class);
Mockito.doReturn(mockSession).when(mockRepo).login(any(Credentials.class));
@@ -134,7 +136,7 @@ public class SlingWebConsoleSecurityProviderTest {
}
@Test
- public void testAuthenticateWithLoginException() throws
RepositoryException {
+ void testAuthenticateWithLoginException() throws RepositoryException {
// simulate the login throwing an exception
Mockito.doThrow(LoginException.class).when(mockRepo).login(any(Credentials.class));
@@ -143,7 +145,7 @@ public class SlingWebConsoleSecurityProviderTest {
}
@Test
- public void testAuthenticateWithOtherException() throws
RepositoryException {
+ void testAuthenticateWithOtherException() throws RepositoryException {
// simulate the login throwing an exception
Mockito.doThrow(RuntimeException.class).when(mockRepo).login(any(Credentials.class));