Skip to content

Commit

Permalink
Update UTs regarding deprecations (#387)
Browse files Browse the repository at this point in the history
With latest changes there were some deprecations, most notably the default ctor of DRSS. Due that the build started emitting quite some warning messages during build.

This is now lowered to 2 warnings for whole build. There is no issue for this, as these changes are all happening in UTs.
  • Loading branch information
cstamas committed Dec 5, 2023
1 parent 9b87550 commit 45c5bdf
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
import org.junit.jupiter.api.Timeout;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;

public class DefaultRepositoryCacheTest {

private final DefaultRepositoryCache cache = new DefaultRepositoryCache();

private final RepositorySystemSession session = new DefaultRepositorySystemSession();
private final RepositorySystemSession session = mock(RepositorySystemSession.class);

private Object get(Object key) {
return cache.get(session, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@
*/
public class DefaultRepositorySystemSessionTest {

private DefaultRepositorySystemSession newSession() {
return new DefaultRepositorySystemSession();
}

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

RemoteRepository repo = new RemoteRepository.Builder("id", "default", "void").build();
assertSame(null, session.getProxySelector().getProxy(repo));
Expand All @@ -49,7 +53,7 @@ void testDefaultProxySelectorUsesExistingProxy() {

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

RemoteRepository repo = new RemoteRepository.Builder("id", "default", "void").build();
assertSame(null, session.getAuthenticationSelector().getAuthentication(repo));
Expand All @@ -65,7 +69,7 @@ public void digest(AuthenticationDigest digest) {}

@Test
void testCopyConstructorCopiesPropertiesDeep() {
DefaultRepositorySystemSession session1 = new DefaultRepositorySystemSession();
DefaultRepositorySystemSession session1 = newSession();
session1.setUserProperties(System.getProperties());
session1.setSystemProperties(System.getProperties());
session1.setConfigProperties(System.getProperties());
Expand All @@ -82,7 +86,7 @@ void testCopyConstructorCopiesPropertiesDeep() {

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

try {
session.getUserProperties().put("key", "test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import java.io.File;
import java.util.Map;

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

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;

public class AuthenticationContextTest {

private RepositorySystemSession newSession() {
return new DefaultRepositorySystemSession();
return mock(RepositorySystemSession.class);
}

private RemoteRepository newRepo(Authentication auth, Proxy proxy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

import java.util.Map;

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

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;

public class AuthenticationDigestTest {

private RepositorySystemSession newSession() {
return new DefaultRepositorySystemSession();
return mock(RepositorySystemSession.class);
}

private RemoteRepository newRepo(Authentication auth, Proxy proxy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@

import java.nio.ByteBuffer;

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

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;

/**
*/
public class TransferEventTest {

private static TransferResource res = new TransferResource("none", "file://nil", "void", null, null);
private static final TransferResource res = new TransferResource("none", "file://nil", "void", null, null);

private static RepositorySystemSession session = new DefaultRepositorySystemSession();
private static final RepositorySystemSession session = mock(RepositorySystemSession.class);

@Test
void testByteArrayConversion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.internal.test.util.TestUtils;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.transfer.RepositoryOfflineException;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -32,7 +33,7 @@ public class DefaultOfflineControllerTest {
private DefaultOfflineController controller;

private RepositorySystemSession newSession(boolean offline, String protocols, String hosts) {
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
DefaultRepositorySystemSession session = TestUtils.newSession();
session.setOffline(offline);
session.setConfigProperty(DefaultOfflineController.CONFIG_PROP_OFFLINE_PROTOCOLS, protocols);
session.setConfigProperty(DefaultOfflineController.CONFIG_PROP_OFFLINE_HOSTS, hosts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import java.util.Collections;

import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.internal.test.util.TestUtils;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
import org.eclipse.aether.resolution.ArtifactDescriptorResult;
Expand All @@ -34,7 +34,7 @@
public class DataPoolTest {

private DataPool newDataPool() {
return new DataPool(new DefaultRepositorySystemSession());
return new DataPool(TestUtils.newSession());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.Iterator;
import java.util.NoSuchElementException;

import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.internal.test.util.TestUtils;
import org.eclipse.aether.internal.test.util.TestVersion;
import org.eclipse.aether.resolution.VersionRangeRequest;
import org.eclipse.aether.resolution.VersionRangeResult;
Expand All @@ -40,7 +40,7 @@ public class DefaultVersionFilterContextTest {

@Test
void iteratorOneItem() {
DefaultVersionFilterContext context = new DefaultVersionFilterContext(new DefaultRepositorySystemSession());
DefaultVersionFilterContext context = new DefaultVersionFilterContext(TestUtils.newSession());
VersionRangeResult result = new VersionRangeResult(new VersionRangeRequest());
result.addVersion(new TestVersion("1.0"));
context.set(FOO_DEPENDENCY, result);
Expand All @@ -52,7 +52,7 @@ void iteratorOneItem() {

@Test
void getCountOneItem() {
DefaultVersionFilterContext context = new DefaultVersionFilterContext(new DefaultRepositorySystemSession());
DefaultVersionFilterContext context = new DefaultVersionFilterContext(TestUtils.newSession());
VersionRangeResult result = new VersionRangeResult(new VersionRangeRequest());
result.addVersion(new TestVersion("1.0"));
context.set(FOO_DEPENDENCY, result);
Expand All @@ -62,7 +62,7 @@ void getCountOneItem() {

@Test
void getOneItem() {
DefaultVersionFilterContext context = new DefaultVersionFilterContext(new DefaultRepositorySystemSession());
DefaultVersionFilterContext context = new DefaultVersionFilterContext(TestUtils.newSession());
VersionRangeResult result = new VersionRangeResult(new VersionRangeRequest());
result.addVersion(new TestVersion("1.0"));
context.set(FOO_DEPENDENCY, result);
Expand All @@ -72,7 +72,7 @@ void getOneItem() {

@Test
void iteratorDelete() {
DefaultVersionFilterContext context = new DefaultVersionFilterContext(new DefaultRepositorySystemSession());
DefaultVersionFilterContext context = new DefaultVersionFilterContext(TestUtils.newSession());
VersionRangeResult result = new VersionRangeResult(new VersionRangeRequest());
result.addVersion(new TestVersion("1.0"));
context.set(FOO_DEPENDENCY, result);
Expand All @@ -86,7 +86,7 @@ void iteratorDelete() {

@Test
void nextBeyondEnd() {
DefaultVersionFilterContext context = new DefaultVersionFilterContext(new DefaultRepositorySystemSession());
DefaultVersionFilterContext context = new DefaultVersionFilterContext(TestUtils.newSession());
VersionRangeResult result = new VersionRangeResult(new VersionRangeRequest());
result.addVersion(new TestVersion("1.0"));
context.set(FOO_DEPENDENCY, result);
Expand All @@ -98,7 +98,7 @@ void nextBeyondEnd() {

@Test
void removeOneOfOne() {
DefaultVersionFilterContext context = new DefaultVersionFilterContext(new DefaultRepositorySystemSession());
DefaultVersionFilterContext context = new DefaultVersionFilterContext(TestUtils.newSession());
VersionRangeResult result = new VersionRangeResult(new VersionRangeRequest());
result.addVersion(new TestVersion("1.0"));
context.set(FOO_DEPENDENCY, result);
Expand All @@ -112,7 +112,7 @@ void removeOneOfOne() {

@Test
void removeOneOfTwo() {
DefaultVersionFilterContext context = new DefaultVersionFilterContext(new DefaultRepositorySystemSession());
DefaultVersionFilterContext context = new DefaultVersionFilterContext(TestUtils.newSession());
VersionRangeResult result = new VersionRangeResult(new VersionRangeRequest());
result.addVersion(new TestVersion("1.0"));
result.addVersion(new TestVersion("2.0"));
Expand All @@ -127,7 +127,7 @@ void removeOneOfTwo() {

@Test
void removeOneOfThree() {
DefaultVersionFilterContext context = new DefaultVersionFilterContext(new DefaultRepositorySystemSession());
DefaultVersionFilterContext context = new DefaultVersionFilterContext(TestUtils.newSession());
VersionRangeResult result = new VersionRangeResult(new VersionRangeRequest());
result.addVersion(new TestVersion("1.0"));
result.addVersion(new TestVersion("2.0"));
Expand All @@ -143,7 +143,7 @@ void removeOneOfThree() {

@Test
void setTwice() {
DefaultVersionFilterContext context = new DefaultVersionFilterContext(new DefaultRepositorySystemSession());
DefaultVersionFilterContext context = new DefaultVersionFilterContext(TestUtils.newSession());
VersionRangeResult fooResult = new VersionRangeResult(new VersionRangeRequest());
fooResult.addVersion(new TestVersion("1.0"));
context.set(FOO_DEPENDENCY, fooResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private boolean isMatch(DependencyNode node, String id) {
void setUp() {
transformer = newTransformer();
parser = newParser();
session = new DefaultRepositorySystemSession();
session = TestUtils.newSession();
}

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

import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.internal.test.util.TestUtils;
import org.eclipse.aether.repository.Authentication;
import org.eclipse.aether.repository.AuthenticationContext;
import org.eclipse.aether.repository.AuthenticationDigest;
Expand All @@ -33,7 +33,7 @@ public class ComponentAuthenticationTest {
private static class Component {}

private RepositorySystemSession newSession() {
return new DefaultRepositorySystemSession();
return TestUtils.newSession();
}

private RemoteRepository newRepo(Authentication auth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.test.util.TestUtils;
import org.eclipse.aether.repository.Authentication;
import org.eclipse.aether.repository.AuthenticationContext;
import org.eclipse.aether.repository.Proxy;
Expand Down Expand Up @@ -111,13 +112,13 @@ public List<java.net.Proxy> select(URI uri) {
void testGetProxy_HttpProxy() throws Exception {
final RemoteRepository repo =
new RemoteRepository.Builder("test", "default", "http://repo.eclipse.org/").build();
final URL url = new URL(repo.getUrl());
final URL url = new URI(repo.getUrl()).toURL();
final InetSocketAddress addr = InetSocketAddress.createUnresolved("proxy", 8080);
java.net.ProxySelector.setDefault(new AbstractProxySelector() {
@Override
public List<java.net.Proxy> select(URI uri) {
if (repo.getHost().equalsIgnoreCase(uri.getHost())) {
return Arrays.asList(new java.net.Proxy(java.net.Proxy.Type.HTTP, addr));
return Collections.singletonList(new java.net.Proxy(java.net.Proxy.Type.HTTP, addr));
}
return Collections.emptyList();
}
Expand All @@ -128,7 +129,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
if (Authenticator.RequestorType.PROXY.equals(getRequestorType())
&& addr.getHostName().equals(getRequestingHost())
&& addr.getPort() == getRequestingPort()
&& url.equals(getRequestingURL())) {
&& Objects.equals(url, getRequestingURL())) {
return new PasswordAuthentication("proxyuser", "proxypass".toCharArray());
}
return super.getPasswordAuthentication();
Expand All @@ -145,8 +146,9 @@ protected PasswordAuthentication getPasswordAuthentication() {
new RemoteRepository.Builder(repo).setProxy(proxy).build();
Authentication auth = proxy.getAuthentication();
assertNotNull(auth);
AuthenticationContext authCtx = AuthenticationContext.forProxy(new DefaultRepositorySystemSession(), repo2);
assertEquals("proxyuser", authCtx.get(AuthenticationContext.USERNAME));
assertEquals("proxypass", authCtx.get(AuthenticationContext.PASSWORD));
try (AuthenticationContext authCtx = AuthenticationContext.forProxy(TestUtils.newSession(), repo2)) {
assertEquals("proxyuser", authCtx.get(AuthenticationContext.USERNAME));
assertEquals("proxypass", authCtx.get(AuthenticationContext.PASSWORD));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package org.eclipse.aether.util.repository;

import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.internal.test.util.TestUtils;
import org.eclipse.aether.repository.Authentication;
import org.eclipse.aether.repository.AuthenticationContext;
import org.eclipse.aether.repository.AuthenticationDigest;
Expand All @@ -31,7 +31,7 @@
public class SecretAuthenticationTest {

private RepositorySystemSession newSession() {
return new DefaultRepositorySystemSession();
return TestUtils.newSession();
}

private RemoteRepository newRepo(Authentication auth) {
Expand All @@ -58,9 +58,10 @@ void testConstructor_CopyChars() {
@Test
void testFill() {
Authentication auth = new SecretAuthentication("key", "value");
AuthenticationContext context = newContext(auth);
assertNull(context.get("another-key"));
assertEquals("value", context.get("key"));
try (AuthenticationContext context = newContext(auth)) {
assertNull(context.get("another-key"));
assertEquals("value", context.get("key"));
}
}

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

import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.internal.test.util.TestUtils;
import org.eclipse.aether.repository.Authentication;
import org.eclipse.aether.repository.AuthenticationContext;
import org.eclipse.aether.repository.AuthenticationDigest;
Expand All @@ -31,7 +31,7 @@
public class StringAuthenticationTest {

private RepositorySystemSession newSession() {
return new DefaultRepositorySystemSession();
return TestUtils.newSession();
}

private RemoteRepository newRepo(Authentication auth) {
Expand All @@ -51,9 +51,10 @@ private String newDigest(Authentication auth) {
@Test
void testFill() {
Authentication auth = new StringAuthentication("key", "value");
AuthenticationContext context = newContext(auth);
assertNull(context.get("another-key"));
assertEquals("value", context.get("key"));
try (AuthenticationContext context = newContext(auth)) {
assertNull(context.get("another-key"));
assertEquals("value", context.get("key"));
}
}

@Test
Expand Down

0 comments on commit 45c5bdf

Please sign in to comment.