From 543f3bbb59c273d1fd8f3c9daa61b5a1d0be758c Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Wed, 3 May 2023 11:17:27 +0200 Subject: [PATCH] Migrate to JUnit 5 --- pom.xml | 17 ++++- .../plexus/classworlds/ClassWorldTest.java | 38 +++++------ .../plexus/classworlds/UrlUtilsTest.java | 8 ++- .../launcher/ConfigurationParserTest.java | 24 +++---- .../launcher/ConfiguratorTest.java | 64 +++++++++---------- .../classworlds/launcher/LauncherTest.java | 36 +++++------ .../classworlds/realm/ClassRealmImplTest.java | 53 ++++++++------- .../realm/DefaultClassRealmTest.java | 41 +++++++----- .../plexus/classworlds/realm/EntryTest.java | 36 +++++------ .../realm/FilteredClassRealmTest.java | 24 +++---- .../classworlds/strategy/StrategyTest.java | 36 +++++------ 11 files changed, 197 insertions(+), 180 deletions(-) diff --git a/pom.xml b/pom.xml index 1b1d39a6..ef77375c 100644 --- a/pom.xml +++ b/pom.xml @@ -55,11 +55,22 @@ 2022-11-12T18:16:59Z + + + + org.junit + junit-bom + 5.9.3 + pom + import + + + + - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter test diff --git a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java index ec1cbea2..b5e9bee7 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java @@ -15,11 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -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.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.net.URL; import java.net.URLClassLoader; @@ -28,35 +28,35 @@ import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class ClassWorldTest +class ClassWorldTest extends AbstractClassWorldsTestCase { private ClassWorld world; - @Before + @BeforeEach public void setUp() { this.world = new ClassWorld(); } - @After + @AfterEach public void tearDown() { this.world = null; } @Test - public void testEmpty() + void testEmpty() { assertTrue( this.world.getRealms().isEmpty() ); } @Test - public void testNewRealm() + void testNewRealm() throws Exception { ClassRealm realm = this.world.newRealm( "foo" ); @@ -65,7 +65,7 @@ public void testNewRealm() } @Test - public void testGetRealm() + void testGetRealm() throws Exception { ClassRealm realm = this.world.newRealm( "foo" ); @@ -74,7 +74,7 @@ public void testGetRealm() } @Test - public void testNewRealm_Duplicate() + void testNewRealm_Duplicate() { try { @@ -94,7 +94,7 @@ public void testNewRealm_Duplicate() } @Test - public void testGetRealm_NoSuch() + void testGetRealm_NoSuch() { try { @@ -112,7 +112,7 @@ public void testGetRealm_NoSuch() } @Test - public void testGetRealms() + void testGetRealms() throws Exception { assertTrue( this.world.getRealms().isEmpty() ); @@ -129,9 +129,9 @@ public void testGetRealms() assertTrue( this.world.getRealms().contains( bar ) ); } - + @Test - public void testPLX334() + void testPLX334() throws Exception { ClassLoader loader = new URLClassLoader( new URL[] { getJarUrl( "component1-1.0.jar" ) } ); diff --git a/src/test/java/org/codehaus/plexus/classworlds/UrlUtilsTest.java b/src/test/java/org/codehaus/plexus/classworlds/UrlUtilsTest.java index 98cae7ea..4ea63fbc 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/UrlUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/UrlUtilsTest.java @@ -16,12 +16,14 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class UrlUtilsTest - extends TestCase +import org.junit.jupiter.api.Test; + +class UrlUtilsTest { + @Test public void testNormalizeUrlPath() { assertEquals( "org/codehaus/Test.class", UrlUtils.normalizeUrlPath( "org/codehaus/Test.class" ) ); diff --git a/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfigurationParserTest.java b/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfigurationParserTest.java index 73d83494..06bb3579 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfigurationParserTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfigurationParserTest.java @@ -1,20 +1,20 @@ package org.codehaus.plexus.classworlds.launcher; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ConfigurationParserTest +class ConfigurationParserTest extends AbstractClassWorldsTestCase { ConfigurationParser configurator = new ConfigurationParser( null, System.getProperties() ); @Test - public void testFilter_Unterminated() + void testFilter_Unterminated() { try { @@ -29,7 +29,7 @@ public void testFilter_Unterminated() } @Test - public void testFilter_Solitary() + void testFilter_Solitary() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); @@ -40,7 +40,7 @@ public void testFilter_Solitary() } @Test - public void testFilter_AtStart() + void testFilter_AtStart() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); @@ -51,7 +51,7 @@ public void testFilter_AtStart() } @Test - public void testFilter_AtEnd() + void testFilter_AtEnd() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); @@ -62,7 +62,7 @@ public void testFilter_AtEnd() } @Test - public void testFilter_Multiple() + void testFilter_Multiple() throws Exception { System.setProperty( "classworlds.test.prop.one", "test prop value one" ); @@ -76,7 +76,7 @@ public void testFilter_Multiple() } @Test - public void testFilter_NonExistent() + void testFilter_NonExistent() { try { @@ -91,7 +91,7 @@ public void testFilter_NonExistent() } @Test - public void testFilter_InMiddle() + void testFilter_InMiddle() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); diff --git a/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java b/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java index dc5c5c3d..5dfd57f9 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/launcher/ConfiguratorTest.java @@ -15,12 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -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.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.File; import java.io.FileInputStream; @@ -33,24 +33,24 @@ import org.codehaus.plexus.classworlds.TestUtil; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class ConfiguratorTest +class ConfiguratorTest extends AbstractClassWorldsTestCase { private Launcher launcher; private Configurator configurator; - @Before + @BeforeEach public void setUp() { this.launcher = new Launcher(); this.configurator = new Configurator( this.launcher ); } - @After + @AfterEach public void tearDown() { this.launcher = null; @@ -64,7 +64,7 @@ public void tearDown() } @Test - public void testConfigure_Nonexistent() + void testConfigure_Nonexistent() throws Exception { try @@ -79,7 +79,7 @@ public void testConfigure_Nonexistent() } @Test - public void testConfigure_DuplicateMain() + void testConfigure_DuplicateMain() throws Exception { try @@ -95,7 +95,7 @@ public void testConfigure_DuplicateMain() } @Test - public void testConfigure_DuplicateRealm() + void testConfigure_DuplicateRealm() throws Exception { try @@ -111,7 +111,7 @@ public void testConfigure_DuplicateRealm() } @Test - public void testConfigure_EarlyImport() + void testConfigure_EarlyImport() throws Exception { try @@ -127,7 +127,7 @@ public void testConfigure_EarlyImport() } @Test - public void testConfigure_RealmSyntax() + void testConfigure_RealmSyntax() throws Exception { try @@ -143,7 +143,7 @@ public void testConfigure_RealmSyntax() } @Test - public void testConfigure_Valid() + void testConfigure_Valid() throws Exception { this.configurator.configure( getConfigPath( "valid.conf" ) ); @@ -185,7 +185,7 @@ public void testConfigure_Valid() } @Test - public void testConfigure_Optionally_NonExistent() + void testConfigure_Optionally_NonExistent() throws Exception { this.configurator.configure( getConfigPath( "optionally-nonexistent.conf" ) ); @@ -206,11 +206,11 @@ public void testConfigure_Optionally_NonExistent() URL[] urls = optRealm.getURLs(); - assertEquals( "no urls", 0, urls.length ); + assertEquals( 0, urls.length , "no urls"); } @Test - public void testConfigure_Optionally_Existent() + void testConfigure_Optionally_Existent() throws Exception { this.configurator.configure( getConfigPath( "optionally-existent.conf" ) ); @@ -231,13 +231,13 @@ public void testConfigure_Optionally_Existent() URL[] urls = optRealm.getURLs(); - assertEquals( "one url", 1, urls.length ); + assertEquals( 1, urls.length , "one url"); assertSame( null, optRealm.getImportClassLoader( "org.xml.sax.SAXException" ) ); } @Test - public void testConfigure_Unhandled() + void testConfigure_Unhandled() throws Exception { try @@ -253,7 +253,7 @@ public void testConfigure_Unhandled() } @Test - public void testSet_Using_Existent() + void testSet_Using_Existent() throws Exception { assertNull( System.getProperty( "set.using.existent" ) ); @@ -264,7 +264,7 @@ public void testSet_Using_Existent() } @Test - public void testSet_Using_NonExistent() + void testSet_Using_NonExistent() throws Exception { assertNull( System.getProperty( "set.using.nonexistent" ) ); @@ -275,7 +275,7 @@ public void testSet_Using_NonExistent() } @Test - public void testSet_Using_NonExistent_Default() + void testSet_Using_NonExistent_Default() throws Exception { assertNull( System.getProperty( "set.using.nonexistent.default" ) ); @@ -286,7 +286,7 @@ public void testSet_Using_NonExistent_Default() } @Test - public void testSet_Using_NonExistent_Override() + void testSet_Using_NonExistent_Override() throws Exception { assertNull( System.getProperty( "set.using.default" ) ); @@ -298,7 +298,7 @@ public void testSet_Using_NonExistent_Override() } @Test - public void testSet_Using_Existent_Override() + void testSet_Using_Existent_Override() throws Exception { assertNull( System.getProperty( "set.using.existent" ) ); @@ -310,7 +310,7 @@ public void testSet_Using_Existent_Override() } @Test - public void testSet_Using_Existent_Default() + void testSet_Using_Existent_Default() throws Exception { assertNull( System.getProperty( "set.using.default" ) ); @@ -321,7 +321,7 @@ public void testSet_Using_Existent_Default() } @Test - public void testSet_Using_Missing_Default() + void testSet_Using_Missing_Default() throws Exception { assertNull( System.getProperty( "set.using.missing" ) ); @@ -332,7 +332,7 @@ public void testSet_Using_Missing_Default() } @Test - public void testSet_Using_Missing_Override() + void testSet_Using_Missing_Override() throws Exception { assertNull( System.getProperty( "set.using.missing" ) ); @@ -344,7 +344,7 @@ public void testSet_Using_Missing_Override() } @Test - public void testSet_Using_Filtered_Default() + void testSet_Using_Filtered_Default() throws Exception { assertNull( System.getProperty( "set.using.filtered.default" ) ); diff --git a/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java b/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java index 5300400e..1e2110e9 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/launcher/LauncherTest.java @@ -15,25 +15,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -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.fail; import java.io.File; import java.io.FileInputStream; import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.TestUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class LauncherTest +class LauncherTest extends AbstractClassWorldsTestCase { private Launcher launcher; - @Before + @BeforeEach public void setUp() { System.setProperty( "java.protocol.handler.pkgs", "org.codehaus.classworlds.protocol" ); @@ -43,14 +43,14 @@ public void setUp() this.launcher.setSystemClassLoader( Thread.currentThread().getContextClassLoader() ); } - @After + @AfterEach public void tearDown() { this.launcher = null; } @Test - public void testConfigure_Valid() + void testConfigure_Valid() throws Exception { launcher.configure( getConfigPath( "valid-launch.conf" ) ); @@ -65,7 +65,7 @@ public void testConfigure_Valid() } @Test - public void testLaunch_ValidStandard() + void testLaunch_ValidStandard() throws Exception { launcher.configure( getConfigPath( "valid-launch.conf" ) ); @@ -74,18 +74,18 @@ public void testLaunch_ValidStandard() } @Test - public void testLaunch_ValidStandardExitCode() + void testLaunch_ValidStandardExitCode() throws Exception { launcher.configure( getConfigPath( "valid-launch-exitCode.conf" ) ); launcher.launch( new String[]{} ); - assertEquals( "check exit code", 15, launcher.getExitCode() ); + assertEquals( 15, launcher.getExitCode() , "check exit code"); } @Test - public void testLaunch_ValidEnhanced() + void testLaunch_ValidEnhanced() throws Exception { launcher.configure( getConfigPath( "valid-enh-launch.conf" ) ); @@ -94,18 +94,18 @@ public void testLaunch_ValidEnhanced() } @Test - public void testLaunch_ValidEnhancedExitCode() + void testLaunch_ValidEnhancedExitCode() throws Exception { launcher.configure( getConfigPath( "valid-enh-launch-exitCode.conf" ) ); launcher.launch( new String[]{} ); - assertEquals( "check exit code", 45, launcher.getExitCode() ); + assertEquals( 45, launcher.getExitCode() , "check exit code"); } @Test - public void testLaunch_NoSuchMethod() + void testLaunch_NoSuchMethod() throws Exception { launcher.configure( getConfigPath( "launch-nomethod.conf" ) ); @@ -122,7 +122,7 @@ public void testLaunch_NoSuchMethod() } @Test - public void testLaunch_ClassNotFound() + void testLaunch_ClassNotFound() throws Exception { launcher.configure( getConfigPath( "launch-noclass.conf" ) ); diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java index dfd14af2..963299ac 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmImplTest.java @@ -15,10 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; import java.net.URL; import java.util.ArrayList; @@ -28,29 +25,29 @@ import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.ClassWorld; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class ClassRealmImplTest +class ClassRealmImplTest extends AbstractClassWorldsTestCase { private ClassWorld world; - @Before + @BeforeEach public void setUp() { this.world = new ClassWorld(); } - @After + @AfterEach public void tearDown() { this.world = null; } @Test - public void testNewRealm() + void testNewRealm() throws Exception { ClassRealm realm = this.world.newRealm( "foo" ); @@ -63,7 +60,7 @@ public void testNewRealm() } @Test - public void testLocateSourceRealm_NoImports() + void testLocateSourceRealm_NoImports() { ClassRealm realm = new ClassRealm( this.world, "foo", null ); @@ -71,7 +68,7 @@ public void testLocateSourceRealm_NoImports() } @Test - public void testLocateSourceRealm_SimpleImport() + void testLocateSourceRealm_SimpleImport() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); @@ -94,7 +91,7 @@ public void testLocateSourceRealm_SimpleImport() } @Test - public void testLocateSourceRealm_MultipleImport() + void testLocateSourceRealm_MultipleImport() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); @@ -121,7 +118,7 @@ public void testLocateSourceRealm_MultipleImport() } @Test - public void testLocateSourceRealm_Hierachy() + void testLocateSourceRealm_Hierachy() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); @@ -156,7 +153,7 @@ public void testLocateSourceRealm_Hierachy() } @Test - public void testLocateSourceRealm_Hierachy_Reverse() + void testLocateSourceRealm_Hierachy_Reverse() throws Exception { ClassRealm fooBarBazRealm = this.world.newRealm( "fooBarBaz" ); @@ -191,7 +188,7 @@ public void testLocateSourceRealm_Hierachy_Reverse() } @Test - public void testLoadClass_SystemClass() + void testLoadClass_SystemClass() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); @@ -202,7 +199,7 @@ public void testLoadClass_SystemClass() } @Test - public void testLoadClass_NonSystemClass() + void testLoadClass_NonSystemClass() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); @@ -222,7 +219,7 @@ public void testLoadClass_NonSystemClass() } @Test - public void testLoadClass_ClassWorldsClass() + void testLoadClass_ClassWorldsClass() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); @@ -235,7 +232,7 @@ public void testLoadClass_ClassWorldsClass() } @Test - public void testLoadClass_Local() + void testLoadClass_Local() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); @@ -268,7 +265,7 @@ public void testLoadClass_Local() } @Test - public void testLoadClass_Imported() + void testLoadClass_Imported() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); @@ -317,7 +314,7 @@ public void testLoadClass_Imported() } @Test - public void testLoadClass_Package() + void testLoadClass_Package() throws Exception { ClassRealm realmA = this.world.newRealm( "realmA" ); @@ -329,12 +326,12 @@ public void testLoadClass_Package() Package p = clazz.getPackage(); assertNotNull( p ); - assertEquals( "p.getName()", "a", p.getName() ); + assertEquals( "a", p.getName() , "p.getName()"); } @Test - public void testLoadClass_Complex() + void testLoadClass_Complex() throws Exception { ClassRealm realmA = this.world.newRealm( "realmA" ); @@ -427,7 +424,7 @@ public void testLoadClass_Complex() } @Test - public void testLoadClass_ClassWorldsClassRepeatedly() + void testLoadClass_ClassWorldsClassRepeatedly() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); @@ -443,7 +440,7 @@ public void testLoadClass_ClassWorldsClassRepeatedly() } @Test - public void testLoadClassWithModuleName_Java9() + void testLoadClassWithModuleName_Java9() { final ExtendedClassRealm mainRealm = new ExtendedClassRealm( world ); mainRealm.addURL( getJarUrl( "a.jar" ) ); @@ -451,7 +448,7 @@ public void testLoadClassWithModuleName_Java9() } @Test - public void testGetResources_BaseBeforeSelf() + void testGetResources_BaseBeforeSelf() throws Exception { String resource = "common.properties"; @@ -481,7 +478,7 @@ public void testGetResources_BaseBeforeSelf() } @Test - public void testGetResources_SelfBeforeParent() + void testGetResources_SelfBeforeParent() throws Exception { String resource = "common.properties"; diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/DefaultClassRealmTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/DefaultClassRealmTest.java index 170b9fd2..8283367d 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/DefaultClassRealmTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/DefaultClassRealmTest.java @@ -16,7 +16,14 @@ * limitations under the License. */ -import static org.junit.Assert.*; +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.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.net.URL; import java.net.URLClassLoader; import java.util.Collections; @@ -25,9 +32,9 @@ import org.codehaus.classworlds.ClassRealmAdapter; import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.ClassWorld; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class DefaultClassRealmTest +class DefaultClassRealmTest extends AbstractClassWorldsTestCase { // ---------------------------------------------------------------------- @@ -35,7 +42,7 @@ public class DefaultClassRealmTest // ---------------------------------------------------------------------- @Test - public void testLoadClassFromRealm() + void testLoadClassFromRealm() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); @@ -46,7 +53,7 @@ public void testLoadClassFromRealm() } @Test - public void testLoadClassFromChildRealmWhereClassIsLocatedInParentRealm() + void testLoadClassFromChildRealmWhereClassIsLocatedInParentRealm() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); @@ -59,7 +66,7 @@ public void testLoadClassFromChildRealmWhereClassIsLocatedInParentRealm() } @Test - public void testLoadClassFromChildRealmWhereClassIsLocatedInGrantParentRealm() + void testLoadClassFromChildRealmWhereClassIsLocatedInGrantParentRealm() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); @@ -74,7 +81,7 @@ public void testLoadClassFromChildRealmWhereClassIsLocatedInGrantParentRealm() } @Test - public void testLoadClassFromChildRealmWhereClassIsLocatedInBothChildRealmAndParentRealm() + void testLoadClassFromChildRealmWhereClassIsLocatedInBothChildRealmAndParentRealm() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "parent", null ); @@ -93,7 +100,7 @@ public void testLoadClassFromChildRealmWhereClassIsLocatedInBothChildRealmAndPar } @Test - public void testLoadNonExistentClass() + void testLoadNonExistentClass() { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); @@ -112,7 +119,7 @@ public void testLoadNonExistentClass() } @Test - public void testImport() + void testImport() throws Exception { ClassWorld world = new ClassWorld(); @@ -129,7 +136,7 @@ public void testImport() } @Test - public void testParentImport() + void testParentImport() throws Exception { ClassWorld world = new ClassWorld(); @@ -154,7 +161,7 @@ public void testParentImport() } @Test - public void testLoadClassFromBaseClassLoaderBeforeSelf() + void testLoadClassFromBaseClassLoaderBeforeSelf() throws Exception { ClassWorld world = new ClassWorld(); @@ -176,7 +183,7 @@ public void testLoadClassFromBaseClassLoaderBeforeSelf() } @Test - public void testLoadClassFromRealmWithCircularClassReferences() + void testLoadClassFromRealmWithCircularClassReferences() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); @@ -195,7 +202,7 @@ public void testLoadClassFromRealmWithCircularClassReferences() // ---------------------------------------------------------------------- @Test - public void testResource() + void testResource() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); @@ -206,7 +213,7 @@ public void testResource() } @Test - public void testMalformedResource() + void testMalformedResource() throws Exception { URL jarUrl = getJarUrl( "component0-1.0.jar" ); @@ -241,7 +248,7 @@ public void testMalformedResource() } @Test - public void testFindResourceOnlyScansSelf() + void testFindResourceOnlyScansSelf() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); @@ -261,7 +268,7 @@ public void testFindResourceOnlyScansSelf() } @Test - public void testFindResourcesOnlyScansSelf() + void testFindResourcesOnlyScansSelf() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); @@ -282,7 +289,7 @@ public void testFindResourcesOnlyScansSelf() /** Should never deadlock. Ever */ @Test - public void testParallelDeadlockClassRealm() + void testParallelDeadlockClassRealm() throws InterruptedException { for (int i = 0; i < 100; i++){ diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java index 3ead8436..10c8e7ad 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java @@ -15,23 +15,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.ClassWorld; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Ben Walding */ -public class EntryTest +class EntryTest extends AbstractClassWorldsTestCase { @Test - public void testCompareTo() + void testCompareTo() throws Exception { ClassWorld cw = new ClassWorld(); @@ -40,14 +40,14 @@ public void testCompareTo() Entry entry1 = new Entry( r, "org.test" ); Entry entry2 = new Entry( r, "org.test.impl" ); - assertTrue( "org.test > org.test.impl", entry1.compareTo( entry2 ) > 0 ); + assertTrue( entry1.compareTo( entry2 ) > 0 , "org.test > org.test.impl"); } /** * Tests the equality is realm independant */ @Test - public void testEquals() throws DuplicateRealmException + void testEquals() throws DuplicateRealmException { ClassWorld cw = new ClassWorld(); ClassRealm r1 = cw.newRealm( "test1" ); @@ -56,12 +56,12 @@ public void testEquals() throws DuplicateRealmException Entry entry1 = new Entry( r1, "org.test" ); Entry entry2 = new Entry( r2, "org.test" ); - assertEquals( "entry1 == entry2", entry1, entry2 ); - assertEquals( "entry1.hashCode() == entry2.hashCode()", entry1.hashCode(), entry2.hashCode() ); + assertEquals( entry1, entry2 , "entry1 == entry2"); + assertEquals( entry1.hashCode(), entry2.hashCode() , "entry1.hashCode() == entry2.hashCode()"); } @Test - public void testMatchesClassByPackageImport() + void testMatchesClassByPackageImport() throws Exception { ClassWorld cw = new ClassWorld(); @@ -77,7 +77,7 @@ public void testMatchesClassByPackageImport() } @Test - public void testMatchesClassByClassImport() + void testMatchesClassByClassImport() throws Exception { ClassWorld cw = new ClassWorld(); @@ -92,7 +92,7 @@ public void testMatchesClassByClassImport() } @Test - public void testMatchesResourceByPackageImport() + void testMatchesResourceByPackageImport() throws Exception { ClassWorld cw = new ClassWorld(); @@ -108,7 +108,7 @@ public void testMatchesResourceByPackageImport() } @Test - public void testMatchesResourceByClassImport() + void testMatchesResourceByClassImport() throws Exception { ClassWorld cw = new ClassWorld(); @@ -123,7 +123,7 @@ public void testMatchesResourceByClassImport() } @Test - public void testMatchesAllImport() + void testMatchesAllImport() throws Exception { ClassWorld cw = new ClassWorld(); @@ -138,7 +138,7 @@ public void testMatchesAllImport() } @Test - public void testMatchesResourceByResourceImport() + void testMatchesResourceByResourceImport() throws Exception { ClassWorld cw = new ClassWorld(); @@ -156,7 +156,7 @@ public void testMatchesResourceByResourceImport() } @Test - public void testMatchesClassByExactPackageImport() + void testMatchesClassByExactPackageImport() throws Exception { ClassWorld cw = new ClassWorld(); @@ -172,7 +172,7 @@ public void testMatchesClassByExactPackageImport() } @Test - public void testMatchesResourceByExactPackageImport() + void testMatchesResourceByExactPackageImport() throws Exception { ClassWorld cw = new ClassWorld(); diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/FilteredClassRealmTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/FilteredClassRealmTest.java index d217652b..e424a55c 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/realm/FilteredClassRealmTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/realm/FilteredClassRealmTest.java @@ -25,21 +25,21 @@ import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.ClassWorld; -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.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +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.assertTrue; -public class FilteredClassRealmTest extends AbstractClassWorldsTestCase +class FilteredClassRealmTest extends AbstractClassWorldsTestCase { private ClassWorld world; private ClassRealm realmA; - @Before + @BeforeEach public void setUp() throws DuplicateRealmException { this.world = new ClassWorld(); @@ -51,7 +51,7 @@ public void setUp() throws DuplicateRealmException } @Test - public void testLoadResources() + void testLoadResources() throws Exception { realmA.addURL( getJarUrl( "a.jar" ) ); @@ -63,7 +63,7 @@ public void testLoadResources() } @Test - public void testLoadClass() throws ClassNotFoundException + void testLoadClass() throws ClassNotFoundException { assertThrows( ClassNotFoundException.class, () -> realmA.loadClass( "a.Aa" ) ); realmA.addURL( getJarUrl( "a.jar" ) ); @@ -76,7 +76,7 @@ public void testLoadClass() throws ClassNotFoundException } @Test - public void testLoadClassWithModule() throws IOException + void testLoadClassWithModule() throws IOException { try ( ExtendedFilteredClassRealm realmA = new ExtendedFilteredClassRealm( world, s -> s.startsWith( "a/Aa" ) ) ) { realmA.addURL( getJarUrl( "a.jar" ) ); diff --git a/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java b/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java index b676570b..e0de2c9b 100644 --- a/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java +++ b/src/test/java/org/codehaus/plexus/classworlds/strategy/StrategyTest.java @@ -15,11 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.InputStream; import java.net.URL; @@ -28,20 +28,20 @@ import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; // jars within jars // hierarchy vs graph -public class StrategyTest +class StrategyTest extends AbstractClassWorldsTestCase { private ClassRealm realm; private Strategy strategy; - @Before + @BeforeEach public void setUp() throws Exception { @@ -51,14 +51,14 @@ public void setUp() } @Test - public void testLoadingOfApplicationClass() + void testLoadingOfApplicationClass() throws Exception { assertNotNull( strategy.loadClass( "org.codehaus.plexus.Component0" ) ); } @Test - public void testLoadingOfApplicationClassThenDoingItAgain() + void testLoadingOfApplicationClassThenDoingItAgain() throws Exception { Class c = strategy.loadClass( "org.codehaus.plexus.Component0" ); @@ -72,14 +72,14 @@ public void testLoadingOfApplicationClassThenDoingItAgain() @Test - public void testLoadingOfSystemClass() + void testLoadingOfSystemClass() throws Exception { assertNotNull( strategy.getRealm().loadClass( "java.lang.Object" ) ); } @Test - public void testLoadingOfNonExistentClass() + void testLoadingOfNonExistentClass() { try { @@ -94,7 +94,7 @@ public void testLoadingOfNonExistentClass() } @Test - public void testGetApplicationResource() + void testGetApplicationResource() throws Exception { URL resource = strategy.getResource( "META-INF/plexus/components.xml" ); @@ -107,10 +107,10 @@ public void testGetApplicationResource() } @Test - public void testGetSystemResource() + void testGetSystemResource() { - assumeTrue( "Due to strong encapsulation you cannot get the java/lang/Object.class as resource since Java 9", - getJavaVersion() < 9.0 ); + assumeTrue( getJavaVersion() < 9.0, + "Due to strong encapsulation you cannot get the java/lang/Object.class as resource since Java 9" ); URL resource = strategy.getRealm().getResource( "java/lang/Object.class" ); @@ -118,7 +118,7 @@ public void testGetSystemResource() } @Test - public void testFindResources() + void testFindResources() throws Exception { realm.addURL( getJarUrl( "component1-1.0.jar" ) );