From 62db310b093299850688ff9870665c1b5b57387d Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Mon, 18 Sep 2023 21:06:42 +1000 Subject: [PATCH 1/4] Add JDK 21 build --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 3e4c8d96d..a12923ab0 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -33,7 +33,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ '8', '11', '17' ] + java: [ '8', '11', '17', '21' ] steps: - name: Checkout code uses: actions/checkout@v4 From 9c12bb86b5a46a94439d2ac545f61e2dfbb4bbd1 Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Thu, 12 Oct 2023 01:56:44 +1100 Subject: [PATCH 2/4] Fix JDK 21 build --- .../com/opensymphony/xwork2/inject/ContainerImplTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/src/test/java/com/opensymphony/xwork2/inject/ContainerImplTest.java b/core/src/test/java/com/opensymphony/xwork2/inject/ContainerImplTest.java index c238c7582..eab385f84 100644 --- a/core/src/test/java/com/opensymphony/xwork2/inject/ContainerImplTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/inject/ContainerImplTest.java @@ -18,11 +18,15 @@ */ package com.opensymphony.xwork2.inject; +import org.apache.commons.lang3.JavaVersion; +import org.apache.commons.lang3.SystemUtils; import junit.framework.TestCase; import java.security.Permission; import java.util.concurrent.Callable; +import static org.junit.Assume.assumeTrue; + /** * ContainerImpl Tester. * @@ -93,6 +97,7 @@ public class ContainerImplTest extends TestCase { * Inject values into field under SecurityManager */ public void testFieldInjectorWithSecurityEnabled() throws Exception { + assumeTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20)); System.setSecurityManager(new TestSecurityManager()); FieldCheck fieldCheck = new FieldCheck(); @@ -109,6 +114,7 @@ public class ContainerImplTest extends TestCase { * Inject values into method under SecurityManager */ public void testMethodInjectorWithSecurityEnabled() throws Exception { + assumeTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20)); System.setSecurityManager(new TestSecurityManager()); MethodCheck methodCheck = new MethodCheck(); From 00db84468db15702787d6beb6e1b21e39d7eb04a Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Thu, 12 Oct 2023 02:15:58 +1100 Subject: [PATCH 3/4] Convert test class to JUnit4 --- .../xwork2/inject/ContainerImplTest.java | 73 ++++++------------- 1 file changed, 24 insertions(+), 49 deletions(-) diff --git a/core/src/test/java/com/opensymphony/xwork2/inject/ContainerImplTest.java b/core/src/test/java/com/opensymphony/xwork2/inject/ContainerImplTest.java index eab385f84..85ef9ace8 100644 --- a/core/src/test/java/com/opensymphony/xwork2/inject/ContainerImplTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/inject/ContainerImplTest.java @@ -20,11 +20,17 @@ package com.opensymphony.xwork2.inject; import org.apache.commons.lang3.JavaVersion; import org.apache.commons.lang3.SystemUtils; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; import java.security.Permission; import java.util.concurrent.Callable; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; /** @@ -34,15 +40,12 @@ import static org.junit.Assume.assumeTrue; * @version 1.0 * @since
11/26/2008
*/ -public class ContainerImplTest extends TestCase { +public class ContainerImplTest { private Container c; - @Override - protected void setUp() throws Exception { - System.setSecurityManager(null); - - super.setUp(); + @Before + public void setUp() throws Exception { ContainerBuilder cb = new ContainerBuilder(); cb.constant("methodCheck.name", "Lukasz"); cb.constant("fieldCheck.name", "Lukasz"); @@ -61,72 +64,43 @@ public class ContainerImplTest extends TestCase { Class.forName(ContainerImpl.FieldInjector.class.getName()); } - /** - * Inject values into field - */ - public void testFieldInjector() throws Exception { - + @Test + public void fieldInjector() throws Exception { FieldCheck fieldCheck = new FieldCheck(); - - try { - c.inject(fieldCheck); - assertTrue(true); - } catch (DependencyException expected) { - fail("No exception expected!"); - } - + c.inject(fieldCheck); assertEquals(fieldCheck.getName(), "Lukasz"); } - /** - * Inject values into method - */ - public void testMethodInjector() throws Exception { - - MethodCheck methodCheck = new MethodCheck(); - - try { - c.inject(methodCheck); - assertTrue(true); - } catch (DependencyException expected) { - fail("No exception expected!"); - } + @Test + public void methodInjector() throws Exception { + c.inject(new MethodCheck()); } /** * Inject values into field under SecurityManager */ + @Test public void testFieldInjectorWithSecurityEnabled() throws Exception { assumeTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20)); System.setSecurityManager(new TestSecurityManager()); + assertThrows(DependencyException.class, () -> c.inject(new FieldCheck())); - FieldCheck fieldCheck = new FieldCheck(); - - try { - c.inject(fieldCheck); - fail("Exception should be thrown!"); - } catch (Error | DependencyException expected) { - assertTrue(true); - } + System.setSecurityManager(null); } /** * Inject values into method under SecurityManager */ + @Test public void testMethodInjectorWithSecurityEnabled() throws Exception { assumeTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20)); System.setSecurityManager(new TestSecurityManager()); + assertThrows(DependencyException.class, () -> c.inject(new MethodCheck())); - MethodCheck methodCheck = new MethodCheck(); - - try { - c.inject(methodCheck); - fail("Exception should be thrown!"); - } catch (DependencyException | Error expected) { - assertTrue(true); - } + System.setSecurityManager(null); } + @Test public void testEarlyInitializable() throws Exception { assertTrue("should being initialized already", EarlyInitializableBean.initializedEarly); @@ -147,6 +121,7 @@ public class ContainerImplTest extends TestCase { earlyInitializableCheck.getPrototypeEarlyInitializable(), earlyInitializableCheck2.getPrototypeEarlyInitializable()); } + @Test public void testInitializable() throws Exception { assertFalse("should not being initialized already", InitializableBean.initialized); From b736eb281d7f5e1518430389aed224e78def8cb5 Mon Sep 17 00:00:00 2001 From: Kusal Kithul-Godage Date: Thu, 12 Oct 2023 03:25:54 +1100 Subject: [PATCH 4/4] Upgrade EasyMock --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index de582f550..d0a5aed20 100644 --- a/pom.xml +++ b/pom.xml @@ -777,7 +777,7 @@ org.easymock easymock - 4.3 + 5.2.0 test