Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Oct 20, 2023
1 parent 898f0ef commit ef599e6
Show file tree
Hide file tree
Showing 27 changed files with 270 additions and 282 deletions.
5 changes: 5 additions & 0 deletions maven-resolver-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@
import org.eclipse.aether.transfer.ArtifactNotFoundException;
import org.eclipse.aether.transfer.ArtifactTransferException;
import org.eclipse.aether.util.repository.SimpleResolutionErrorPolicy;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

/**
*/
Expand All @@ -92,7 +92,7 @@ public class DefaultArtifactResolverTest {

private DefaultRemoteRepositoryFilterManager remoteRepositoryFilterManager;

@Before
@BeforeEach
public void setup() {
remoteRepositoryFilterSources = new HashMap<>();
remoteRepositoryFilterManager = new DefaultRemoteRepositoryFilterManager(remoteRepositoryFilterSources);
Expand Down Expand Up @@ -125,7 +125,7 @@ private DefaultArtifactResolver setupArtifactResolver(
remoteRepositoryFilterManager);
}

@After
@AfterEach
public void teardown() throws Exception {
if (session.getLocalRepository() != null) {
TestFileUtils.deleteFile(session.getLocalRepository().getBasedir());
Expand Down Expand Up @@ -400,8 +400,8 @@ public void get(
connector.assertSeenExpected();
for (ArtifactResult result : e.getResults()) {
Throwable t = result.getExceptions().get(0);
assertTrue(t.toString(), t instanceof ArtifactNotFoundException);
assertTrue(t.toString(), t.getMessage().contains("cached"));
assertTrue(t instanceof ArtifactNotFoundException, t.toString());
assertTrue(t.getMessage().contains("cached"), t.toString());
}
}
}
Expand Down Expand Up @@ -472,7 +472,7 @@ public File findArtifact(Artifact artifact) {

ArtifactResult result = resolver.resolveArtifact(session, request);

assertTrue("exception on resolveArtifact", result.getExceptions().isEmpty());
assertTrue(result.getExceptions().isEmpty(), "exception on resolveArtifact");

Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
Expand Down Expand Up @@ -550,7 +550,7 @@ public void testRepositoryEventsSuccessfulRemote() throws ArtifactResolutionExce
resolver.resolveArtifact(session, request);

List<RepositoryEvent> events = listener.getEvents();
assertEquals(events.toString(), 4, events.size());
assertEquals(4, events.size(), events.toString());
RepositoryEvent event = events.get(0);
assertEquals(EventType.ARTIFACT_RESOLVING, event.getType());
assertNull(event.getException());
Expand Down Expand Up @@ -602,7 +602,7 @@ public void get(
}

List<RepositoryEvent> events = listener.getEvents();
assertEquals(events.toString(), 4, events.size());
assertEquals(4, events.size(), events.toString());

RepositoryEvent event = events.get(0);
assertEquals(artifact, event.getArtifact());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@
import org.eclipse.aether.repository.RepositoryPolicy;
import org.eclipse.aether.spi.connector.checksum.ChecksumPolicy;
import org.eclipse.aether.transfer.TransferResource;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.*;

public class DefaultChecksumPolicyProviderTest {

Expand All @@ -47,15 +42,15 @@ public class DefaultChecksumPolicyProviderTest {

private TransferResource resource;

@Before
@BeforeEach
public void setup() {
session = TestUtils.newSession();
provider = new DefaultChecksumPolicyProvider();
repository = new RemoteRepository.Builder("test", "default", "file:/void").build();
resource = new TransferResource(repository.getId(), repository.getUrl(), "file.txt", null, null);
}

@After
@AfterEach
public void teardown() {
provider = null;
session = null;
Expand Down Expand Up @@ -86,11 +81,11 @@ public void testNewChecksumPolicy_Ignore() {
assertNull(policy);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testNewChecksumPolicy_Unknown() {
ChecksumPolicy policy = provider.newChecksumPolicy(session, repository, resource, CHECKSUM_POLICY_UNKNOWN);
assertNotNull(policy);
assertEquals(WarnChecksumPolicy.class, policy.getClass());
assertThrows(
IllegalArgumentException.class,
() -> provider.newChecksumPolicy(session, repository, resource, CHECKSUM_POLICY_UNKNOWN));
}

@Test
Expand All @@ -101,7 +96,7 @@ public void testGetEffectiveChecksumPolicy_EqualPolicies() {
RepositoryPolicy.CHECKSUM_POLICY_IGNORE
};
for (String policy : policies) {
assertEquals(policy, policy, provider.getEffectiveChecksumPolicy(session, policy, policy));
assertEquals(policy, provider.getEffectiveChecksumPolicy(session, policy, policy), policy);
}
}

Expand All @@ -114,13 +109,13 @@ public void testGetEffectiveChecksumPolicy_DifferentPolicies() {
};
for (String[] testCase : testCases) {
assertEquals(
testCase[0] + " vs " + testCase[1],
testCase[0],
provider.getEffectiveChecksumPolicy(session, testCase[0], testCase[1]));
provider.getEffectiveChecksumPolicy(session, testCase[0], testCase[1]),
testCase[0] + " vs " + testCase[1]);
assertEquals(
testCase[0] + " vs " + testCase[1],
testCase[0],
provider.getEffectiveChecksumPolicy(session, testCase[1], testCase[0]));
provider.getEffectiveChecksumPolicy(session, testCase[1], testCase[0]),
testCase[0] + " vs " + testCase[1]);
}
}

Expand All @@ -135,11 +130,11 @@ public void testGetEffectiveChecksumPolicy_UnknownPolicies() {
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class,
() -> provider.getEffectiveChecksumPolicy(session, CHECKSUM_POLICY_UNKNOWN, testCase[1]));
assertThat(e.getMessage(), is("Unsupported policy: unknown"));
assertEquals(e.getMessage(), "Unsupported policy: unknown");
e = assertThrows(
IllegalArgumentException.class,
() -> provider.getEffectiveChecksumPolicy(session, testCase[1], CHECKSUM_POLICY_UNKNOWN));
assertThat(e.getMessage(), is("Unsupported policy: unknown"));
assertEquals(e.getMessage(), "Unsupported policy: unknown");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,12 @@
import org.eclipse.aether.spi.connector.MetadataUpload;
import org.eclipse.aether.spi.connector.RepositoryConnector;
import org.eclipse.aether.transfer.MetadataNotFoundException;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static java.util.Objects.requireNonNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;

public class DefaultDeployerTest {

Expand All @@ -76,7 +73,7 @@ public class DefaultDeployerTest {

private RecordingRepositoryListener listener;

@Before
@BeforeEach
public void setup() throws IOException {
artifact = new DefaultArtifact("gid", "aid", "jar", "ver");
artifact = artifact.setFile(TestFileUtils.createTempFile("artifact"));
Expand Down Expand Up @@ -105,7 +102,7 @@ public void setup() throws IOException {
session.setRepositoryListener(listener);
}

@After
@AfterEach
public void teardown() throws Exception {
if (session.getLocalRepository() != null) {
TestFileUtils.deleteFile(session.getLocalRepository().getBasedir());
Expand All @@ -131,16 +128,16 @@ public void testSuccessfulDeploy() throws DeploymentException {
connector.assertSeenExpected();
}

@Test(expected = DeploymentException.class)
public void testNullArtifactFile() throws DeploymentException {
@Test
public void testNullArtifactFile() {
request.addArtifact(artifact.setFile(null));
deployer.deploy(session, request);
assertThrows(DeploymentException.class, () -> deployer.deploy(session, request));
}

@Test(expected = DeploymentException.class)
public void testNullMetadataFile() throws DeploymentException {
request.addArtifact(artifact.setFile(null));
deployer.deploy(session, request);
@Test
public void testNullMetadataFile() {
request.addMetadata(metadata.setFile(null));
assertThrows(DeploymentException.class, () -> deployer.deploy(session, request));
}

@Test
Expand Down Expand Up @@ -333,6 +330,6 @@ public void close() {}

props = new Properties();
TestFileUtils.readProps(metadataFile, props);
assertNull(props.toString(), props.get("old"));
assertNull(props.get("old"), props.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void testMetadataDestinationEqualsSource() throws IOException {
TestFileUtils.writeString(file, "test");

request.addMetadata(metadata);
assertThrows( InstallationException.class, () -> installer.install(session, request));
assertThrows(InstallationException.class, () -> installer.install(session, request));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ private RemoteRepository.Builder newRepo(String id, String url, boolean enabled,
}

private void assertEqual(RemoteRepository expected, RemoteRepository actual) {
assertEquals("id", expected.getId(), actual.getId());
assertEquals("url", expected.getUrl(), actual.getUrl());
assertEquals("type", expected.getContentType(), actual.getContentType());
assertEquals(expected.getId(), actual.getId(), "id");
assertEquals(expected.getUrl(), actual.getUrl(), "url");
assertEquals(expected.getContentType(), actual.getContentType(), "type");
assertEqual(expected.getPolicy(false), actual.getPolicy(false));
assertEqual(expected.getPolicy(true), actual.getPolicy(true));
}

private void assertEqual(RepositoryPolicy expected, RepositoryPolicy actual) {
assertEquals(expected.isEnabled(), actual.isEnabled(), "enabled");
assertEquals("checksums", expected.getChecksumPolicy(), actual.getChecksumPolicy());
assertEquals("artifactUpdates", expected.getArtifactUpdatePolicy(), actual.getArtifactUpdatePolicy());
assertEquals("metadataUpdates", expected.getMetadataUpdatePolicy(), actual.getMetadataUpdatePolicy());
assertEquals(expected.getChecksumPolicy(), actual.getChecksumPolicy(), "checksums");
assertEquals(expected.getArtifactUpdatePolicy(), actual.getArtifactUpdatePolicy(), "artifactUpdates");
assertEquals(expected.getMetadataUpdatePolicy(), actual.getMetadataUpdatePolicy(), "metadataUpdates");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public void testDispatchHandlesAllEventTypes() {
assertNotNull(handler.methodName, "not handled: " + type);

assertEquals(
"badly handled: " + type,
type.name().replace("_", "").toLowerCase(Locale.ENGLISH),
handler.methodName.toLowerCase(Locale.ENGLISH));
handler.methodName.toLowerCase(Locale.ENGLISH),
"badly handled: " + type);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ private UpdateCheck<Artifact, ArtifactTransferException> newArtifactCheck() {
return check;
}

@Test(expected = Exception.class)
@Test
public void testCheckMetadataFailOnNoFile() {
UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
check.setItem(metadata.setFile(null));
check.setFile(null);

manager.checkMetadata(session, check);
assertThrows(NullPointerException.class, () -> manager.checkMetadata(session, check));
}

@Test
Expand Down Expand Up @@ -435,14 +435,13 @@ public void testCheckMetadataNotWhenUpdatePolicyIsNeverAndTimestampIsUnavailable
assertFalse(check.isRequired());
}

@Test(expected = NullPointerException.class)
@Test
public void testCheckArtifactFailOnNoFile() {
UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
check.setItem(artifact.setFile(null));
check.setFile(null);

manager.checkArtifact(session, check);
assertNotNull(check.getException());
assertThrows(NullPointerException.class, () -> manager.checkArtifact(session, check));
}

@Test
Expand Down
Loading

0 comments on commit ef599e6

Please sign in to comment.