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-commons-mime.git


The following commit(s) were added to refs/heads/master by this push:
     new 1da9c00  SLING-13199 Migrate to junit 5 (#11)
1da9c00 is described below

commit 1da9c00081102f3eeef5b2053ea23cec31a42878
Author: Eric Norman <[email protected]>
AuthorDate: Tue May 12 11:31:31 2026 -0700

    SLING-13199 Migrate to junit 5 (#11)
---
 pom.xml                                            |  9 +++-
 .../mime/internal/MimeTypeServiceImplTest.java     | 57 +++++++++++-----------
 .../internal/MimeTypeWebConsolePluginTest.java     | 12 ++---
 .../mime/internal/TikaMimeTypeProviderTest.java    | 12 +++--
 4 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/pom.xml b/pom.xml
index 24a2a3c..e423974 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,8 +83,13 @@
             <scope>provided</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/commons/mime/internal/MimeTypeServiceImplTest.java
 
b/src/test/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImplTest.java
index c303b18..62bac4d 100644
--- 
a/src/test/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImplTest.java
+++ 
b/src/test/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImplTest.java
@@ -21,13 +21,19 @@ package org.apache.sling.commons.mime.internal;
 import java.io.IOException;
 import java.io.InputStream;
 
-import junit.framework.TestCase;
 import org.apache.sling.commons.mime.MimeTypeProvider;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
 
 /**
  * The <code>MimeTypeServiceImplTest</code>
  */
-public class MimeTypeServiceImplTest extends TestCase {
+class MimeTypeServiceImplTest {
 
     private static final String IMAGE_GIF = "image/gif";
 
@@ -45,34 +51,31 @@ public class MimeTypeServiceImplTest extends TestCase {
 
     private MimeTypeServiceImpl service;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
+    @BeforeEach
+    void setUp() {
         this.service = new MimeTypeServiceImpl();
     }
 
-    @Override
-    protected void tearDown() throws Exception {
+    @AfterEach
+    void tearDown() {
         this.service = null;
-
-        super.tearDown();
     }
 
-    public void testNoMapping() throws Exception {
+    @Test
+    void testNoMapping() {
         assertNull(this.service.getMimeType("file." + TXT));
         assertNull(this.service.getMimeType(TXT));
         assertNull(this.service.getExtension(TEXT_PLAIN));
     }
 
-    public void testTxtMapping() throws Exception {
-
+    @Test
+    void testTxtMapping() {
         this.service.registerMimeType(TEXT_PLAIN, TXT, LOG, APT);
 
         final String[] exts = {TXT, LOG, APT};
         for (String ext : exts) {
-            assertEquals("Extension " + ext + " (1)", TEXT_PLAIN, 
this.service.getMimeType("file." + ext));
-            assertEquals("Extension " + ext + " (2)", TEXT_PLAIN, 
this.service.getMimeType(ext));
+            assertEquals(TEXT_PLAIN, this.service.getMimeType("file." + ext), 
"Extension " + ext + " (1)");
+            assertEquals(TEXT_PLAIN, this.service.getMimeType(ext), "Extension 
" + ext + " (2)");
         }
 
         assertEquals(TEXT_PLAIN, this.service.getMimeType(("file." + 
TXT).toUpperCase()));
@@ -85,14 +88,15 @@ public class MimeTypeServiceImplTest extends TestCase {
         assertEquals(TXT, this.service.getExtension(TEXT_PLAIN));
     }
 
-    public void testFileLoading() throws Exception {
+    @Test
+    void testFileLoading() throws Exception {
         loadMimeTypes(MimeTypeServiceImpl.CORE_MIME_TYPES);
         loadMimeTypes(MimeTypeServiceImpl.MIME_TYPES);
 
         final String[] exts = {TXT, LOG, APT};
         for (String ext : exts) {
-            assertEquals("Extension " + ext + " (1)", TEXT_PLAIN, 
this.service.getMimeType("file." + ext));
-            assertEquals("Extension " + ext + " (2)", TEXT_PLAIN, 
this.service.getMimeType(ext));
+            assertEquals(TEXT_PLAIN, this.service.getMimeType("file." + ext), 
"Extension " + ext + " (1)");
+            assertEquals(TEXT_PLAIN, this.service.getMimeType(ext), "Extension 
" + ext + " (2)");
         }
 
         assertEquals(TEXT_PLAIN, this.service.getMimeType(("file." + 
TXT).toUpperCase()));
@@ -106,7 +110,8 @@ public class MimeTypeServiceImplTest extends TestCase {
         assertEquals(TXT, this.service.getExtension(TEXT_PLAIN));
     }
 
-    public void testProvider() throws Exception {
+    @Test
+    void testProvider() {
         MimeTypeProvider mtp = this.createMimeTypeProvider(IMAGE_GIF, GIF);
 
         assertNull(this.service.getMimeType(GIF));
@@ -123,7 +128,8 @@ public class MimeTypeServiceImplTest extends TestCase {
         assertNull(this.service.getExtension(IMAGE_GIF));
     }
 
-    public void testProvider2() throws Exception {
+    @Test
+    void testProvider2() {
         MimeTypeProvider mtp = this.createMimeTypeProvider(IMAGE_GIF, GIF);
 
         this.service.registerMimeType(IMAGE_GIF, UNMAPPED_GIF);
@@ -173,16 +179,9 @@ public class MimeTypeServiceImplTest extends TestCase {
     }
 
     private void loadMimeTypes(String path) throws IOException {
-        InputStream ins = this.getClass().getResourceAsStream(path);
-        assertNotNull(ins);
-
-        try {
+        try (InputStream ins = this.getClass().getResourceAsStream(path)) {
+            assertNotNull(ins);
             this.service.registerMimeType(ins);
-        } finally {
-            try {
-                ins.close();
-            } catch (IOException ignore) {
-            }
         }
     }
 }
diff --git 
a/src/test/java/org/apache/sling/commons/mime/internal/MimeTypeWebConsolePluginTest.java
 
b/src/test/java/org/apache/sling/commons/mime/internal/MimeTypeWebConsolePluginTest.java
index ea40c6d..88d5ae8 100644
--- 
a/src/test/java/org/apache/sling/commons/mime/internal/MimeTypeWebConsolePluginTest.java
+++ 
b/src/test/java/org/apache/sling/commons/mime/internal/MimeTypeWebConsolePluginTest.java
@@ -25,23 +25,23 @@ import java.io.StringWriter;
 
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 /**
  *
  */
-public class MimeTypeWebConsolePluginTest {
+class MimeTypeWebConsolePluginTest {
 
     /**
      * Test method for {@link 
org.apache.sling.commons.mime.internal.MimeTypeWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest,
 jakarta.servlet.http.HttpServletResponse)}.
      */
     @Test
-    public void testDoGet() throws IOException {
+    void testDoGet() throws IOException {
         final MimeTypeServiceImpl service = new MimeTypeServiceImpl();
         try (InputStream ins = 
this.getClass().getResourceAsStream(MimeTypeServiceImpl.CORE_MIME_TYPES)) {
             assertNotNull(ins);
@@ -61,6 +61,6 @@ public class MimeTypeWebConsolePluginTest {
         String output = sw.toString();
 
         // Assert: basic expected content is present
-        assertTrue("Output should contain a table element", 
output.contains("<table id='mimetabtable'"));
+        assertTrue(output.contains("<table id='mimetabtable'"), "Output should 
contain a table element");
     }
 }
diff --git 
a/src/test/java/org/apache/sling/commons/mime/internal/TikaMimeTypeProviderTest.java
 
b/src/test/java/org/apache/sling/commons/mime/internal/TikaMimeTypeProviderTest.java
index 5e41921..15397a9 100644
--- 
a/src/test/java/org/apache/sling/commons/mime/internal/TikaMimeTypeProviderTest.java
+++ 
b/src/test/java/org/apache/sling/commons/mime/internal/TikaMimeTypeProviderTest.java
@@ -18,22 +18,26 @@
  */
 package org.apache.sling.commons.mime.internal;
 
-import junit.framework.TestCase;
 import org.apache.sling.commons.mime.MimeTypeProvider;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 /**
  * Unit tests for the {@link TikaMimeTypeProvider} class.
  */
-public class TikaMimeTypeProviderTest extends TestCase {
+class TikaMimeTypeProviderTest {
 
-    public void testGetMimeType() {
+    @Test
+    void testGetMimeType() {
         MimeTypeProvider provider = new TikaMimeTypeProvider();
         assertEquals("text/plain", provider.getMimeType("test.txt"));
         assertEquals("application/pdf", provider.getMimeType("test.pdf"));
         assertEquals("image/jpeg", provider.getMimeType("test.jpg"));
     }
 
-    public void testGetExtension() {
+    @Test
+    void testGetExtension() {
         MimeTypeProvider provider = new TikaMimeTypeProvider();
         assertEquals("txt", provider.getExtension("text/plain"));
         assertEquals("pdf", provider.getExtension("application/pdf"));

Reply via email to