Skip to content

Commit

Permalink
Cleanup junit 4 tests #2
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Feb 12, 2024
1 parent 2e35945 commit 96aba15
Show file tree
Hide file tree
Showing 43 changed files with 223 additions and 354 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ under the License.
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<version>2.15.1</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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("");
}
};

Expand Down Expand Up @@ -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(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import java.util.Collections;
import java.util.List;

import org.apache.maven.wagon.authorization.AuthorizationException;

/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -90,12 +88,11 @@ public int getTimeout() {
return timeout;
}

public List<String> getFileList(String destinationDirectory)
throws TransferFailedException, AuthorizationException {
return Collections.<String>emptyList();
public List<String> getFileList(String destinationDirectory) {
return Collections.emptyList();
}

public boolean resourceExists(String resourceName) throws AuthorizationException {
public boolean resourceExists(String resourceName) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SessionEventSupportTest {
private Wagon wagon;

@Before
public void setUp() throws Exception {
public void setUp() {

eventSupport = new SessionEventSupport();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class TransferEventSupportTest {
private Wagon wagon;

@Before
public void setUp() throws Exception {
public void setUp() {

eventSupport = new TransferEventSupport();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testTransferEventProperties() throws ConnectionException, Authentica

event.setResource(null);

assertEquals(null, event.getResource());
assertNull(event.getResource());

res.setName("/foo/baa");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
public class RepositoryTest {
@Test
public void testRepositoryProperties() throws Exception {
public void testRepositoryProperties() {
Repository repository = new Repository();

repository.setBasedir("directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/
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;
Expand Down Expand Up @@ -163,7 +163,7 @@ protected void setupRepositories() throws Exception {
}
}

protected void customizeContext() throws Exception {
protected void customizeContext() {
getContainer().addContextValue("test.repository", localRepositoryPath);
}

Expand All @@ -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();

Expand Down Expand Up @@ -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"
};

Expand All @@ -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("."));
Expand Down
Loading

0 comments on commit 96aba15

Please sign in to comment.