You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/08/18 09:38:06 UTC

(maven-wagon) 01/01: Migrate HttpWagonHttpServerTestCase and its subclasses off PlexusTestCase

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

slachiewicz pushed a commit to branch junit5-http-server-testcase-3x
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git

commit 4e43d6a4ff0fbdabb63ad4ce1c4195ced633df47
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Tue Aug 18 11:37:56 2026 +0200

    Migrate HttpWagonHttpServerTestCase and its subclasses off PlexusTestCase
    
    Backport of the same change on master; this branch's copies were
    byte-identical to master's before its migration.
    
    The base lifecycle method is renamed startTestServer so a subclass
    @BeforeEach cannot override it: with the same signature JUnit 5 would run
    only the override and the server would never be created. getName() came
    from junit.framework.TestCase and now comes from an injected TestInfo.
---
 .../wagon/providers/http/HttpWagonErrorTest.java     | 12 +++++++++++-
 .../providers/http/HttpWagonHttpServerTestCase.java  | 20 +++++++++++++++-----
 .../wagon/providers/http/HttpWagonTimeoutTest.java   | 12 +++++++++++-
 3 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonErrorTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonErrorTest.java
index ca518018..ff07c8c4 100644
--- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonErrorTest.java
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonErrorTest.java
@@ -27,6 +27,11 @@
 import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.repository.Repository;
 import org.eclipse.jetty.servlet.ServletHolder;
+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;
 
 /**
  * User: jdumay Date: 24/01/2008 Time: 17:17:34
@@ -34,14 +39,15 @@
 public class HttpWagonErrorTest extends HttpWagonHttpServerTestCase {
     private int serverPort;
 
+    @BeforeEach
     protected void setUp() throws Exception {
-        super.setUp();
         ServletHolder servlets = new ServletHolder(new ErrorWithMessageServlet());
         context.addServlet(servlets, "/*");
         startServer();
         serverPort = getPort();
     }
 
+    @Test
     public void testGet401() throws Exception {
         Exception thrown = null;
 
@@ -73,6 +79,7 @@ public void testGet401() throws Exception {
                 thrown.getMessage());
     }
 
+    @Test
     public void testGet403() throws Exception {
         Exception thrown = null;
 
@@ -104,6 +111,7 @@ public void testGet403() throws Exception {
                 thrown.getMessage());
     }
 
+    @Test
     public void testGet404() throws Exception {
         Exception thrown = null;
 
@@ -135,6 +143,7 @@ public void testGet404() throws Exception {
                 thrown.getMessage());
     }
 
+    @Test
     public void testGet407() throws Exception {
         Exception thrown = null;
 
@@ -166,6 +175,7 @@ public void testGet407() throws Exception {
                 thrown.getMessage());
     }
 
+    @Test
     public void testGet500() throws Exception {
         Exception thrown = null;
 
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonHttpServerTestCase.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonHttpServerTestCase.java
index b04c6cd0..45b59d54 100644
--- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonHttpServerTestCase.java
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonHttpServerTestCase.java
@@ -18,25 +18,31 @@
  */
 package org.apache.maven.wagon.providers.http;
 
+import java.lang.reflect.Method;
+
 import org.apache.maven.wagon.Wagon;
-import org.codehaus.plexus.PlexusTestCase;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.ServerConnector;
 import org.eclipse.jetty.server.handler.ResourceHandler;
 import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestInfo;
 
 /**
  * User: jdumay Date: 24/01/2008 Time: 18:15:53
  */
-public abstract class HttpWagonHttpServerTestCase extends PlexusTestCase {
+public abstract class HttpWagonHttpServerTestCase {
     private Server server;
 
+    private String testName;
+
     protected ResourceHandler resourceHandler;
 
     protected ServletContextHandler context;
 
-    protected void setUp() throws Exception {
-        super.setUp();
+    @BeforeEach
+    protected void startTestServer(TestInfo testInfo) throws Exception {
+        testName = testInfo.getTestMethod().map(Method::getName).orElseGet(testInfo::getDisplayName);
         server = new Server(0);
 
         context = new ServletContextHandler(ServletContextHandler.SESSIONS);
@@ -45,8 +51,12 @@ protected void setUp() throws Exception {
         server.setHandler(context);
     }
 
+    protected final String getName() {
+        return testName;
+    }
+
     protected Wagon getWagon() throws Exception {
-        return (Wagon) lookup(HttpWagon.ROLE);
+        return new HttpWagon();
     }
 
     protected void startServer() throws Exception {
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTimeoutTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTimeoutTest.java
index a148421d..8fda72a1 100644
--- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTimeoutTest.java
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonTimeoutTest.java
@@ -28,18 +28,25 @@
 import org.apache.maven.wagon.shared.http.HttpConfiguration;
 import org.apache.maven.wagon.shared.http.HttpMethodConfiguration;
 import org.eclipse.jetty.servlet.ServletHolder;
+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.assertTrue;
 
 /**
  * User: jdumay Date: 24/01/2008 Time: 17:17:34
  */
 public class HttpWagonTimeoutTest extends HttpWagonHttpServerTestCase {
+    @BeforeEach
     protected void setUp() throws Exception {
-        super.setUp();
         ServletHolder servlets = new ServletHolder(new WaitForeverServlet());
         context.addServlet(servlets, "/*");
         startServer();
     }
 
+    @Test
     public void testGetTimeout() throws Exception {
         Exception thrown = null;
 
@@ -68,6 +75,7 @@ public void testGetTimeout() throws Exception {
         assertEquals(TransferFailedException.class, thrown.getClass());
     }
 
+    @Test
     public void testResourceExits() throws Exception {
         Exception thrown = null;
 
@@ -93,6 +101,7 @@ public void testResourceExits() throws Exception {
         assertEquals(TransferFailedException.class, thrown.getClass());
     }
 
+    @Test
     public void testPutTimeout() throws Exception {
         Exception thrown = null;
 
@@ -121,6 +130,7 @@ public void testPutTimeout() throws Exception {
         assertEquals(TransferFailedException.class, thrown.getClass());
     }
 
+    @Test
     public void testConnectionTimeout() throws Exception {
         Exception thrown = null;