This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-shared-jar.git


The following commit(s) were added to refs/heads/master by this push:
     new 4288530  Cleanup tests (#123)
4288530 is described below

commit 4288530d81572df9cf5de70184f0420c5a8cff00
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sun Dec 21 15:36:10 2025 +0100

    Cleanup tests (#123)
    
    Co-authored-by: Moderne <[email protected]>
---
 .../apache/maven/shared/jar/JarAnalyzerTest.java   |  18 +--
 .../shared/jar/classes/ImportVisitorTest.java      |   8 +-
 .../shared/jar/classes/JarClassesAnalyzerTest.java | 144 +++++++++------------
 .../JarIdentificationAnalyzerTest.java             |   6 +-
 .../exposers/EmbeddedMavenModelExposerTest.java    |   6 +-
 5 files changed, 82 insertions(+), 100 deletions(-)

diff --git a/src/test/java/org/apache/maven/shared/jar/JarAnalyzerTest.java 
b/src/test/java/org/apache/maven/shared/jar/JarAnalyzerTest.java
index f342573..d797dca 100644
--- a/src/test/java/org/apache/maven/shared/jar/JarAnalyzerTest.java
+++ b/src/test/java/org/apache/maven/shared/jar/JarAnalyzerTest.java
@@ -23,9 +23,9 @@ import java.io.IOException;
 import java.util.zip.ZipException;
 
 import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -53,45 +53,45 @@ class JarAnalyzerTest extends AbstractJarAnalyzerTestCase {
     }
 
     @Test
-    void testSealed() throws Exception {
+    void sealed() throws Exception {
         JarData jarData = getJarData("evil-sealed-regex-1.0.jar");
         assertTrue(jarData.isSealed());
     }
 
     @Test
-    void testNotSealed() throws Exception {
+    void notSealed() throws Exception {
         JarData jarData = getJarData("codec.jar");
         assertFalse(jarData.isSealed());
     }
 
     @Test
-    void testMultiRelease() throws Exception {
+    void multiRelease() throws Exception {
         JarData jarData = getJarData("multi-release-test-0.0.1.jar");
         assertTrue(jarData.isMultiRelease());
     }
 
     @Test
-    void testNotMultiRelease() throws Exception {
+    void notMultiRelease() throws Exception {
         JarData jarData = getJarData("codec.jar");
         assertFalse(jarData.isMultiRelease());
     }
 
     @Test
-    void testMissingFile() {
+    void missingFile() {
         assertThrows(IOException.class, () -> new JarAnalyzer(new 
File("foo-bar-this-should-not-exist.jar")));
     }
 
     @Test
-    void testInvalidJarFile() throws Exception {
+    void invalidJarFile() throws Exception {
         assertThrows(ZipException.class, () -> getJarAnalyzer("invalid.jar"));
     }
 
     @Test
-    void testCloseTwice() throws Exception {
+    void closeTwice() throws Exception {
         JarAnalyzer jarAnalyzer = getJarAnalyzer("codec.jar");
 
         // no exception should be thrown
-        Assertions.assertDoesNotThrow(() -> {
+        assertDoesNotThrow(() -> {
             jarAnalyzer.closeQuietly();
             jarAnalyzer.closeQuietly();
         });
diff --git 
a/src/test/java/org/apache/maven/shared/jar/classes/ImportVisitorTest.java 
b/src/test/java/org/apache/maven/shared/jar/classes/ImportVisitorTest.java
index 7bf3e05..16c7f5c 100644
--- a/src/test/java/org/apache/maven/shared/jar/classes/ImportVisitorTest.java
+++ b/src/test/java/org/apache/maven/shared/jar/classes/ImportVisitorTest.java
@@ -19,10 +19,8 @@
 package org.apache.maven.shared.jar.classes;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.List;
 
-import org.apache.bcel.classfile.ClassFormatException;
 import org.apache.bcel.classfile.ClassParser;
 import org.apache.bcel.classfile.DescendingVisitor;
 import org.apache.bcel.classfile.JavaClass;
@@ -40,7 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 class ImportVisitorTest extends AbstractJarAnalyzerTestCase {
 
     @Test
-    void testImportsJxr() throws ClassFormatException, IOException {
+    void importsJxr() throws Exception {
         File jxrjar = getSampleJar("jxr.jar");
         String classname = "org/apache/maven/jxr/DirectoryIndexer.class";
         ClassParser classParser = new ClassParser(jxrjar.getAbsolutePath(), 
classname);
@@ -60,7 +58,7 @@ class ImportVisitorTest extends AbstractJarAnalyzerTestCase {
     }
 
     @Test
-    void testImportsAnt() throws ClassFormatException, IOException {
+    void importsAnt() throws Exception {
         File jxrjar = getSampleJar("ant.jar");
         String classname = "org/apache/tools/ant/Target.class";
         ClassParser classParser = new ClassParser(jxrjar.getAbsolutePath(), 
classname);
@@ -108,7 +106,7 @@ class ImportVisitorTest extends AbstractJarAnalyzerTestCase 
{
                 "helloworld-24.jar",
                 "helloworld-25.jar"
             })
-    void testImportByJDKVersion(String jarName) throws IOException, 
ClassFormatException {
+    void importByJDKVersion(String jarName) throws Exception {
         File jarFile = getSampleJar(jarName);
 
         ClassParser classParser = new ClassParser(jarFile.getAbsolutePath(), 
"net/test/HelloWorld.class");
diff --git 
a/src/test/java/org/apache/maven/shared/jar/classes/JarClassesAnalyzerTest.java 
b/src/test/java/org/apache/maven/shared/jar/classes/JarClassesAnalyzerTest.java
index dc97b61..5c4cc18 100644
--- 
a/src/test/java/org/apache/maven/shared/jar/classes/JarClassesAnalyzerTest.java
+++ 
b/src/test/java/org/apache/maven/shared/jar/classes/JarClassesAnalyzerTest.java
@@ -33,12 +33,13 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.MethodSource;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 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.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 /**
  * JarAnalyzer Classes Test Case
@@ -50,7 +51,7 @@ class JarClassesAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
     private JarClassesAnalysis analyzer;
 
     @Test
-    void testAnalyzeJXR() throws Exception {
+    void analyzeJXR() throws Exception {
         JarClasses jclass = getJarClasses("jxr.jar");
 
         assertFalse(jclass.getImports().isEmpty(), "classes.imports.length > 
0");
@@ -67,7 +68,7 @@ class JarClassesAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
     }
 
     @Test
-    void testAnalyzeANT() throws Exception {
+    void analyzeANT() throws Exception {
         JarClasses jclass = getJarClasses("ant.jar");
 
         assertFalse(jclass.getImports().isEmpty(), "classes.imports.length > 
0");
@@ -84,7 +85,7 @@ class JarClassesAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
     }
 
     @Test
-    void testAnalyzeJarWithInvalidClassFile() throws Exception {
+    void analyzeJarWithInvalidClassFile() throws Exception {
         JarClasses jclass = getJarClasses("invalid-class-file.jar");
 
         // Doesn't fail, as exceptions are ignored.
@@ -96,14 +97,14 @@ class JarClassesAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
     }
 
     @Test
-    void testAnalyzeJarWithDebug() throws Exception {
+    void analyzeJarWithDebug() throws Exception {
         JarClasses jclass = getJarClasses("helloworld-1.4-debug.jar");
 
         assertTrue(jclass.isDebugPresent(), "has debug");
     }
 
     @Test
-    void testAnalyzeJarWithoutDebug() throws Exception {
+    void analyzeJarWithoutDebug() throws Exception {
         JarClasses jclass = getJarClasses("helloworld-1.4.jar");
 
         assertFalse(jclass.isDebugPresent(), "no debug present");
@@ -148,14 +149,14 @@ class JarClassesAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
     }
 
     @Test
-    void testAnalyzeJarWithModuleInfoClass() throws Exception {
+    void analyzeJarWithModuleInfoClass() throws Exception {
         JarData jarData = getJarData("tomcat-jni-9.0.75.jar");
         JarClasses jclass = jarData.getJarClasses();
         assertEquals("1.8", jclass.getJdkRevision());
     }
 
     @Test
-    void testAnalyzeJarWithOnlyModuleInfoClass() throws Exception {
+    void analyzeJarWithOnlyModuleInfoClass() throws Exception {
         JarData jarData = getJarData("module-info-only-test-0.0.1.jar");
         assertEquals(10, jarData.getNumEntries());
         // root level information
@@ -186,7 +187,7 @@ class JarClassesAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
     }
 
     @Test
-    void testAnalyzeMultiReleaseJarVersion() throws Exception {
+    void analyzeMultiReleaseJarVersion() throws Exception {
         JarData jarData = getJarData("multi-release-test-0.0.1.jar");
         assertEquals(37, jarData.getNumEntries());
         // root level information
@@ -229,12 +230,8 @@ class JarClassesAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
         assertEquals("[9, 11]", jarVersionedRuntimeMap.keySet().toString());
 
         // test best fit
-        try {
-            jarVersionedRuntimes.getBestFitJarVersionedRuntime(null);
-            fail("It should throw an NPE");
-        } catch (NullPointerException e) {
-            assertTrue(true);
-        }
+        assertThrows(NullPointerException.class, () -> 
jarVersionedRuntimes.getBestFitJarVersionedRuntime(null));
+
         assertNull(jarVersionedRuntimes.getBestFitJarVersionedRuntime(8)); // 
unreal value but good just for testing
         assertEquals(
                 "9",
@@ -261,26 +258,11 @@ class JarClassesAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
                         .getJarClasses()
                         .getJdkRevision());
 
-        try {
-            
jarVersionedRuntimes.getBestFitJarVersionedRuntimeBySystemProperty(null);
-            fail("It should throw an NPE");
-        } catch (NullPointerException e) {
-            assertTrue(true);
-        }
-
-        try {
-            getBestFitReleaseBySystemProperty(jarVersionedRuntimes, null);
-            fail("It should throw an NPE");
-        } catch (NullPointerException e) {
-            assertTrue(true);
-        }
-
-        try {
-            getBestFitReleaseBySystemProperty(jarVersionedRuntimes, "xxx");
-            fail("It should throw an ISE");
-        } catch (IllegalStateException e) {
-            assertTrue(true);
-        }
+        assertThrows(
+                NullPointerException.class,
+                () -> 
jarVersionedRuntimes.getBestFitJarVersionedRuntimeBySystemProperty(null));
+        assertThrows(NullPointerException.class, () -> 
getBestFitReleaseBySystemProperty(jarVersionedRuntimes, null));
+        assertThrows(IllegalStateException.class, () -> 
getBestFitReleaseBySystemProperty(jarVersionedRuntimes, "xxx"));
 
         assertNull(getBestFitReleaseBySystemProperty(jarVersionedRuntimes, 
"8"));
         assertEquals(
@@ -309,57 +291,59 @@ class JarClassesAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
      * Exposes issue MSHARED-1413
      */
     @Test
-    public void 
testAnalyzeMultiReleaseJarWithVersion11HasALowerJdkRevisionClass() {
-        try {
-            // Version 11 has one class compiled to target Java 1.8
-            JarData jarData = 
getJarData("multi-release-version-with-lower-jdk-revision-class-0.0.1.jar");
-            JarClasses jclass = jarData.getJarClasses();
-
-            assertNull(jclass.getJdkRevision());
-
-            JarVersionedRuntimes jarVersionedRuntimes = 
jarData.getVersionedRuntimes();
-            assertNotNull(jarVersionedRuntimes);
-            Map<Integer, JarVersionedRuntime> jarVersionedRuntimeMap = 
jarVersionedRuntimes.getVersionedRuntimeMap();
-            assertNotNull(jarVersionedRuntimeMap);
-            assertEquals(1, jarVersionedRuntimeMap.size()); // 11
-
-            JarVersionedRuntime jarVersionedRuntime11 = 
jarVersionedRuntimes.getJarVersionedRuntime(11);
-            JarClasses jarClasses11 = jarVersionedRuntime11.getJarClasses();
-            assertEquals("1.8", jarClasses11.getJdkRevision());
-        } catch (Exception e) {
-            fail("It should not raise an exception", e);
-        }
+    void analyzeMultiReleaseJarWithVersion11HasALowerJdkRevisionClass() {
+        assertDoesNotThrow(
+                () -> {
+                    // Version 11 has one class compiled to target Java 1.8
+                    JarData jarData = 
getJarData("multi-release-version-with-lower-jdk-revision-class-0.0.1.jar");
+                    JarClasses jclass = jarData.getJarClasses();
+
+                    assertNull(jclass.getJdkRevision());
+
+                    JarVersionedRuntimes jarVersionedRuntimes = 
jarData.getVersionedRuntimes();
+                    assertNotNull(jarVersionedRuntimes);
+                    Map<Integer, JarVersionedRuntime> jarVersionedRuntimeMap =
+                            jarVersionedRuntimes.getVersionedRuntimeMap();
+                    assertNotNull(jarVersionedRuntimeMap);
+                    assertEquals(1, jarVersionedRuntimeMap.size()); // 11
+
+                    JarVersionedRuntime jarVersionedRuntime11 = 
jarVersionedRuntimes.getJarVersionedRuntime(11);
+                    JarClasses jarClasses11 = 
jarVersionedRuntime11.getJarClasses();
+                    assertEquals("1.8", jarClasses11.getJdkRevision());
+                },
+                "It should not raise an exception");
     }
 
     /**
      * Ensures no exceptions are raised when versioned content does not 
contain classes (just resources)
      */
     @Test
-    public void testAnalyzeMultiReleaseJarResourcesOnly() {
-        try {
-            JarData jarData = 
getJarData("multi-release-resources-only-0.0.1.jar");
-            JarClasses jclass = jarData.getJarClasses();
-
-            assertEquals("1.8", jclass.getJdkRevision());
-
-            JarVersionedRuntimes jarVersionedRuntimes = 
jarData.getVersionedRuntimes();
-            assertNotNull(jarVersionedRuntimes);
-            Map<Integer, JarVersionedRuntime> jarVersionedRuntimeMap = 
jarVersionedRuntimes.getVersionedRuntimeMap();
-            assertNotNull(jarVersionedRuntimeMap);
-            assertEquals(2, jarVersionedRuntimeMap.size()); // 9 and 11
-
-            JarVersionedRuntime jarVersionedRuntime9 = 
jarVersionedRuntimes.getJarVersionedRuntime(9);
-            JarClasses jarClasses9 = jarVersionedRuntime9.getJarClasses();
-            // no classes found
-            assertNull(jarClasses9.getJdkRevision());
-
-            JarVersionedRuntime jarVersionedRuntime11 = 
jarVersionedRuntimes.getJarVersionedRuntime(11);
-            JarClasses jarClasses11 = jarVersionedRuntime11.getJarClasses();
-            // no classes found
-            assertNull(jarClasses11.getJdkRevision());
-        } catch (Exception e) {
-            fail("It should not raise an exception", e);
-        }
+    void analyzeMultiReleaseJarResourcesOnly() {
+        assertDoesNotThrow(
+                () -> {
+                    JarData jarData = 
getJarData("multi-release-resources-only-0.0.1.jar");
+                    JarClasses jclass = jarData.getJarClasses();
+
+                    assertEquals("1.8", jclass.getJdkRevision());
+
+                    JarVersionedRuntimes jarVersionedRuntimes = 
jarData.getVersionedRuntimes();
+                    assertNotNull(jarVersionedRuntimes);
+                    Map<Integer, JarVersionedRuntime> jarVersionedRuntimeMap =
+                            jarVersionedRuntimes.getVersionedRuntimeMap();
+                    assertNotNull(jarVersionedRuntimeMap);
+                    assertEquals(2, jarVersionedRuntimeMap.size()); // 9 and 11
+
+                    JarVersionedRuntime jarVersionedRuntime9 = 
jarVersionedRuntimes.getJarVersionedRuntime(9);
+                    JarClasses jarClasses9 = 
jarVersionedRuntime9.getJarClasses();
+                    // no classes found
+                    assertNull(jarClasses9.getJdkRevision());
+
+                    JarVersionedRuntime jarVersionedRuntime11 = 
jarVersionedRuntimes.getJarVersionedRuntime(11);
+                    JarClasses jarClasses11 = 
jarVersionedRuntime11.getJarClasses();
+                    // no classes found
+                    assertNull(jarClasses11.getJdkRevision());
+                },
+                "It should not raise an exception");
     }
 
     private void assertEntriesContains(List<JarEntry> list, final String 
entryToFind) {
diff --git 
a/src/test/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalyzerTest.java
 
b/src/test/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalyzerTest.java
index 33f706c..e5160a6 100644
--- 
a/src/test/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalyzerTest.java
+++ 
b/src/test/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalyzerTest.java
@@ -49,7 +49,7 @@ class JarIdentificationAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
     }
 
     @Test
-    void testTaxonAnalyzerWithJXR() throws Exception {
+    void taxonAnalyzerWithJXR() throws Exception {
         JarIdentification taxon = getJarTaxon("jxr.jar");
 
         assertEquals("org.apache.maven", taxon.getGroupId(), 
"identification.groupId");
@@ -67,7 +67,7 @@ class JarIdentificationAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
      * @throws Exception failures
      */
     @Test
-    void testTaxonAnalyzerWithCODEC() throws Exception {
+    void taxonAnalyzerWithCODEC() throws Exception {
         JarIdentification taxon = getJarTaxon("codec.jar");
 
         assertEquals("org.apache.commons.codec", taxon.getGroupId(), 
"identification.groupId");
@@ -83,7 +83,7 @@ class JarIdentificationAnalyzerTest extends 
AbstractJarAnalyzerTestCase {
     }
 
     @Test
-    void testTaxonAnalyzerWithANT() throws Exception {
+    void taxonAnalyzerWithANT() throws Exception {
         JarIdentification taxon = getJarTaxon("ant.jar");
 
         assertEquals("org.apache.tools.ant", taxon.getGroupId(), 
"identification.groupId");
diff --git 
a/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
 
b/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
index aae04c8..38277a1 100644
--- 
a/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
+++ 
b/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
@@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 class EmbeddedMavenModelExposerTest extends AbstractJarAnalyzerTestCase {
 
     @Test
-    void testExposerWithParent() throws Exception {
+    void exposerWithParent() throws Exception {
         File file = getSampleJar("test1.jar");
 
         JarIdentification identification = new JarIdentification();
@@ -54,7 +54,7 @@ class EmbeddedMavenModelExposerTest extends 
AbstractJarAnalyzerTestCase {
     }
 
     @Test
-    void testExposerWithJXR() throws Exception {
+    void exposerWithJXR() throws Exception {
         File file = getSampleJar("jxr.jar");
 
         JarIdentification identification = new JarIdentification();
@@ -70,7 +70,7 @@ class EmbeddedMavenModelExposerTest extends 
AbstractJarAnalyzerTestCase {
     }
 
     @Test
-    void testExposerWithANT() throws Exception {
+    void exposerWithANT() throws Exception {
         File file = getSampleJar("ant.jar");
 
         JarIdentification identification = new JarIdentification();

Reply via email to