From 96aba150e9b4babb8fcb1064ee45e7b01c8b2466 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Mon, 12 Feb 2024 00:48:33 +0100 Subject: [PATCH] Cleanup junit 4 tests #2 --- pom.xml | 2 +- .../apache/maven/wagon/AbstractWagonTest.java | 41 +++--- .../maven/wagon/PermissionModeUtilsTest.java | 3 +- .../apache/maven/wagon/StreamWagonTest.java | 12 +- .../org/apache/maven/wagon/WagonMock.java | 13 +- .../wagon/events/SessionEventSupportTest.java | 2 +- .../maven/wagon/events/SessionEventTest.java | 2 +- .../events/TransferEventSupportTest.java | 2 +- .../maven/wagon/events/TransferEventTest.java | 2 +- .../wagon/repository/RepositoryTest.java | 2 +- .../maven/wagon/CommandExecutorTestCase.java | 6 +- .../maven/wagon/StreamingWagonTestCase.java | 17 +-- .../org/apache/maven/wagon/WagonTestCase.java | 12 +- .../maven/wagon/http/HttpWagonTestCase.java | 100 ++++++--------- .../maven/wagon/providers/file/FileWagon.java | 8 +- wagon-providers/wagon-ftp/pom.xml | 1 + .../maven/wagon/providers/ftp/FtpWagon.java | 23 +--- .../wagon/providers/ftp/FtpWagonTest.java | 2 +- .../http/LightweightHttpsWagonTest.java | 5 - .../wagon/shared/http/EncodingUtilTest.java | 25 ++-- .../http/AbstractHttpClientWagonTest.java | 120 ++++++++---------- .../http/ErrorWithMessageServlet.java | 3 +- .../providers/http/HttpClientWagonTest.java | 3 +- .../http/HttpWagonHttpServerTestCase.java | 2 +- .../http/HttpWagonPreemptiveTest.java | 10 -- .../http/HttpsWagonPreemptiveTest.java | 15 --- .../wagon/providers/http/HttpsWagonTest.java | 4 - .../providers/http/HugeFileDownloadTest.java | 14 +- .../scm/AbstractScmCvsWagonTest.java | 3 +- .../providers/scm/AbstractScmWagonTest.java | 2 +- .../providers/scm/ScmCvsExeWagonTest.java | 6 +- .../providers/scm/ScmGitExeWagonTest.java | 13 +- .../ssh/TestPasswordAuthenticator.java | 9 +- .../ssh/TestPublickeyAuthenticator.java | 7 +- .../knownhost/KnownHostsProviderTestCase.java | 2 +- .../ssh/jsch/EmbeddedScpWagonWithKeyTest.java | 5 +- .../ssh/jsch/ScpWagonWithProxyTest.java | 12 +- .../providers/webdav/HttpClientWagonTest.java | 3 +- .../providers/webdav/WebDavWagonTest.java | 28 ++-- .../maven/wagon/tck/http/GetWagonTests.java | 13 +- .../maven/wagon/tck/http/HttpWagonTests.java | 7 +- .../tck/http/WagonTestCaseConfigurator.java | 12 +- .../tck/http/fixture/ErrorCodeServlet.java | 4 +- 43 files changed, 223 insertions(+), 354 deletions(-) diff --git a/pom.xml b/pom.xml index ac32e6ff..1d01aa43 100644 --- a/pom.xml +++ b/pom.xml @@ -303,7 +303,7 @@ under the License. commons-io commons-io - 2.6 + 2.15.1 org.easymock diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java index 4379c372..7518e5ce 100644 --- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java +++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java @@ -54,20 +54,15 @@ protected void closeConnection() throws ConnectionException {} protected void openConnectionInternal() throws ConnectionException, AuthenticationException {} - public void get(String resourceName, File destination) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {} + public void get(String resourceName, File destination) {} - public boolean getIfNewer(String resourceName, File destination, long timestamp) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { + public boolean getIfNewer(String resourceName, File destination, long timestamp) { return false; } - public void put(File source, String destination) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {} + public void put(File source, String destination) {} } - private String basedir; - private WagonMock wagon = null; private File destination; @@ -81,9 +76,9 @@ public void put(File source, String destination) private TransferListener transferListener = null; @Before - public void setUp() throws Exception { + public void setUp() { - basedir = System.getProperty("basedir"); + String basedir = System.getProperty("basedir"); destination = new File(basedir, "target/folder/subfolder"); @@ -198,15 +193,13 @@ public void testProxyConfiguration() throws ConnectionException, AuthenticationE final ProxyInfo socksProxyInfo = new ProxyInfo(); socksProxyInfo.setType("http"); - ProxyInfoProvider proxyInfoProvider = new ProxyInfoProvider() { - public ProxyInfo getProxyInfo(String protocol) { - if ("http".equals(protocol) || "dav".equals(protocol)) { - return httpProxyInfo; - } else if ("scp".equals(protocol)) { - return socksProxyInfo; - } - return null; + ProxyInfoProvider proxyInfoProvider = protocol -> { + if ("http".equals(protocol) || "dav".equals(protocol)) { + return httpProxyInfo; + } else if ("scp".equals(protocol)) { + return socksProxyInfo; } + return null; }; Repository repository = new Repository(); @@ -299,9 +292,7 @@ public void testSessionCloseEvents() throws Exception { } @Test - public void testSessionCloseRefusedEventConnectionException() throws Exception { - Repository repository = new Repository(); - + public void testSessionCloseRefusedEventConnectionException() { sessionListener.sessionDisconnecting(anyObject(SessionEvent.class)); sessionListener.sessionError(anyObject(SessionEvent.class)); replay(sessionListener); @@ -438,7 +429,7 @@ public void testRepositoryPermissionsOverride() throws ConnectionException, Auth @Test public void testRepositoryUserName() throws ConnectionException, AuthenticationException { - Repository repository = new Repository("id", "http://bporter:password@www.example.com/path/to/resource"); + Repository repository = new Repository("id", "https://bporter:password@www.example.com/path/to/resource"); AuthenticationInfo authenticationInfo = new AuthenticationInfo(); authenticationInfo.setUserName("brett"); @@ -452,7 +443,7 @@ public void testRepositoryUserName() throws ConnectionException, AuthenticationE @Test public void testRepositoryUserNameNotGivenInCredentials() throws ConnectionException, AuthenticationException { - Repository repository = new Repository("id", "http://bporter:password@www.example.com/path/to/resource"); + Repository repository = new Repository("id", "https://bporter:password@www.example.com/path/to/resource"); AuthenticationInfo authenticationInfo = new AuthenticationInfo(); wagon.connect(repository, authenticationInfo); @@ -501,11 +492,11 @@ public void testPostProcessListeners() throws TransferFailedException, IOExcepti } static final class ProgressAnswer implements IAnswer { - private ByteArrayOutputStream baos = new ByteArrayOutputStream(); + private final ByteArrayOutputStream baos = new ByteArrayOutputStream(); private int size; - public Object answer() throws Throwable { + public Object answer() { byte[] buffer = (byte[]) getCurrentArguments()[1]; int length = (Integer) getCurrentArguments()[2]; baos.write(buffer, 0, length); diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/PermissionModeUtilsTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/PermissionModeUtilsTest.java index 0a049f1f..d1f84e25 100644 --- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/PermissionModeUtilsTest.java +++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/PermissionModeUtilsTest.java @@ -31,10 +31,9 @@ */ public class PermissionModeUtilsTest { /** - * @throws Exception on error */ @Test - public void testNumeric() throws Exception { + public void testNumeric() { final String[][] tests = { {"0", "777"}, {"0000", "777"}, diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/StreamWagonTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/StreamWagonTest.java index 0de50774..58958ac6 100644 --- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/StreamWagonTest.java +++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/StreamWagonTest.java @@ -38,17 +38,17 @@ public class StreamWagonTest { private static class TestWagon extends StreamWagon { - public void closeConnection() throws ConnectionException {} + public void closeConnection() {} public void fillInputData(InputData inputData) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {} public void fillOutputData(OutputData outputData) throws TransferFailedException {} - protected void openConnectionInternal() throws ConnectionException, AuthenticationException {} + protected void openConnectionInternal() {} } - private Repository repository = new Repository("id", "url"); + private final Repository repository = new Repository("id", "url"); @Test public void testNullInputStream() throws Exception { @@ -122,7 +122,7 @@ public void testTransferFailedExceptionOnInput() throws Exception { public void testTransferFailedExceptionOnOutput() throws Exception { StreamingWagon wagon = new TestWagon() { public void fillOutputData(OutputData inputData) throws TransferFailedException { - throw (TransferFailedException) new TransferFailedException(""); + throw new TransferFailedException(""); } }; @@ -318,8 +318,8 @@ public void testGetIfNewerToStreamWithSameTimeResource() throws Exception { } private boolean runTestGetIfNewerToStream(final long resourceTime, long comparisonTime) - throws IOException, ConnectionException, AuthenticationException, TransferFailedException, - ResourceDoesNotExistException, AuthorizationException { + throws ConnectionException, AuthenticationException, TransferFailedException, ResourceDoesNotExistException, + AuthorizationException { StreamingWagon wagon = new TestWagon() { public void fillInputData(InputData inputData) { inputData.setInputStream(new StringInputStream("")); diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/WagonMock.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/WagonMock.java index 626bf919..015047ee 100644 --- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/WagonMock.java +++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/WagonMock.java @@ -25,8 +25,6 @@ import java.util.Collections; import java.util.List; -import org.apache.maven.wagon.authorization.AuthorizationException; - /** * @author Jason van Zyl * @@ -41,7 +39,7 @@ public WagonMock(boolean errorInputStream) { this.errorInputStream = errorInputStream; } - public void fillInputData(InputData inputData) throws TransferFailedException { + public void fillInputData(InputData inputData) { InputStream is; @@ -61,7 +59,7 @@ public void fillInputData(InputData inputData) throws TransferFailedException { inputData.setInputStream(is); } - public void fillOutputData(OutputData outputData) throws TransferFailedException { + public void fillOutputData(OutputData outputData) { OutputStream os; @@ -90,12 +88,11 @@ public int getTimeout() { return timeout; } - public List getFileList(String destinationDirectory) - throws TransferFailedException, AuthorizationException { - return Collections.emptyList(); + public List getFileList(String destinationDirectory) { + return Collections.emptyList(); } - public boolean resourceExists(String resourceName) throws AuthorizationException { + public boolean resourceExists(String resourceName) { return false; } } diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventSupportTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventSupportTest.java index 90378427..e38a9f47 100644 --- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventSupportTest.java +++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventSupportTest.java @@ -40,7 +40,7 @@ public class SessionEventSupportTest { private Wagon wagon; @Before - public void setUp() throws Exception { + public void setUp() { eventSupport = new SessionEventSupport(); diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventTest.java index 4e8f2ba8..d2198499 100644 --- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventTest.java +++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventTest.java @@ -60,7 +60,7 @@ public void testSessionEventProperties() throws ConnectionException, Authenticat assertEquals(exception, event.getException()); event.setException(null); - assertEquals(null, event.getException()); + assertNull(event.getException()); event.setException(exception); assertEquals(exception, event.getException()); diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventSupportTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventSupportTest.java index d7cc39e3..e2930200 100644 --- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventSupportTest.java +++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventSupportTest.java @@ -37,7 +37,7 @@ public class TransferEventSupportTest { private Wagon wagon; @Before - public void setUp() throws Exception { + public void setUp() { eventSupport = new TransferEventSupport(); diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventTest.java index 518de3fd..0af23335 100644 --- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventTest.java +++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventTest.java @@ -82,7 +82,7 @@ public void testTransferEventProperties() throws ConnectionException, Authentica event.setResource(null); - assertEquals(null, event.getResource()); + assertNull(event.getResource()); res.setName("/foo/baa"); diff --git a/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java b/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java index 89a26c57..a82a7e4e 100644 --- a/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java +++ b/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java @@ -29,7 +29,7 @@ */ public class RepositoryTest { @Test - public void testRepositoryProperties() throws Exception { + public void testRepositoryProperties() { Repository repository = new Repository(); repository.setBasedir("directory"); diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/CommandExecutorTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/CommandExecutorTestCase.java index 5c9210d8..09b4908c 100644 --- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/CommandExecutorTestCase.java +++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/CommandExecutorTestCase.java @@ -30,7 +30,7 @@ */ public abstract class CommandExecutorTestCase extends PlexusTestCase { public void testErrorInCommandExecuted() throws Exception { - CommandExecutor exec = (CommandExecutor) lookup(CommandExecutor.ROLE); + CommandExecutor exec = lookup(CommandExecutor.ROLE); Repository repository = getTestRepository(); @@ -62,14 +62,14 @@ public void testIgnoreFailuresInCommandExecuted() throws Exception { try { Streams streams = exec.executeCommand("fail", true); // expect no exception, and stderr has something. - assertTrue(streams.getErr().length() > 0); + assertFalse(streams.getErr().isEmpty()); } finally { exec.disconnect(); } } public void testExecuteSuccessfulCommand() throws Exception { - CommandExecutor exec = (CommandExecutor) lookup(CommandExecutor.ROLE); + CommandExecutor exec = lookup(CommandExecutor.ROLE); Repository repository = getTestRepository(); diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/StreamingWagonTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/StreamingWagonTestCase.java index 30246302..f11c49c8 100644 --- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/StreamingWagonTestCase.java +++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/StreamingWagonTestCase.java @@ -19,10 +19,9 @@ package org.apache.maven.wagon; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Files; import java.text.SimpleDateFormat; import org.apache.maven.wagon.observers.ChecksumObserver; @@ -66,7 +65,7 @@ public void testFailedGetToStream() throws Exception { OutputStream stream = null; try { - stream = new FileOutputStream(destFile); + stream = Files.newOutputStream(destFile.toPath()); wagon.getToStream("fubar.txt", stream); fail("File was found when it shouldn't have been"); stream.close(); @@ -125,13 +124,9 @@ private void getIfNewerToStream(long timestamp, boolean expectedResult, int expe connectWagon(wagon); - OutputStream stream = new LazyFileOutputStream(destFile); - - try { + try (OutputStream stream = new LazyFileOutputStream(destFile)) { boolean result = wagon.getIfNewerToStream(this.resource, stream, timestamp); assertEquals(expectedResult, result); - } finally { - stream.close(); } disconnectWagon(wagon); @@ -153,7 +148,7 @@ public void testFailedGetIfNewerToStream() throws Exception { destFile.deleteOnExit(); OutputStream stream = null; try { - stream = new FileOutputStream(destFile); + stream = Files.newOutputStream(destFile.toPath()); wagon.getIfNewerToStream("fubar.txt", stream, 0); fail("File was found when it shouldn't have been"); stream.close(); @@ -218,7 +213,7 @@ private int putStream() throws Exception { InputStream stream = null; try { - stream = new FileInputStream(sourceFile); + stream = Files.newInputStream(sourceFile.toPath()); wagon.putFromStream(stream, resource, sourceFile.length(), sourceFile.lastModified()); stream.close(); stream = null; @@ -249,7 +244,7 @@ private void getStream(int expectedSize) throws Exception { OutputStream stream = null; try { - stream = new FileOutputStream(destFile); + stream = Files.newOutputStream(destFile.toPath()); wagon.getToStream(this.resource, stream); stream.close(); stream = null; diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java index b0953cc5..e92266b8 100644 --- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java +++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java @@ -50,12 +50,12 @@ * @author Jason van Zyl */ public abstract class WagonTestCase extends PlexusTestCase { - protected static Logger logger = LoggerFactory.getLogger(WagonTestCase.class); + protected final Logger logger = LoggerFactory.getLogger(getClass()); static final class ProgressAnswer implements IAnswer { private int size; - public Object answer() throws Throwable { + public Object answer() { int length = (Integer) getCurrentArguments()[2]; size += length; return null; @@ -163,7 +163,7 @@ protected void setupRepositories() throws Exception { } } - protected void customizeContext() throws Exception { + protected void customizeContext() { getContainer().addContextValue("test.repository", localRepositoryPath); } @@ -184,7 +184,7 @@ protected RepositoryPermissions getPermissions() { } protected Wagon getWagon() throws Exception { - Wagon wagon = (Wagon) lookup(Wagon.ROLE, getProtocol()); + Wagon wagon = lookup(Wagon.ROLE, getProtocol()); Debug debug = new Debug(); @@ -648,7 +648,7 @@ public void testWagonGetFileList() throws Exception { String dirName = "file-list"; - String filenames[] = new String[] { + String[] filenames = new String[] { "test-resource.txt", "test-resource.pom", "test-resource b.txt", "more-resources.dat", ".index.txt" }; @@ -674,7 +674,7 @@ public void testWagonGetFileList() throws Exception { // WAGON-250 list = wagon.getFileList(""); assertNotNull("file list should not be null.", list); - assertTrue("file list should contain items (actually contains '" + list + "').", !list.isEmpty()); + assertFalse("file list should contain items (actually contains '" + list + "').", list.isEmpty()); assertTrue(list.contains("file-list/")); assertFalse(list.contains("file-list")); assertFalse(list.contains(".")); diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java index 937d210e..ad0f3949 100644 --- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java +++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java @@ -31,13 +31,8 @@ import java.io.OutputStream; import java.lang.reflect.Method; import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; +import java.nio.file.Files; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.zip.DeflaterOutputStream; import java.util.zip.GZIPOutputStream; @@ -68,7 +63,6 @@ import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Response; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.AbstractHandler; @@ -129,7 +123,7 @@ protected final int getTestRepositoryPort() { return connector.getLocalPort(); } - protected ServletContextHandler createContext(Server server, File repositoryDirectory) throws IOException { + protected ServletContextHandler createContext(Server server, File repositoryDirectory) { ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS); root.setResourceBase(repositoryDirectory.getAbsolutePath()); ServletHolder servletHolder = new ServletHolder(new DefaultServlet()); @@ -338,8 +332,7 @@ public void testResourceExists429() throws Exception { AbstractHandler handler = new AbstractHandler() { public void handle( - String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { + String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) { if (called.get()) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); baseRequest.setHandled(true); @@ -524,11 +517,7 @@ public void testProxiedRequestWithAuthenticationWithProvider() throws Exception proxyInfo.setPassword("secret"); AuthorizingProxyHandler handler = new AuthorizingProxyHandler(); - ProxyInfoProvider proxyInfoProvider = new ProxyInfoProvider() { - public ProxyInfo getProxyInfo(String protocol) { - return proxyInfo; - } - }; + ProxyInfoProvider proxyInfoProvider = protocol -> proxyInfo; runTestProxiedRequestWithProvider(proxyInfoProvider, handler); assertTrue(handler.headers.containsKey("Proxy-Authorization")); @@ -803,7 +792,7 @@ protected void checkHandlerResult( } if (!success) { - fail("expected " + expectedResponseCodes + ", got " + handlerRequestResponses); + fail("expected " + Arrays.toString(expectedResponseCodes) + ", got " + handlerRequestResponses); } } @@ -989,15 +978,15 @@ public void testRedirectPutFailureNonRepeatableStream() throws Exception { */ @SuppressWarnings("checkstyle:visibilitymodifier") public static class RedirectHandler extends AbstractHandler { - String reason; + final String reason; - int retCode; + final int retCode; - String redirectUrl; + final String redirectUrl; - File repositoryDirectory; + final File repositoryDirectory; - public List handlerRequestResponses = new ArrayList<>(); + public final List handlerRequestResponses = new ArrayList<>(); RedirectHandler(String reason, int retCode, String redirectUrl, File repositoryDirectory) { this.reason = reason; @@ -1344,7 +1333,7 @@ private String writeTestFile(File parent, String child, String compressionType) File file = new File(parent, child); file.getParentFile().mkdirs(); file.deleteOnExit(); - OutputStream out = new FileOutputStream(file); + OutputStream out = Files.newOutputStream(file.toPath()); try { out.write(child.getBytes()); } finally { @@ -1362,7 +1351,7 @@ private String writeTestFile(File parent, String child, String compressionType) file = new File(parent, child + ext); file.deleteOnExit(); String content; - out = new FileOutputStream(file); + out = Files.newOutputStream(file.toPath()); if ("gzip".equals(compressionType)) { out = new GZIPOutputStream(out); } @@ -1418,8 +1407,7 @@ public void testPut429() throws Exception { AbstractHandler handler = new AbstractHandler() { public void handle( - String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { + String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) { if (called.get()) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); baseRequest.setHandled(true); @@ -1672,8 +1660,8 @@ public void setStatusToReturn(int status) { this.status = status; } - public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { + public void handle( + String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) { if (status != 0) { response.setStatus(status); baseRequest.setHandled(true); @@ -1696,14 +1684,11 @@ static class DeployedResource { @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("DeployedResource"); - sb.append("{httpMethod='").append(httpMethod).append('\''); - sb.append(", requestUri='").append(requestUri).append('\''); - sb.append(", contentLength='").append(contentLength).append('\''); - sb.append(", transferEncoding='").append(transferEncoding).append('\''); - sb.append('}'); - return sb.toString(); + return "DeployedResource" + "{httpMethod='" + + httpMethod + '\'' + ", requestUri='" + + requestUri + '\'' + ", contentLength='" + + contentLength + '\'' + ", transferEncoding='" + + transferEncoding + '\'' + '}'; } } @@ -1714,18 +1699,18 @@ public String toString() { public static class PutHandler extends AbstractHandler { private final File resourceBase; - public List deployedResources = new ArrayList<>(); + public final List deployedResources = new ArrayList<>(); public int putCallNumber = 0; - public List handlerRequestResponses = new ArrayList<>(); + public final List handlerRequestResponses = new ArrayList<>(); public PutHandler(File repositoryDirectory) { this.resourceBase = repositoryDirectory; } public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { + throws IOException { if (baseRequest.isHandled() || !"PUT".equals(baseRequest.getMethod())) { return; } @@ -1738,7 +1723,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques InputStream in = null; try { in = request.getInputStream(); - out = new FileOutputStream(file); + out = Files.newOutputStream(file.toPath()); IOUtil.copy(in, out); out.close(); out = null; @@ -1759,14 +1744,14 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques response.setStatus(HttpServletResponse.SC_CREATED); - handlerRequestResponses.add(new HandlerRequestResponse( - request.getMethod(), ((Response) response).getStatus(), request.getRequestURI())); + handlerRequestResponses.add( + new HandlerRequestResponse(request.getMethod(), response.getStatus(), request.getRequestURI())); } } private static class AuthorizingProxyHandler extends TestHeaderHandler { - List handlerRequestResponses = new ArrayList<>(); + final List handlerRequestResponses = new ArrayList<>(); public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { @@ -1795,7 +1780,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques private static class TestHeaderHandler extends AbstractHandler { public Map headers = Collections.emptyMap(); - public List handlerRequestResponses = new ArrayList<>(); + public final List handlerRequestResponses = new ArrayList<>(); TestHeaderHandler() {} @@ -1805,11 +1790,11 @@ public void handle( headers = new HashMap<>(); for (Enumeration e = baseRrequest.getHeaderNames(); e.hasMoreElements(); ) { String name = e.nextElement(); - Enumeration headerValues = baseRrequest.getHeaders(name); + Enumeration headerValues = baseRrequest.getHeaders(name); // as per HTTP spec http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html // multiple values for the same header key are concatenated separated by comma // otherwise we wouldn't notice headers with same key added multiple times - StringBuffer combinedHeaderValue = new StringBuffer(); + StringBuilder combinedHeaderValue = new StringBuilder(); for (int i = 0; headerValues.hasMoreElements(); i++) { if (i > 0) { combinedHeaderValue.append(","); @@ -1824,7 +1809,7 @@ public void handle( response.getWriter().print("Hello, World!"); handlerRequestResponses.add(new HandlerRequestResponse( - baseRrequest.getMethod(), ((Response) response).getStatus(), baseRrequest.getRequestURI())); + baseRrequest.getMethod(), response.getStatus(), baseRrequest.getRequestURI())); baseRrequest.setHandled(true); } @@ -1855,7 +1840,7 @@ protected TestSecurityHandler createSecurityHandler() { @SuppressWarnings("checkstyle:visibilitymodifier") public static class TestSecurityHandler extends ConstraintSecurityHandler { - public List handlerRequestResponses = new ArrayList<>(); + public final List handlerRequestResponses = new ArrayList<>(); @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) @@ -1864,7 +1849,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques super.handle(target, baseRequest, request, response); handlerRequestResponses.add( - new HandlerRequestResponse(method, ((Response) response).getStatus(), request.getRequestURI())); + new HandlerRequestResponse(method, response.getStatus(), request.getRequestURI())); } } @@ -1873,11 +1858,11 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques */ @SuppressWarnings("checkstyle:visibilitymodifier") public static class HandlerRequestResponse { - public String method; + public final String method; - public int responseCode; + public final int responseCode; - public String requestUri; + public final String requestUri; private HandlerRequestResponse(String method, int responseCode, String requestUri) { this.method = method; @@ -1887,13 +1872,10 @@ private HandlerRequestResponse(String method, int responseCode, String requestUr @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("HandlerRequestResponse"); - sb.append("{method='").append(method).append('\''); - sb.append(", responseCode=").append(responseCode); - sb.append(", requestUri='").append(requestUri).append('\''); - sb.append('}'); - return sb.toString(); + return "HandlerRequestResponse" + "{method='" + + method + '\'' + ", responseCode=" + + responseCode + ", requestUri='" + + requestUri + '\'' + '}'; } } diff --git a/wagon-providers/wagon-file/src/main/java/org/apache/maven/wagon/providers/file/FileWagon.java b/wagon-providers/wagon-file/src/main/java/org/apache/maven/wagon/providers/file/FileWagon.java index 778f28d4..b6b3c97e 100644 --- a/wagon-providers/wagon-file/src/main/java/org/apache/maven/wagon/providers/file/FileWagon.java +++ b/wagon-providers/wagon-file/src/main/java/org/apache/maven/wagon/providers/file/FileWagon.java @@ -36,7 +36,6 @@ import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.StreamWagon; import org.apache.maven.wagon.TransferFailedException; -import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.resource.Resource; import org.codehaus.plexus.util.FileUtils; @@ -122,8 +121,7 @@ public boolean supportsDirectoryCopy() { return true; } - public void putDirectory(File sourceDirectory, String destinationDirectory) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { + public void putDirectory(File sourceDirectory, String destinationDirectory) throws TransferFailedException { if (getRepository().getBasedir() == null) { throw new TransferFailedException("Unable to putDirectory() with a null basedir."); } @@ -182,7 +180,7 @@ private File resolveDestinationPath(String destinationPath) { } public List getFileList(String destinationDirectory) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { + throws TransferFailedException, ResourceDoesNotExistException { if (getRepository().getBasedir() == null) { throw new TransferFailedException("Unable to getFileList() with a null basedir."); } @@ -210,7 +208,7 @@ public List getFileList(String destinationDirectory) return list; } - public boolean resourceExists(String resourceName) throws TransferFailedException, AuthorizationException { + public boolean resourceExists(String resourceName) throws TransferFailedException { if (getRepository().getBasedir() == null) { throw new TransferFailedException("Unable to getFileList() with a null basedir."); } diff --git a/wagon-providers/wagon-ftp/pom.xml b/wagon-providers/wagon-ftp/pom.xml index 11fc24cd..ce24c319 100644 --- a/wagon-providers/wagon-ftp/pom.xml +++ b/wagon-providers/wagon-ftp/pom.xml @@ -55,6 +55,7 @@ under the License. commons-io commons-io + test diff --git a/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java b/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java index 7fd651d4..f2edd0e1 100644 --- a/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java +++ b/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java @@ -27,7 +27,6 @@ import java.util.Calendar; import java.util.List; -import org.apache.commons.io.IOUtils; import org.apache.commons.net.ProtocolCommandEvent; import org.apache.commons.net.ProtocolCommandListener; import org.apache.commons.net.ftp.FTP; @@ -44,7 +43,6 @@ import org.apache.maven.wagon.WagonConstants; import org.apache.maven.wagon.authentication.AuthenticationException; import org.apache.maven.wagon.authentication.AuthenticationInfo; -import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.repository.RepositoryPermissions; import org.apache.maven.wagon.resource.Resource; @@ -325,8 +323,7 @@ public void fillInputData(InputData inputData) throws TransferFailedException, R inputData.setInputStream(is); } - private void ftpChangeDirectory(Resource resource) - throws IOException, TransferFailedException, ResourceDoesNotExistException { + private void ftpChangeDirectory(Resource resource) throws IOException, ResourceDoesNotExistException { if (!ftp.changeWorkingDirectory(getRepository().getBasedir())) { throw new ResourceDoesNotExistException( "Required directory: '" + getRepository().getBasedir() + "' " + "is missing"); @@ -373,7 +370,7 @@ protected void fireSessionDebug(String msg) { @Override public List getFileList(String destinationDirectory) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { + throws TransferFailedException, ResourceDoesNotExistException { Resource resource = new Resource(destinationDirectory); try { @@ -404,7 +401,7 @@ public List getFileList(String destinationDirectory) } @Override - public boolean resourceExists(String resourceName) throws TransferFailedException, AuthorizationException { + public boolean resourceExists(String resourceName) throws TransferFailedException { Resource resource = new Resource(resourceName); try { @@ -431,8 +428,7 @@ public boolean supportsDirectoryCopy() { } @Override - public void putDirectory(File sourceDirectory, String destinationDirectory) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { + public void putDirectory(File sourceDirectory, String destinationDirectory) throws TransferFailedException { // Change to root. try { @@ -515,11 +511,7 @@ private void ftpRecursivePut(File sourceFile, String fileName) throws TransferFa } } else { // Oh how I hope and pray, in denial, but today I am still just a file. - - FileInputStream sourceFileStream = null; - try { - sourceFileStream = new FileInputStream(sourceFile); - + try (FileInputStream sourceFileStream = new FileInputStream(sourceFile)) { // It's a file. Upload it in the current directory. if (ftp.storeFile(fileName, sourceFileStream)) { if (permissions != null) { @@ -547,14 +539,9 @@ private void ftpRecursivePut(File sourceFile, String fileName) throws TransferFa + "' FTP Server response: " + ftp.getReplyString(); throw new TransferFailedException(msg); } - - sourceFileStream.close(); - sourceFileStream = null; } catch (IOException e) { throw new TransferFailedException( "IOException caught while attempting to upload " + sourceFile.getAbsolutePath(), e); - } finally { - IOUtils.closeQuietly(sourceFileStream); } } diff --git a/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java b/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java index f206d20f..a54062d2 100644 --- a/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java +++ b/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java @@ -108,7 +108,7 @@ protected void createDirectory(Wagon wagon, String resourceToCreate, String dirN getRepositoryDirectory().mkdirs(); } - protected void tearDownWagonTestingFixtures() throws Exception { + protected void tearDownWagonTestingFixtures() { server.stop(); server = null; } diff --git a/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpsWagonTest.java b/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpsWagonTest.java index 64fcfc4c..49987ebd 100644 --- a/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpsWagonTest.java +++ b/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpsWagonTest.java @@ -43,9 +43,4 @@ protected ServerConnector addConnector(Server server) { server.addConnector(serverConnector); return serverConnector; } - - @Override - protected boolean assertOnTransferProgress() { - return false; - } } diff --git a/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java b/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java index 4f1f310d..4fd4ba71 100644 --- a/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java +++ b/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java @@ -18,9 +18,6 @@ */ package org.apache.maven.wagon.shared.http; -import java.net.MalformedURLException; -import java.net.URISyntaxException; - import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -34,28 +31,28 @@ public void testEncodeURLWithTrailingSlash() { } @Test - public void testEncodeURLWithSpaces() throws URISyntaxException, MalformedURLException { + public void testEncodeURLWithSpaces() { String encodedURL = EncodingUtil.encodeURLToString("file://host:1/path with spaces"); assertEquals("file://host:1/path%20with%20spaces", encodedURL); } @Test - public void testEncodeURLWithSpacesInPath() throws URISyntaxException, MalformedURLException { + public void testEncodeURLWithSpacesInPath() { String encodedURL = EncodingUtil.encodeURLToString("file://host:1", "path with spaces"); assertEquals("file://host:1/path%20with%20spaces", encodedURL); } @Test - public void testEncodeURLWithSpacesInBothBaseAndPath() throws URISyntaxException, MalformedURLException { + public void testEncodeURLWithSpacesInBothBaseAndPath() { String encodedURL = EncodingUtil.encodeURLToString("file://host:1/with%20a", "path with spaces"); assertEquals("file://host:1/with%20a/path%20with%20spaces", encodedURL); } @Test - public void testEncodeURLWithSlashes1() throws URISyntaxException, MalformedURLException { + public void testEncodeURLWithSlashes1() { String encodedURL = EncodingUtil.encodeURLToString("file://host:1/basePath", "a", "b", "c"); assertEquals("file://host:1/basePath/a/b/c", encodedURL); @@ -66,7 +63,7 @@ public void testEncodeURLWithSlashes1() throws URISyntaxException, MalformedURLE } @Test - public void testEncodeURLWithSlashes2() throws URISyntaxException, MalformedURLException { + public void testEncodeURLWithSlashes2() { String encodedURL = EncodingUtil.encodeURLToString("file://host:1/basePath/", "a", "b", "c"); assertEquals("file://host:1/basePath/a/b/c", encodedURL); @@ -77,42 +74,42 @@ public void testEncodeURLWithSlashes2() throws URISyntaxException, MalformedURLE } @Test - public void testEncodeURLWithSlashes3() throws URISyntaxException, MalformedURLException { + public void testEncodeURLWithSlashes3() { String encodedURL = EncodingUtil.encodeURLToString("file://host:1/basePath/", new String[0]); assertEquals("file://host:1/basePath/", encodedURL); } @Test - public void testEncodeURLWithSlashes4() throws URISyntaxException, MalformedURLException { + public void testEncodeURLWithSlashes4() { String encodedURL = EncodingUtil.encodeURLToString("file://host:1/basePath", new String[0]); assertEquals("file://host:1/basePath", encodedURL); } @Test - public void testEncodeURLWithSlashes5() throws URISyntaxException, MalformedURLException { + public void testEncodeURLWithSlashes5() { String encodedURL = EncodingUtil.encodeURLToString("file://host:1/basePath", "a/1", "b/1", "c/1"); assertEquals("file://host:1/basePath/a%2F1/b%2F1/c%2F1", encodedURL); } @Test - public void testEncodeURLWithSlashes6() throws URISyntaxException, MalformedURLException { + public void testEncodeURLWithSlashes6() { String encodedURL = EncodingUtil.encodeURLToString("file://host:1/", new String[0]); assertEquals("file://host:1/", encodedURL); } @Test - public void testEncodeURLWithSlashes7() throws URISyntaxException, MalformedURLException { + public void testEncodeURLWithSlashes7() { String encodedURL = EncodingUtil.encodeURLToString("file://host:1", new String[0]); assertEquals("file://host:1", encodedURL); } @Test - public void testEncodeURLWithNonLatin() throws URISyntaxException, MalformedURLException { + public void testEncodeURLWithNonLatin() { String encodedURL = EncodingUtil.encodeURLToString("file://host:1", "пипец/"); assertEquals("file://host:1/%D0%BF%D0%B8%D0%BF%D0%B5%D1%86/", encodedURL); diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagonTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagonTest.java index 6ae9f3b1..a5fbe186 100644 --- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagonTest.java +++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagonTest.java @@ -58,7 +58,7 @@ public class AbstractHttpClientWagonTest { public void test() throws Exception { AbstractHttpClientWagon wagon = new AbstractHttpClientWagon() {}; - Repository repository = new Repository("central", "http://repo.maven.apache.org/maven2"); + Repository repository = new Repository("central", "https://repo.maven.apache.org/maven2"); wagon.connect(repository); @@ -77,82 +77,70 @@ public void test() throws Exception { @Test public void retryableConfigurationDefaultTest() throws Exception { - doTestHttpClient(new Runnable() { - @Override - public void run() { - final HttpRequestRetryHandler handler = getCurrentHandler(); - assertNotNull(handler); - assertThat(handler, instanceOf(DefaultHttpRequestRetryHandler.class)); - final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler); - assertEquals(3, impl.getRetryCount()); - assertFalse(impl.isRequestSentRetryEnabled()); - } + doTestHttpClient(() -> { + final HttpRequestRetryHandler handler = getCurrentHandler(); + assertNotNull(handler); + assertThat(handler, instanceOf(DefaultHttpRequestRetryHandler.class)); + final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler); + assertEquals(3, impl.getRetryCount()); + assertFalse(impl.isRequestSentRetryEnabled()); }); } @Test public void retryableConfigurationCountTest() throws Exception { - doTestHttpClient(new Runnable() { - @Override - public void run() { - System.setProperty("maven.wagon.http.retryHandler.class", "default"); - System.setProperty("maven.wagon.http.retryHandler.count", "5"); - - final HttpRequestRetryHandler handler = getCurrentHandler(); - assertNotNull(handler); - assertThat(handler, instanceOf(DefaultHttpRequestRetryHandler.class)); - final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler); - assertEquals(5, impl.getRetryCount()); - assertFalse(impl.isRequestSentRetryEnabled()); - } + doTestHttpClient(() -> { + System.setProperty("maven.wagon.http.retryHandler.class", "default"); + System.setProperty("maven.wagon.http.retryHandler.count", "5"); + + final HttpRequestRetryHandler handler = getCurrentHandler(); + assertNotNull(handler); + assertThat(handler, instanceOf(DefaultHttpRequestRetryHandler.class)); + final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler); + assertEquals(5, impl.getRetryCount()); + assertFalse(impl.isRequestSentRetryEnabled()); }); } @Test public void retryableConfigurationSentTest() throws Exception { - doTestHttpClient(new Runnable() { - @Override - public void run() { - System.setProperty("maven.wagon.http.retryHandler.class", "default"); - System.setProperty("maven.wagon.http.retryHandler.requestSentEnabled", "true"); - - final HttpRequestRetryHandler handler = getCurrentHandler(); - assertNotNull(handler); - assertThat(handler, instanceOf(DefaultHttpRequestRetryHandler.class)); - final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler); - assertEquals(3, impl.getRetryCount()); - assertTrue(impl.isRequestSentRetryEnabled()); - } + doTestHttpClient(() -> { + System.setProperty("maven.wagon.http.retryHandler.class", "default"); + System.setProperty("maven.wagon.http.retryHandler.requestSentEnabled", "true"); + + final HttpRequestRetryHandler handler = getCurrentHandler(); + assertNotNull(handler); + assertThat(handler, instanceOf(DefaultHttpRequestRetryHandler.class)); + final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler); + assertEquals(3, impl.getRetryCount()); + assertTrue(impl.isRequestSentRetryEnabled()); }); } @Test public void retryableConfigurationExceptionsTest() throws Exception { - doTestHttpClient(new Runnable() { - @Override - public void run() { - System.setProperty("maven.wagon.http.retryHandler.class", "default"); - System.setProperty("maven.wagon.http.retryHandler.nonRetryableClasses", IOException.class.getName()); - - final HttpRequestRetryHandler handler = getCurrentHandler(); - assertNotNull(handler); - assertThat(handler, instanceOf(DefaultHttpRequestRetryHandler.class)); - final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler); - assertEquals(3, impl.getRetryCount()); - assertFalse(impl.isRequestSentRetryEnabled()); - - try { - final Field nonRetriableClasses = - handler.getClass().getSuperclass().getDeclaredField("nonRetriableClasses"); - if (!nonRetriableClasses.isAccessible()) { - nonRetriableClasses.setAccessible(true); - } - final Set exceptions = Set.class.cast(nonRetriableClasses.get(handler)); - assertEquals(1, exceptions.size()); - assertTrue(exceptions.contains(IOException.class)); - } catch (final Exception e) { - fail(e.getMessage()); + doTestHttpClient(() -> { + System.setProperty("maven.wagon.http.retryHandler.class", "default"); + System.setProperty("maven.wagon.http.retryHandler.nonRetryableClasses", IOException.class.getName()); + + final HttpRequestRetryHandler handler = getCurrentHandler(); + assertNotNull(handler); + assertThat(handler, instanceOf(DefaultHttpRequestRetryHandler.class)); + final DefaultHttpRequestRetryHandler impl = DefaultHttpRequestRetryHandler.class.cast(handler); + assertEquals(3, impl.getRetryCount()); + assertFalse(impl.isRequestSentRetryEnabled()); + + try { + final Field nonRetriableClasses = + handler.getClass().getSuperclass().getDeclaredField("nonRetriableClasses"); + if (!nonRetriableClasses.isAccessible()) { + nonRetriableClasses.setAccessible(true); } + final Set exceptions = Set.class.cast(nonRetriableClasses.get(handler)); + assertEquals(1, exceptions.size()); + assertTrue(exceptions.contains(IOException.class)); + } catch (final Exception e) { + fail(e.getMessage()); } }); } @@ -163,26 +151,26 @@ private HttpRequestRetryHandler getCurrentHandler() { .getContextClassLoader() .loadClass("org.apache.maven.wagon.shared.http.AbstractHttpClientWagon"); - final CloseableHttpClient httpClient = CloseableHttpClient.class.cast( - impl.getMethod("getHttpClient").invoke(null)); + final CloseableHttpClient httpClient = + (CloseableHttpClient) impl.getMethod("getHttpClient").invoke(null); final Field redirectExec = httpClient.getClass().getDeclaredField("execChain"); if (!redirectExec.isAccessible()) { redirectExec.setAccessible(true); } - final RedirectExec redirectExecInstance = RedirectExec.class.cast(redirectExec.get(httpClient)); + final RedirectExec redirectExecInstance = (RedirectExec) redirectExec.get(httpClient); final Field requestExecutor = redirectExecInstance.getClass().getDeclaredField("requestExecutor"); if (!requestExecutor.isAccessible()) { requestExecutor.setAccessible(true); } - final RetryExec requestExecutorInstance = RetryExec.class.cast(requestExecutor.get(redirectExecInstance)); + final RetryExec requestExecutorInstance = (RetryExec) requestExecutor.get(redirectExecInstance); final Field retryHandler = requestExecutorInstance.getClass().getDeclaredField("retryHandler"); if (!retryHandler.isAccessible()) { retryHandler.setAccessible(true); } - return HttpRequestRetryHandler.class.cast(retryHandler.get(requestExecutorInstance)); + return (HttpRequestRetryHandler) retryHandler.get(requestExecutorInstance); } catch (final Exception e) { throw new IllegalStateException(e); } diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/ErrorWithMessageServlet.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/ErrorWithMessageServlet.java index 4eadd309..f1d5dcd4 100644 --- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/ErrorWithMessageServlet.java +++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/ErrorWithMessageServlet.java @@ -37,7 +37,6 @@ * under the License. */ -import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -54,7 +53,7 @@ public class ErrorWithMessageServlet extends HttpServlet { public static final String MESSAGE = "it sucks!"; - public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { if (request.getPathInfo().endsWith("/401")) { response.sendError(401, MESSAGE); } else if (request.getPathInfo().endsWith("/403")) { diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java index 1ad6c5c1..8b2ba062 100755 --- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java +++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java @@ -22,7 +22,6 @@ import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpHead; import org.apache.maven.wagon.OutputData; -import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.shared.http.AbstractHttpClientWagon; import org.apache.maven.wagon.shared.http.ConfigurationUtils; import org.apache.maven.wagon.shared.http.HttpConfiguration; @@ -99,6 +98,6 @@ public void testTurnOffDefaultHeaders() { private static final class TestWagon extends AbstractHttpClientWagon { @Override - public void fillOutputData(OutputData outputData) throws TransferFailedException {} + public void fillOutputData(OutputData outputData) {} } } 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..edaa47a5 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 @@ -46,7 +46,7 @@ protected void setUp() throws Exception { } protected Wagon getWagon() throws Exception { - return (Wagon) lookup(HttpWagon.ROLE); + return lookup(HttpWagon.ROLE); } protected void startServer() throws Exception { diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonPreemptiveTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonPreemptiveTest.java index e911c8af..ae97108a 100644 --- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonPreemptiveTest.java +++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpWagonPreemptiveTest.java @@ -35,18 +35,8 @@ protected Wagon getWagon() throws Exception { return wagon; } - @Override - protected boolean supportPreemptiveAuthenticationPut() { - return true; - } - @Override protected boolean supportPreemptiveAuthenticationGet() { return true; } - - @Override - protected boolean supportProxyPreemptiveAuthentication() { - return true; - } } diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpsWagonPreemptiveTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpsWagonPreemptiveTest.java index 9a570470..f5fb90ae 100644 --- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpsWagonPreemptiveTest.java +++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpsWagonPreemptiveTest.java @@ -53,23 +53,8 @@ protected Wagon getWagon() throws Exception { return wagon; } - @Override - protected boolean supportPreemptiveAuthenticationPut() { - return true; - } - @Override protected boolean supportPreemptiveAuthenticationGet() { return true; } - - @Override - protected boolean supportProxyPreemptiveAuthentication() { - return true; - } - - @Override - protected boolean assertOnTransferProgress() { - return false; - } } diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpsWagonTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpsWagonTest.java index 00928f70..b95469b3 100644 --- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpsWagonTest.java +++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpsWagonTest.java @@ -27,10 +27,6 @@ protected String getProtocol() { return "https"; } - protected boolean assertOnTransferProgress() { - return false; - } - protected ServerConnector addConnector(Server server) { System.setProperty( "javax.net.ssl.trustStore", diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HugeFileDownloadTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HugeFileDownloadTest.java index 7b68d6ef..9f1b452e 100644 --- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HugeFileDownloadTest.java +++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HugeFileDownloadTest.java @@ -18,7 +18,6 @@ */ package org.apache.maven.wagon.providers.http; -import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -53,8 +52,9 @@ public class HugeFileDownloadTest extends PlexusTestCase { private static final Logger LOGGER = LoggerFactory.getLogger(HugeFileDownloadTest.class); - private static long HUGE_FILE_SIZE = Integer.valueOf(Integer.MAX_VALUE).longValue() - + Integer.valueOf(Integer.MAX_VALUE).longValue(); + private static final long HUGE_FILE_SIZE = + Integer.valueOf(Integer.MAX_VALUE).longValue() + + Integer.valueOf(Integer.MAX_VALUE).longValue(); private Server server; private ServerConnector connector; @@ -73,8 +73,7 @@ public void testDownloadHugeFileWithContentLength() throws Exception { root.setResourceBase(new File(getBasedir(), "target").getAbsolutePath()); ServletHolder servletHolder = new ServletHolder(new HttpServlet() { @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { FileInputStream fis = new FileInputStream(hugeFile); resp.addHeader("Content-Length", String.valueOf(hugeFile.length())); @@ -122,8 +121,7 @@ public void testDownloadHugeFileWithChunked() throws Exception { root.setResourceBase(new File(getBasedir(), "target").getAbsolutePath()); ServletHolder servletHolder = new ServletHolder(new HttpServlet() { @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { FileInputStream fis = new FileInputStream(hugeFile); IOUtil.copy(fis, resp.getOutputStream()); @@ -157,7 +155,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) } protected Wagon getWagon() throws Exception { - Wagon wagon = (Wagon) lookup(Wagon.ROLE, "http"); + Wagon wagon = lookup(Wagon.ROLE, "http"); Debug debug = new Debug(); diff --git a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmCvsWagonTest.java b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmCvsWagonTest.java index c59bd86d..21c1b228 100644 --- a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmCvsWagonTest.java +++ b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmCvsWagonTest.java @@ -19,7 +19,6 @@ package org.apache.maven.wagon.providers.scm; import java.io.File; -import java.io.IOException; import org.codehaus.plexus.util.FileUtils; @@ -51,7 +50,7 @@ protected String getScmId() { return "cvs"; } - protected String getTestRepositoryUrl() throws IOException { + protected String getTestRepositoryUrl() { return repository; } } diff --git a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java index c0d8bd28..39adcbee 100644 --- a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java +++ b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java @@ -90,7 +90,7 @@ protected ScmProvider getScmProvider() { return null; } - protected Wagon getWagon() throws Exception { + protected Wagon getWagon() { return wagon; } diff --git a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmCvsExeWagonTest.java b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmCvsExeWagonTest.java index ca9b99d9..679746e4 100644 --- a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmCvsExeWagonTest.java +++ b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmCvsExeWagonTest.java @@ -42,17 +42,17 @@ protected ScmProvider getScmProvider() { } @Override - public void testWagonGetFileList() throws Exception { + public void testWagonGetFileList() { // cvs rls is rare } @Override - public void testWagonResourceExists() throws Exception { + public void testWagonResourceExists() { // cvs rls is rare } @Override - public void testWagonResourceNotExists() throws Exception { + public void testWagonResourceNotExists() { // cvs rls is rare } diff --git a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmGitExeWagonTest.java b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmGitExeWagonTest.java index dcedd79b..28e616de 100644 --- a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmGitExeWagonTest.java +++ b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmGitExeWagonTest.java @@ -30,7 +30,7 @@ protected ScmProvider getScmProvider() { } @Override - public void testWagonGetFileList() throws Exception { + public void testWagonGetFileList() { // remote list unsupported // When a command is unsupported, SCM throws NoSuchCommandScmException. // However, there's no equivalent exception in the Wagon API. @@ -40,22 +40,17 @@ public void testWagonGetFileList() throws Exception { } @Override - public void testWagonGetFileListWhenDirectoryDoesNotExist() throws Exception { + public void testWagonGetFileListWhenDirectoryDoesNotExist() { // remote list unsupported } @Override - public void testWagonResourceExists() throws Exception { + public void testWagonResourceExists() { // remote list unsupported } @Override - public void testWagonResourceNotExists() throws Exception { + public void testWagonResourceNotExists() { // remote list unsupported } - - @Override - protected boolean supportsGetIfNewer() { - return false; - } } diff --git a/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestPasswordAuthenticator.java b/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestPasswordAuthenticator.java index b25f64f4..d966763a 100644 --- a/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestPasswordAuthenticator.java +++ b/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestPasswordAuthenticator.java @@ -52,12 +52,9 @@ public PasswordAuthenticatorRequest(String username, String password) { @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("PasswordAuthenticatorRequest"); - sb.append("{username='").append(username).append('\''); - sb.append(", password='").append(password).append('\''); - sb.append('}'); - return sb.toString(); + return "PasswordAuthenticatorRequest" + "{username='" + + username + '\'' + ", password='" + + password + '\'' + '}'; } public String getUsername() { diff --git a/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestPublickeyAuthenticator.java b/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestPublickeyAuthenticator.java index e77bef72..8081030b 100644 --- a/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestPublickeyAuthenticator.java +++ b/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/TestPublickeyAuthenticator.java @@ -92,12 +92,7 @@ public PublickeyAuthenticatorRequest(String username, PublicKey publicKey) { @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("PublickeyAuthenticatorRequest"); - sb.append("{username='").append(username).append('\''); - sb.append(", publicKey=").append(publicKey); - sb.append('}'); - return sb.toString(); + return "PublickeyAuthenticatorRequest" + "{username='" + username + '\'' + ", publicKey=" + publicKey + '}'; } } diff --git a/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostsProviderTestCase.java b/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostsProviderTestCase.java index 8616a187..2cf9fb8b 100644 --- a/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostsProviderTestCase.java +++ b/wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostsProviderTestCase.java @@ -98,7 +98,7 @@ protected void setUp() throws Exception { super.setUp(); source = new Repository("test", "scp://" + TestData.getUserName() + "@" + TestData.getHostname() + "/tmp/foo"); - wagon = (SshWagon) lookup(Wagon.ROLE, "scp"); + wagon = lookup(Wagon.ROLE, "scp"); wagon.setInteractive(false); this.okHostsProvider = new SingleKnownHostProvider(TestData.getHostname(), CORRECT_KEY); diff --git a/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/jsch/EmbeddedScpWagonWithKeyTest.java b/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/jsch/EmbeddedScpWagonWithKeyTest.java index a0f4e771..c9d9e5d9 100644 --- a/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/jsch/EmbeddedScpWagonWithKeyTest.java +++ b/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/jsch/EmbeddedScpWagonWithKeyTest.java @@ -19,7 +19,6 @@ package org.apache.maven.wagon.providers.ssh.jsch; import java.io.File; -import java.io.IOException; import org.apache.maven.wagon.Wagon; import org.apache.maven.wagon.authentication.AuthenticationInfo; @@ -38,9 +37,9 @@ protected Wagon getWagon() throws Exception { ScpWagon scpWagon = (ScpWagon) super.getWagon(); scpWagon.setInteractive(false); scpWagon.setKnownHostsProvider(new KnownHostsProvider() { - public void storeKnownHosts(String contents) throws IOException {} + public void storeKnownHosts(String contents) {} - public void addKnownHost(KnownHostEntry knownHost) throws IOException {} + public void addKnownHost(KnownHostEntry knownHost) {} public void setHostKeyChecking(String hostKeyChecking) {} diff --git a/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/jsch/ScpWagonWithProxyTest.java b/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/jsch/ScpWagonWithProxyTest.java index aed55deb..201faa4e 100644 --- a/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/jsch/ScpWagonWithProxyTest.java +++ b/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/jsch/ScpWagonWithProxyTest.java @@ -18,7 +18,6 @@ */ package org.apache.maven.wagon.providers.ssh.jsch; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -48,8 +47,7 @@ public void testHttpProxy() throws Exception { handled = false; Handler handler = new AbstractHandler() { public void handle( - String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { + String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) { assertEquals("CONNECT", request.getMethod()); handled = true; @@ -70,7 +68,7 @@ public void handle( proxyInfo.setType("http"); proxyInfo.setNonProxyHosts(null); - Wagon wagon = (Wagon) lookup(Wagon.ROLE, "scp"); + Wagon wagon = lookup(Wagon.ROLE, "scp"); try { wagon.connect(new Repository("id", "scp://localhost/tmp"), proxyInfo); fail(); @@ -140,12 +138,12 @@ public void run() { } handled = true; - } catch (IOException e) { + } catch (IOException ignored) { } finally { if (sock != null) { try { sock.close(); - } catch (IOException e) { + } catch (IOException ignored) { } } } @@ -154,7 +152,7 @@ public void run() { if (ssock != null) { try { ssock.close(); - } catch (IOException e) { + } catch (IOException ignored) { } } } diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java index 9e79d556..2e186538 100644 --- a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java +++ b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java @@ -23,7 +23,6 @@ import org.apache.http.params.HttpParams; import org.apache.maven.wagon.ConnectionException; import org.apache.maven.wagon.OutputData; -import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.authentication.AuthenticationException; import org.apache.maven.wagon.authentication.AuthenticationInfo; import org.apache.maven.wagon.proxy.ProxyInfo; @@ -201,6 +200,6 @@ public void testNTCredentialsWithNTDomain() throws AuthenticationException, Conn private static final class TestWagon extends WebDavWagon { @Override - public void fillOutputData(OutputData outputData) throws TransferFailedException {} + public void fillOutputData(OutputData outputData) {} } } diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java index 223e2888..de4a4e31 100644 --- a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java +++ b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java @@ -52,7 +52,7 @@ */ public class WebDavWagonTest extends HttpWagonTestCase { - protected String getTestRepositoryUrl() throws IOException { + protected String getTestRepositoryUrl() { return getProtocol() + "://localhost:" + getTestRepositoryPort() + "/newfolder/folder2/"; } @@ -60,7 +60,7 @@ protected String getProtocol() { return "dav"; } - protected ServletContextHandler createContext(Server server, File repositoryDirectory) throws IOException { + protected ServletContextHandler createContext(Server server, File repositoryDirectory) { ServletContextHandler dav = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletHolder davServletHolder = new ServletHolder(new DAVServlet()); davServletHolder.setInitParameter("rootPath", repositoryDirectory.getAbsolutePath()); @@ -225,17 +225,17 @@ public void testWagonWebDavGetFileList() throws Exception { String dirName = "file-list"; - String filenames[] = + String[] filenames = new String[] {"test-resource.txt", "test-resource.pom", "test-resource b.txt", "more-resources.dat"}; - for (int i = 0; i < filenames.length; i++) { - putFile(dirName + "/" + filenames[i], dirName + "/" + filenames[i], filenames[i] + "\n"); + for (String filename : filenames) { + putFile(dirName + "/" + filename, dirName + "/" + filename, filename + "\n"); } - String dirnames[] = new String[] {"test-dir1", "test-dir2"}; + String[] dirnames = new String[] {"test-dir1", "test-dir2"}; - for (int i = 0; i < dirnames.length; i++) { - new File(getDavRepository(), dirName + "/" + dirnames[i]).mkdirs(); + for (String dirname : dirnames) { + new File(getDavRepository(), dirName + "/" + dirname).mkdirs(); } Wagon wagon = getWagon(); @@ -247,12 +247,12 @@ public void testWagonWebDavGetFileList() throws Exception { assertNotNull("file list should not be null.", list); assertEquals("file list should contain 6 items", 6, list.size()); - for (int i = 0; i < filenames.length; i++) { - assertTrue("Filename '" + filenames[i] + "' should be in list.", list.contains(filenames[i])); + for (String filename : filenames) { + assertTrue("Filename '" + filename + "' should be in list.", list.contains(filename)); } - for (int i = 0; i < dirnames.length; i++) { - assertTrue("Directory '" + dirnames[i] + "' should be in list.", list.contains(dirnames[i] + "/")); + for (String dirname : dirnames) { + assertTrue("Directory '" + dirname + "' should be in list.", list.contains(dirname + "/")); } /////////////////////////////////////////////////////////////////////////// @@ -269,7 +269,7 @@ public void testWagonWebDavGetFileList() throws Exception { try { list = wagon.getFileList(dirName + "/test-dir-bogus"); fail("Exception expected"); - } catch (ResourceDoesNotExistException e) { + } catch (ResourceDoesNotExistException ignored) { } @@ -296,7 +296,7 @@ public void testWagonFailsOnPutFailureByDefault() throws Exception { try { wagon.put(testFile, filename); fail("Exception expected"); - } catch (TransferFailedException e) { + } catch (TransferFailedException ignored) { } } finally { diff --git a/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/GetWagonTests.java b/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/GetWagonTests.java index 688c16a7..c826cbc7 100644 --- a/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/GetWagonTests.java +++ b/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/GetWagonTests.java @@ -43,8 +43,7 @@ import org.junit.Ignore; import org.junit.Test; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static junit.framework.Assert.*; import static org.apache.maven.wagon.tck.http.Assertions.NO_RESPONSE_STATUS_CODE; import static org.apache.maven.wagon.tck.http.Assertions.assertFileContentsFromResource; import static org.apache.maven.wagon.tck.http.Assertions.assertWagonExceptionMessage; @@ -100,9 +99,7 @@ public void highLatencyLowTimeout() } @Test - public void inifiniteLatencyTimeout() - throws ConnectionException, AuthenticationException, ComponentConfigurationException, IOException, - TransferFailedException, ResourceDoesNotExistException, AuthorizationException { + public void inifiniteLatencyTimeout() { if (!isSupported()) { return; } @@ -155,7 +152,7 @@ public void run() { logger.info("Interrupting thread."); t.interrupt(); - assertTrue("TransferFailedException should have been thrown.", holder.getValue() != null); + assertNotNull("TransferFailedException should have been thrown.", holder.getValue()); assertWagonExceptionMessage(holder.getValue(), NO_RESPONSE_STATUS_CODE, getBaseUrl() + "infinite/", "", null); } @@ -235,7 +232,7 @@ public void sixLevelTemporaryMove() @Test public void infinitePermanentMove() throws ConnectionException, AuthenticationException, ComponentConfigurationException, IOException, - TransferFailedException, ResourceDoesNotExistException, AuthorizationException { + ResourceDoesNotExistException, AuthorizationException { String myPath = "moved.txt"; String targetPath = "/base.txt"; @@ -280,7 +277,7 @@ public void infiniteTemporaryMove() @SuppressWarnings("checkstyle:methodname") public void permanentMove_TooManyRedirects_limit20() throws ConnectionException, AuthenticationException, ComponentConfigurationException, IOException, - TransferFailedException, ResourceDoesNotExistException, AuthorizationException { + ResourceDoesNotExistException, AuthorizationException { String myPath = "moved.txt"; String targetPath = "/base.txt"; diff --git a/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/HttpWagonTests.java b/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/HttpWagonTests.java index 8fcbd25c..3a454aa9 100644 --- a/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/HttpWagonTests.java +++ b/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/HttpWagonTests.java @@ -237,12 +237,7 @@ protected int getPortPropertyValue() { protected String getBaseUrl() { if (baseUrl == null) { - StringBuilder sb = new StringBuilder(); - sb.append(isSsl() ? "https" : "http"); - sb.append("://" + ServerFixture.SERVER_HOST + ":"); - sb.append(getPort()); - - baseUrl = sb.toString(); + baseUrl = (isSsl() ? "https" : "http") + "://" + ServerFixture.SERVER_HOST + ":" + getPort(); } return baseUrl; diff --git a/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/WagonTestCaseConfigurator.java b/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/WagonTestCaseConfigurator.java index 190c9ba7..5a73a71a 100644 --- a/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/WagonTestCaseConfigurator.java +++ b/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/WagonTestCaseConfigurator.java @@ -46,14 +46,14 @@ public class WagonTestCaseConfigurator implements Contextualizable { private String wagonHint; - private static Logger logger = LoggerFactory.getLogger(WagonTestCaseConfigurator.class); + private static final Logger LOGGER = LoggerFactory.getLogger(WagonTestCaseConfigurator.class); public boolean isSupported(final String useCaseId) { if (useCaseConfigs != null) { PlexusConfiguration config = useCaseConfigs.getChild(useCaseId, false); if (config != null && config.getChild(UNSUPPORTED_ELEMENT, false) != null) { - logger.info("Test case '" + useCaseId + "' is marked as unsupported by this wagon."); + LOGGER.info("Test case '" + useCaseId + "' is marked as unsupported by this wagon."); return false; } } @@ -68,17 +68,17 @@ public boolean configureWagonForTest(final Wagon wagon, final String useCaseId) if (config != null) { if (config.getChild(UNSUPPORTED_ELEMENT, false) != null) { - logger.error("Test case '" + useCaseId + "' is marked as unsupported by this wagon."); + LOGGER.error("Test case '" + useCaseId + "' is marked as unsupported by this wagon."); return false; } else { - logger.info("Configuring wagon for test case: " + useCaseId + " with:\n\n" + config); + LOGGER.info("Configuring wagon for test case: " + useCaseId + " with:\n\n" + config); configurator.configureComponent(wagon, useCaseConfigs.getChild(useCaseId, false), realm); } } else { - logger.info("No wagon configuration found for test case: " + useCaseId); + LOGGER.info("No wagon configuration found for test case: " + useCaseId); } } else { - logger.info("No test case configurations found."); + LOGGER.info("No test case configurations found."); } return true; diff --git a/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/fixture/ErrorCodeServlet.java b/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/fixture/ErrorCodeServlet.java index 110fb588..cc545aa0 100644 --- a/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/fixture/ErrorCodeServlet.java +++ b/wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/fixture/ErrorCodeServlet.java @@ -18,7 +18,6 @@ */ package org.apache.maven.wagon.tck.http.fixture; -import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -42,8 +41,7 @@ public ErrorCodeServlet(final int code, final String message) { } @Override - protected void service(final HttpServletRequest req, final HttpServletResponse resp) - throws ServletException, IOException { + protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { resp.sendError(code, message); } }