This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-launcher.git
The following commit(s) were added to refs/heads/master by this push:
new 943d614 SLING-13048 - Make tests work in Java 21+ (#49)
943d614 is described below
commit 943d6147507a35bbe68df21c36f7f92e94f466c2
Author: Sergiu Dumitriu <[email protected]>
AuthorDate: Thu Jan 22 17:05:07 2026 -0500
SLING-13048 - Make tests work in Java 21+ (#49)
- use SystemUtils to check for the Java version
- use Assume to mark the test as disabled in incompatible Java versions
---
.../apache/sling/feature/launcher/impl/MainIT.java | 25 ++++++++++------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/src/test/java/org/apache/sling/feature/launcher/impl/MainIT.java
b/src/test/java/org/apache/sling/feature/launcher/impl/MainIT.java
index 7548ba4..9ce6822 100644
--- a/src/test/java/org/apache/sling/feature/launcher/impl/MainIT.java
+++ b/src/test/java/org/apache/sling/feature/launcher/impl/MainIT.java
@@ -26,15 +26,17 @@ import java.util.Map;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
+import org.apache.commons.lang3.JavaVersion;
+import org.apache.commons.lang3.SystemUtils;
import org.apache.sling.feature.ArtifactId;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.Assume;
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -79,18 +81,6 @@ public class MainIT {
}
}
- @BeforeClass
- public static void setUp() throws Exception {
-
- System.setSecurityManager(new NoSystemExitSecurityManager());
- }
-
- @AfterClass
- public static void tearDown() throws Exception {
-
- System.setSecurityManager(null);
- }
-
@Test
public void testSplitCommandlineArgs() {
@@ -345,11 +335,18 @@ public class MainIT {
@Test
public void testMain_main() {
+ // The security manager mechanism is no longer functional after Java
17.
+ // Without a security manager trapping the System.exit call,
+ // the whole VM would be shut down, which trips up Maven.
+
Assume.assumeTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_17));
+ System.setSecurityManager(new NoSystemExitSecurityManager());
try {
Main.main(new String[] {});
+ fail("Invoking without any arguments should have failed.");
} catch (SystemExitException e) {
assertEquals("Exit status", 1, e.status);
}
+ System.setSecurityManager(null);
}
}