Skip to content

Commit

Permalink
[MRESOLVER-418] Migrate to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Oct 19, 2023
1 parent b119627 commit 0c2ce7d
Show file tree
Hide file tree
Showing 143 changed files with 642 additions and 777 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,9 +20,9 @@

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 {

Expand All @@ -31,7 +31,7 @@ public 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,9 +20,9 @@

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.*;

/**
*/
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,14 +40,14 @@ private void put(Object key, Object value) {
cache.put(session, key, value);
}

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

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

@Test
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,13 +26,10 @@
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.*;

/**
*/
Expand Down Expand Up @@ -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,14 +47,14 @@ private Object computeIfAbsent(Object key, Supplier<Object> supplier) {
return data.computeIfAbsent(key, supplier);
}

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

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

@Test
Expand Down Expand Up @@ -98,8 +99,9 @@ public void testComputeIfAbsent() {
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.eclipse.aether;

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

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

/**
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.HashMap;
import java.util.Map;

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

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

/**
*/
Expand Down Expand Up @@ -84,14 +84,14 @@ public void testDefaultArtifactString() {
assertEquals("cls", a.getClassifier());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testDefaultArtifactContainsGroupAndArtifactOnly() {
new DefaultArtifact("gid:aid");
assertThrows(IllegalArgumentException.class, () -> new DefaultArtifact("gid:aid"));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testDefaultArtifactContainsGroupOnly() {
new DefaultArtifact("gid");
assertThrows(IllegalArgumentException.class, () -> new DefaultArtifact("gid"));
}

@Test
Expand Down Expand Up @@ -167,15 +167,15 @@ public void testPropertiesCopied() {
@Test
public void testIsSnapshot() {
Artifact a = new DefaultArtifact("gid:aid:ext:cls:1.0");
assertFalse(a.getVersion(), a.isSnapshot());
assertFalse(a.isSnapshot(), a.getVersion());

a = new DefaultArtifact("gid:aid:ext:cls:1.0-SNAPSHOT");
assertTrue(a.getVersion(), a.isSnapshot());
assertTrue(a.isSnapshot(), a.getVersion());

a = new DefaultArtifact("gid:aid:ext:cls:1.0-20101116.150650-3");
assertTrue(a.getVersion(), a.isSnapshot());
assertTrue(a.isSnapshot(), a.getVersion());

a = new DefaultArtifact("gid:aid:ext:cls:1.0-20101116x150650-3");
assertFalse(a.getVersion(), a.isSnapshot());
assertFalse(a.isSnapshot(), a.getVersion());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import java.util.Collections;

import org.eclipse.aether.artifact.DefaultArtifact;
import org.junit.Test;
import org.junit.jupiter.api.Test;

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

/**
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.Test;
import org.junit.jupiter.api.Test;

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

public class AuthenticationContextTest {

Expand All @@ -50,7 +50,7 @@ public void fill(AuthenticationContext context, String key, Map<String, String>
assertNotNull(context);
assertNotNull(context.getSession());
assertNotNull(context.getRepository());
assertNull("fill() should only be called once", context.get("key"));
assertNull(context.get("key"), "fill() should only be called once");
context.put("key", "value");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.Test;
import org.junit.jupiter.api.Test;

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

public class AuthenticationDigestTest {

Expand Down Expand Up @@ -58,7 +58,7 @@ public void digest(AuthenticationDigest digest) {
assertSame(session, digest.getSession());
assertNotNull(digest.getRepository());
assertNull(digest.getProxy());
assertNull("digest() should only be called once", repos[0]);
assertNull(repos[0], "digest() should only be called once");
repos[0] = digest.getRepository();

digest.update((byte[]) null);
Expand Down Expand Up @@ -99,7 +99,7 @@ public void digest(AuthenticationDigest digest) {
assertSame(session, digest.getSession());
assertNotNull(digest.getRepository());
assertNotNull(digest.getProxy());
assertNull("digest() should only be called once", proxies[0]);
assertNull(proxies[0], "digest() should only be called once");
proxies[0] = digest.getProxy();

digest.update((byte[]) null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
import java.util.Map;

import org.eclipse.aether.repository.RemoteRepository.Builder;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

public class RemoteRepositoryBuilderTest {

private RemoteRepository prototype;

@Before
@BeforeEach
public void init() {
prototype = new Builder("id", "type", "file:void").build();
}
Expand All @@ -44,9 +44,9 @@ public void testReusePrototype() {
assertSame(prototype, builder.build());
}

@Test(expected = NullPointerException.class)
@Test
public void testPrototypeMandatory() {
new Builder(null);
assertThrows(NullPointerException.class, () -> new Builder(null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.eclipse.aether.repository;

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

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

/**
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

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.*;

/**
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.Test;
import org.junit.jupiter.api.Test;

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

/**
*/
Expand Down
Loading

0 comments on commit 0c2ce7d

Please sign in to comment.