Skip to content

Commit

Permalink
[MRESOLVER-418] Migrate to JUnit 5 (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas authored Oct 20, 2023
1 parent b119627 commit e3fc1dc
Show file tree
Hide file tree
Showing 155 changed files with 2,171 additions and 2,308 deletions.
9 changes: 2 additions & 7 deletions maven-resolver-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,8 @@

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@

import java.lang.reflect.Method;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class AbstractForwardingRepositorySystemSessionTest {

@Test
public void testAllMethodsImplemented() throws Exception {
void testAllMethodsImplemented() throws Exception {
for (Method method : RepositorySystemSession.class.getMethods()) {
Method m = AbstractForwardingRepositorySystemSession.class.getDeclaredMethod(
method.getName(), method.getParameterTypes());
assertNotNull(method.toString(), m);
assertNotNull(m, method.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

import java.lang.reflect.Method;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

/**
*/
public class AbstractRepositoryListenerTest {

@Test
public void testAllEventTypesHandled() throws Exception {
void testAllEventTypesHandled() throws Exception {
for (Method method : RepositoryListener.class.getMethods()) {
assertNotNull(
AbstractRepositoryListener.class.getDeclaredMethod(method.getName(), method.getParameterTypes()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class DefaultRepositoryCacheTest {

private DefaultRepositoryCache cache = new DefaultRepositoryCache();
private final DefaultRepositoryCache cache = new DefaultRepositoryCache();

private RepositorySystemSession session = new DefaultRepositorySystemSession();
private final RepositorySystemSession session = new DefaultRepositorySystemSession();

private Object get(Object key) {
return cache.get(session, key);
Expand All @@ -39,18 +40,18 @@ private void put(Object key, Object value) {
cache.put(session, key, value);
}

@Test(expected = RuntimeException.class)
public void testGet_NullKey() {
get(null);
@Test
void testGet_NullKey() {
assertThrows(RuntimeException.class, () -> get(null));
}

@Test(expected = RuntimeException.class)
public void testPut_NullKey() {
put(null, "data");
@Test
void testPut_NullKey() {
assertThrows(RuntimeException.class, () -> put(null, "data"));
}

@Test
public void testGetPut() {
void testGetPut() {
Object key = "key";
assertNull(get(key));
put(key, "value");
Expand All @@ -61,7 +62,8 @@ public void testGetPut() {
assertNull(get(key));
}

@Test(timeout = 10000L)
@Test
@Timeout(value = 10L)
public void testConcurrency() throws Exception {
final AtomicReference<Throwable> error = new AtomicReference<>();
Thread[] threads = new Thread[20];
Expand All @@ -88,6 +90,6 @@ public void run() {
for (Thread thread : threads) {
thread.join();
}
assertNull(String.valueOf(error.get()), error.get());
assertNull(error.get(), String.valueOf(error.get()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,17 @@
import org.eclipse.aether.repository.AuthenticationDigest;
import org.eclipse.aether.repository.Proxy;
import org.eclipse.aether.repository.RemoteRepository;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;

/**
*/
public class DefaultRepositorySystemSessionTest {

@Test
public void testDefaultProxySelectorUsesExistingProxy() {
void testDefaultProxySelectorUsesExistingProxy() {
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();

RemoteRepository repo = new RemoteRepository.Builder("id", "default", "void").build();
Expand All @@ -51,7 +48,7 @@ public void testDefaultProxySelectorUsesExistingProxy() {
}

@Test
public void testDefaultAuthenticationSelectorUsesExistingAuth() {
void testDefaultAuthenticationSelectorUsesExistingAuth() {
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();

RemoteRepository repo = new RemoteRepository.Builder("id", "default", "void").build();
Expand All @@ -67,7 +64,7 @@ public void digest(AuthenticationDigest digest) {}
}

@Test
public void testCopyConstructorCopiesPropertiesDeep() {
void testCopyConstructorCopiesPropertiesDeep() {
DefaultRepositorySystemSession session1 = new DefaultRepositorySystemSession();
session1.setUserProperties(System.getProperties());
session1.setSystemProperties(System.getProperties());
Expand All @@ -84,7 +81,7 @@ public void testCopyConstructorCopiesPropertiesDeep() {
}

@Test
public void testReadOnlyProperties() {
void testReadOnlyProperties() {
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();

try {
Expand All @@ -110,7 +107,7 @@ public void testReadOnlyProperties() {
}

@Test
public void testCopyRepositorySystemSession() throws Exception {
void testCopyRepositorySystemSession() throws Exception {
RepositorySystemSession session = Mockito.mock(RepositorySystemSession.class, Mockito.RETURNS_MOCKS);

RepositorySystemSession newSession = new DefaultRepositorySystemSession(session);
Expand All @@ -119,7 +116,7 @@ public void testCopyRepositorySystemSession() throws Exception {

for (Method method : methods) {
if (method.getParameterCount() == 0) {
assertEquals(method.getName(), method.invoke(session) == null, method.invoke(newSession) == null);
assertEquals(method.invoke(session) == null, method.invoke(newSession) == null, method.getName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class DefaultSessionDataTest {

private DefaultSessionData data = new DefaultSessionData();
private final DefaultSessionData data = new DefaultSessionData();

private Object get(Object key) {
return data.get(key);
Expand All @@ -46,18 +47,18 @@ private Object computeIfAbsent(Object key, Supplier<Object> supplier) {
return data.computeIfAbsent(key, supplier);
}

@Test(expected = RuntimeException.class)
public void testGet_NullKey() {
get(null);
@Test
void testGet_NullKey() {
assertThrows(RuntimeException.class, () -> get(null));
}

@Test(expected = RuntimeException.class)
public void testSet_NullKey() {
set(null, "data");
@Test
void testSet_NullKey() {
assertThrows(RuntimeException.class, () -> set(null, "data"));
}

@Test
public void testGetSet() {
void testGetSet() {
Object key = "key";
assertNull(get(key));
set(key, "value");
Expand All @@ -69,7 +70,7 @@ public void testGetSet() {
}

@Test
public void testGetSafeSet() {
void testGetSafeSet() {
Object key = "key";
assertNull(get(key));
assertFalse(set(key, "wrong", "value"));
Expand All @@ -91,15 +92,16 @@ public void testGetSafeSet() {
}

@Test
public void testComputeIfAbsent() {
void testComputeIfAbsent() {
Object key = "key";
assertNull(get(key));
assertEquals("value", computeIfAbsent(key, () -> "value"));
assertEquals("value", computeIfAbsent(key, () -> "changed"));
}

@Test(timeout = 10000L)
public void testConcurrency() throws Exception {
@Test
@Timeout(10L)
public void testConcurrency() throws InterruptedException {
final AtomicReference<Throwable> error = new AtomicReference<>();
Thread[] threads = new Thread[20];
for (int i = 0; i < threads.length; i++) {
Expand All @@ -125,6 +127,6 @@ public void run() {
for (Thread thread : threads) {
thread.join();
}
assertNull(String.valueOf(error.get()), error.get());
assertNull(error.get(), String.valueOf(error.get()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import org.eclipse.aether.transfer.NoRepositoryLayoutException;
import org.eclipse.aether.transfer.NoTransporterException;
import org.eclipse.aether.transfer.RepositoryOfflineException;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class RepositoryExceptionTest {

Expand Down Expand Up @@ -96,33 +96,33 @@ private RemoteRepository newRepo() {
}

@Test
public void testArtifactDescriptorException_Serializable() {
void testArtifactDescriptorException_Serializable() {
ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();
request.setArtifact(newArtifact()).addRepository(newRepo()).setTrace(newTrace());
ArtifactDescriptorResult result = new ArtifactDescriptorResult(request);
assertSerializable(new ArtifactDescriptorException(result));
}

@Test
public void testArtifactResolutionException_Serializable() {
void testArtifactResolutionException_Serializable() {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(newArtifact()).addRepository(newRepo()).setTrace(newTrace());
ArtifactResult result = new ArtifactResult(request);
assertSerializable(new ArtifactResolutionException(Arrays.asList(result)));
}

@Test
public void testArtifactTransferException_Serializable() {
void testArtifactTransferException_Serializable() {
assertSerializable(new ArtifactTransferException(newArtifact(), newRepo(), "error"));
}

@Test
public void testArtifactNotFoundException_Serializable() {
void testArtifactNotFoundException_Serializable() {
assertSerializable(new ArtifactNotFoundException(newArtifact(), newRepo(), "error"));
}

@Test
public void testDependencyCollectionException_Serializable() {
void testDependencyCollectionException_Serializable() {
CollectRequest request = new CollectRequest();
request.addDependency(new Dependency(newArtifact(), "compile"));
request.addRepository(newRepo());
Expand All @@ -132,7 +132,7 @@ public void testDependencyCollectionException_Serializable() {
}

@Test
public void testDependencyResolutionException_Serializable() {
void testDependencyResolutionException_Serializable() {
CollectRequest request = new CollectRequest();
request.addDependency(new Dependency(newArtifact(), "compile"));
request.addRepository(newRepo());
Expand All @@ -145,56 +145,56 @@ public void testDependencyResolutionException_Serializable() {
}

@Test
public void testMetadataTransferException_Serializable() {
void testMetadataTransferException_Serializable() {
assertSerializable(new MetadataTransferException(newMetadata(), newRepo(), "error"));
}

@Test
public void testMetadataNotFoundException_Serializable() {
void testMetadataNotFoundException_Serializable() {
assertSerializable(new MetadataNotFoundException(newMetadata(), newRepo(), "error"));
}

@Test
public void testNoLocalRepositoryManagerException_Serializable() {
void testNoLocalRepositoryManagerException_Serializable() {
assertSerializable(new NoLocalRepositoryManagerException(new LocalRepository("/tmp")));
}

@Test
public void testNoRepositoryConnectorException_Serializable() {
void testNoRepositoryConnectorException_Serializable() {
assertSerializable(new NoRepositoryConnectorException(newRepo()));
}

@Test
public void testNoRepositoryLayoutException_Serializable() {
void testNoRepositoryLayoutException_Serializable() {
assertSerializable(new NoRepositoryLayoutException(newRepo()));
}

@Test
public void testNoTransporterException_Serializable() {
void testNoTransporterException_Serializable() {
assertSerializable(new NoTransporterException(newRepo()));
}

@Test
public void testRepositoryOfflineException_Serializable() {
void testRepositoryOfflineException_Serializable() {
assertSerializable(new RepositoryOfflineException(newRepo()));
}

@Test
public void testUnsolvableVersionConflictException_Serializable() {
void testUnsolvableVersionConflictException_Serializable() {
DependencyNode node = new DefaultDependencyNode(new Dependency(newArtifact(), "test"));
assertSerializable(new UnsolvableVersionConflictException(Collections.singleton(Arrays.asList(node))));
}

@Test
public void testVersionResolutionException_Serializable() {
void testVersionResolutionException_Serializable() {
VersionRequest request = new VersionRequest();
request.setArtifact(newArtifact()).addRepository(newRepo()).setTrace(newTrace());
VersionResult result = new VersionResult(request);
assertSerializable(new VersionResolutionException(result));
}

@Test
public void testVersionRangeResolutionException_Serializable() {
void testVersionRangeResolutionException_Serializable() {
VersionRangeRequest request = new VersionRangeRequest();
request.setArtifact(newArtifact()).addRepository(newRepo()).setTrace(newTrace());
VersionRangeResult result = new VersionRangeResult(request);
Expand Down
Loading

0 comments on commit e3fc1dc

Please sign in to comment.