Skip to content

Commit

Permalink
[SHRINKRES-328] Simplifying assertions, adding try-with-resources and…
Browse files Browse the repository at this point in the history
… resolving unused imports in test classes
  • Loading branch information
petrberan committed Dec 1, 2023
1 parent 56db390 commit 7c8217d
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void notEqualsByGroupIdValue() {
final String classifier = "classifier";
final MavenCoordinate coordinate1 = new MavenCoordinateImpl(groupId, artifactId, version, packaging, classifier);
final MavenCoordinate coordinate2 = new MavenCoordinateImpl("wrong", artifactId, version, packaging, classifier);
Assert.assertFalse(coordinate1.equals(coordinate2));
Assert.assertNotEquals(coordinate1, coordinate2);
}

@Test
Expand All @@ -60,7 +60,7 @@ public void notEqualsByArtifactIdValue() {
final String classifier = "classifier";
final MavenCoordinate coordinate1 = new MavenCoordinateImpl(groupId, artifactId, version, packaging, classifier);
final MavenCoordinate coordinate2 = new MavenCoordinateImpl(groupId, "wrong", version, packaging, classifier);
Assert.assertFalse(coordinate1.equals(coordinate2));
Assert.assertNotEquals(coordinate1, coordinate2);
}

@Test
Expand All @@ -85,7 +85,7 @@ public void notEqualsByPackagingValue() {
final MavenCoordinate coordinate1 = new MavenCoordinateImpl(groupId, artifactId, version, packaging, classifier);
final MavenCoordinate coordinate2 = new MavenCoordinateImpl(groupId, artifactId, version, PackagingType.EAR,
classifier);
Assert.assertFalse(coordinate1.equals(coordinate2));
Assert.assertNotEquals(coordinate1, coordinate2);
}

@Test
Expand All @@ -97,7 +97,7 @@ public void notEqualsByClassifierValue() {
final String classifier = "classifier";
final MavenCoordinate coordinate1 = new MavenCoordinateImpl(groupId, artifactId, version, packaging, classifier);
final MavenCoordinate coordinate2 = new MavenCoordinateImpl(groupId, artifactId, version, packaging, "wrong");
Assert.assertFalse(coordinate1.equals(coordinate2));
Assert.assertNotEquals(coordinate1, coordinate2);
}

@Test
Expand All @@ -109,7 +109,7 @@ public void equalHashCodes() {
final String classifier = "classifier";
final MavenCoordinate coordinate1 = new MavenCoordinateImpl(groupId, artifactId, version, packaging, classifier);
final MavenCoordinate coordinate2 = new MavenCoordinateImpl(groupId, artifactId, version, packaging, classifier);
Assert.assertTrue(coordinate1.hashCode() == coordinate2.hashCode());
Assert.assertEquals(coordinate1.hashCode(), coordinate2.hashCode());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public void equalsByValue() {
public void notEqualsByGroupIdValue() {
final MavenDependencyExclusion exclusion1 = new MavenDependencyExclusionImpl("groupId", "artifactId");
final MavenDependencyExclusion exclusion2 = new MavenDependencyExclusionImpl("groupId2", "artifactId");
Assert.assertFalse(exclusion1.equals(exclusion2));
Assert.assertNotEquals(exclusion1, exclusion2);
}

@Test
public void notEqualsByArtifactIdValue() {
final MavenDependencyExclusion exclusion1 = new MavenDependencyExclusionImpl("groupId", "artifactId");
final MavenDependencyExclusion exclusion2 = new MavenDependencyExclusionImpl("groupId", "artifactId2");
Assert.assertFalse(exclusion1.equals(exclusion2));
Assert.assertNotEquals(exclusion1, exclusion2);
}

@Test
Expand All @@ -55,7 +55,7 @@ public void equalHashCodes() {
final String artifactId = "artifactId";
final MavenDependencyExclusion exclusion1 = new MavenDependencyExclusionImpl(groupId, artifactId);
final MavenDependencyExclusion exclusion2 = new MavenDependencyExclusionImpl(groupId, artifactId);
Assert.assertTrue(exclusion1.hashCode() == exclusion2.hashCode());
Assert.assertEquals(exclusion1.hashCode(), exclusion2.hashCode());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ public void mimickMavenDependencies() {
// .importAnyDependencies(new ScopeFilter("compile", "runtime", ""));
}

/**
* Use case 10:
* <p/>
* Import test dependencies and exclude G:A:V
*/
@Test
public void importTestDependenciesWithExtraExclusion() {
// /**
// * Use case 10:
// * <p/>
// * Import test dependencies and exclude G:A:V
// */
// @Test
// public void importTestDependenciesWithExtraExclusion() {

// TODO
// DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("pom.xml")
Expand All @@ -282,15 +282,15 @@ public void importTestDependenciesWithExtraExclusion() {
// DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("pom.xml")
// .importAnyDependencies(new CombinedFilter(new ScopeFilter("test"), new ExclusionFilter("G:A:V")))
// .resolveAsFiles();
}

/**
* Use case 11:
* <p/>
* Import test dependencies and exclude arquillian/shrinkwrap/container (SHRINKRES-30)
*/
@Test
public void importTestDependenciesWithArquillianExclusions() {
// }

// /**
// * Use case 11:
// * <p/>
// * Import test dependencies and exclude arquillian/shrinkwrap/container (SHRINKRES-30)
// */
// @Test
// public void importTestDependenciesWithArquillianExclusions() {
// TODO
// solution 1 = enumerate within previous use case
// solution 2 = write a GroupExclusionFilter, note that MavenDependency has no getter for groupId!
Expand All @@ -301,7 +301,7 @@ public void importTestDependenciesWithArquillianExclusions() {
* we go need to define an easy way for users to write group exclusions such that another level can define SW, SWR, SWD,
* ARQ etc and exclude in one go.
*/
}
// }

/**
* Use case 12:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jboss.shrinkwrap.resolver.impl.maven.embedded.invoker.equipped;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.concurrent.Callable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,10 @@ public void testGAemptyTCV() {
@Test(expected = IllegalArgumentException.class)
public void testGAemptyTemptyCV() {
Artifact artifact = new DefaultArtifact("g:a:::1");
Assert.assertEquals("g", artifact.getGroupId());
Assert.assertEquals("a", artifact.getArtifactId());
Assert.assertEquals("1", artifact.getVersion());
Assert.assertEquals("sources", artifact.getClassifier());
Assert.assertEquals("jar", artifact.getExtension());
}

@Test(expected = CoordinateParseException.class)
public void test2GAemptyTemptyCV() {
MavenCoordinateParser dependency = MavenCoordinateParser.parse("g:a:::1");
Assert.assertEquals("g", dependency.getGroupId());
Assert.assertEquals("a", dependency.getArtifactId());
Assert.assertEquals("1", dependency.getVersion());
Assert.assertEquals("sources", dependency.getClassifier());
Assert.assertEquals("jar", dependency.getPackaging());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void notEqualsByValueExclusions() {
final MavenDependencyExclusion exclusion2 = new MavenDependencyExclusionImpl("wrong", "artifactId2");
final MavenDependency dependency1 = new MavenDependencyImpl(coordinate, scope, optional, exclusion1);
final MavenDependency dependency2 = new MavenDependencyImpl(coordinate, scope, optional, exclusion2);
Assert.assertTrue(dependency1.equals(dependency2));
Assert.assertEquals(dependency1, dependency2);
}

@Test
Expand All @@ -88,7 +88,7 @@ public void notEqualsByValueExclusionsMismatchThis() {
final MavenDependencyExclusion exclusion = new MavenDependencyExclusionImpl("groupId1", "artifactId1");
final MavenDependency dependency1 = new MavenDependencyImpl(coordinate, scope, optional);
final MavenDependency dependency2 = new MavenDependencyImpl(coordinate, scope, optional, exclusion);
Assert.assertTrue(dependency1.equals(dependency2));
Assert.assertEquals(dependency1, dependency2);
}

@Test
Expand All @@ -99,7 +99,7 @@ public void notEqualsByValueExclusionsMismatchThat() {
final MavenDependencyExclusion exclusion = new MavenDependencyExclusionImpl("groupId1", "artifactId1");
final MavenDependency dependency1 = new MavenDependencyImpl(coordinate, scope, optional, exclusion);
final MavenDependency dependency2 = new MavenDependencyImpl(coordinate, scope, optional);
Assert.assertTrue(dependency1.equals(dependency2));
Assert.assertEquals(dependency1, dependency2);
}

@Test
Expand All @@ -110,7 +110,7 @@ public void notEqualsByValueCoordinate() {
final MavenDependency dependency1 = new MavenDependencyImpl(coordinate, scope, optional);
final MavenDependency dependency2 = new MavenDependencyImpl(new MavenCoordinateImpl("g", "a", "v", null, "c"),
scope, optional);
Assert.assertFalse(dependency1.equals(dependency2));
Assert.assertNotEquals(dependency1, dependency2);
}

@Test
Expand All @@ -120,7 +120,7 @@ public void notEqualsByValueScope() {
final boolean optional = true;
final MavenDependency dependency1 = new MavenDependencyImpl(coordinate, scope, optional);
final MavenDependency dependency2 = new MavenDependencyImpl(coordinate, ScopeType.IMPORT, optional);
Assert.assertTrue(dependency1.equals(dependency2));
Assert.assertEquals(dependency1, dependency2);
}

@Test
Expand All @@ -130,7 +130,7 @@ public void notEqualsByValueOptional() {
final boolean optional = true;
final MavenDependency dependency1 = new MavenDependencyImpl(coordinate, scope, optional);
final MavenDependency dependency2 = new MavenDependencyImpl(coordinate, scope, false);
Assert.assertTrue(dependency1.equals(dependency2));
Assert.assertEquals(dependency1, dependency2);
}

@Test
Expand All @@ -142,7 +142,7 @@ public void equalHashCodes() {
final MavenDependencyExclusion exclusion2 = new MavenDependencyExclusionImpl("groupId2", "artifactId2");
final MavenDependency dependency1 = new MavenDependencyImpl(coordinate, scope, optional, exclusion1, exclusion2);
final MavenDependency dependency2 = new MavenDependencyImpl(coordinate, scope, optional, exclusion1, exclusion2);
Assert.assertTrue(dependency1.hashCode() == dependency2.hashCode());
Assert.assertEquals(dependency1.hashCode(), dependency2.hashCode());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ public void packageDirectoriesWithClasses() throws IOException {
mockedArtResult.setArtifact(testPomArtifactMock);

MavenResolvedArtifact mavenResolvedArtifact = MavenResolvedArtifactImpl.fromArtifactResult(mockedArtResult);
ZipFile outputZipFile = new ZipFile(mavenResolvedArtifact.asFile());
try (ZipFile outputZipFile = new ZipFile(mavenResolvedArtifact.asFile())) {

//Check if existing files are in zip.
Assert.assertNotNull(outputZipFile.getEntry("a/a.file"));
//Check if existing files are in zip.
Assert.assertNotNull(outputZipFile.getEntry("a/a.file"));

//Check if directories are not separately contained
Assert.assertNull(outputZipFile.getEntry("b/c" + File.separator));

//Check if non existing items are null !
Assert.assertNull(outputZipFile.getEntry("a/non-exist" + File.separator));
//Check if directories are not separately contained
Assert.assertNull(outputZipFile.getEntry("b/c" + File.separator));

//Check if non existing items are null !
Assert.assertNull(outputZipFile.getEntry("a/non-exist" + File.separator));
}
}

/**
Expand All @@ -93,13 +93,13 @@ public void packageWar() throws IOException {
mockedArtResult.setArtifact(testPomArtifactMock);

MavenResolvedArtifact mavenResolvedArtifact = MavenResolvedArtifactImpl.fromArtifactResult(mockedArtResult);
ZipFile outputZipFile = new ZipFile(mavenResolvedArtifact.asFile());

//Check if the included files were taken from the "target/Artifact.artifactId-Artifact.version" directory
Assert.assertNotNull(outputZipFile.getEntry("special/a.file"));
try (ZipFile outputZipFile = new ZipFile(mavenResolvedArtifact.asFile())) {

//Check if the default "target/classes" directory was not included
Assert.assertNull(outputZipFile.getEntry("a/a.file"));
//Check if the included files were taken from the "target/Artifact.artifactId-Artifact.version" directory
Assert.assertNotNull(outputZipFile.getEntry("special/a.file"));

//Check if the default "target/classes" directory was not included
Assert.assertNull(outputZipFile.getEntry("a/a.file"));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jboss.shrinkwrap.resolver.impl.maven.integration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;

Expand Down Expand Up @@ -69,18 +71,18 @@ public void asMavenResolvedArtifact() {

assertEquals("jar", resolvedArtifactInfos[0].getExtension());
assertEquals("1.0.0", resolvedArtifactInfos[0].getResolvedVersion());
assertEquals(false, resolvedArtifactInfos[0].isSnapshotVersion());
assertFalse(resolvedArtifactInfos[0].isSnapshotVersion());
assertEquals("jar", resolvedArtifactInfos[0].getExtension());
assertEquals(false, resolvedArtifactInfos[0].isOptional());
assertFalse(resolvedArtifactInfos[0].isOptional());
assertEquals(originalCoordinateA, resolvedArtifactInfos[0].getCoordinate());

new ValidationUtil("test-deps-b-1.0.0.jar").validate(resolvedArtifactInfos[1].as(File.class));

assertEquals("jar", resolvedArtifactInfos[1].getExtension());
assertEquals("1.0.0", resolvedArtifactInfos[1].getResolvedVersion());
assertEquals(false, resolvedArtifactInfos[1].isSnapshotVersion());
assertFalse(resolvedArtifactInfos[1].isSnapshotVersion());
assertEquals("jar", resolvedArtifactInfos[1].getExtension());
assertEquals(false, resolvedArtifactInfos[1].isOptional());
assertFalse(resolvedArtifactInfos[1].isOptional());
assertEquals(originalCoordinateB, resolvedArtifactInfos[1].getCoordinate());
}

Expand All @@ -102,9 +104,9 @@ public void asSingleResolvedArtifactInfo() {

assertEquals("jar", resolvedArtifact.getExtension());
assertEquals("1.0.0", resolvedArtifact.getResolvedVersion());
assertEquals(false, resolvedArtifact.isSnapshotVersion());
assertFalse(resolvedArtifact.isSnapshotVersion());
assertEquals("jar", resolvedArtifact.getExtension());
assertEquals(false, resolvedArtifact.isOptional());
assertFalse(resolvedArtifact.isOptional());
assertEquals(originalCoordinate, resolvedArtifact.getCoordinate());
}

Expand Down Expand Up @@ -159,26 +161,26 @@ public void resolvedArtifactInfoDependecies() {

assertEquals("jar", resolvedArtifact.getExtension());
assertEquals("1.0.0", resolvedArtifact.getResolvedVersion());
assertEquals(false, resolvedArtifact.isSnapshotVersion());
assertFalse(resolvedArtifact.isSnapshotVersion());
assertEquals("jar", resolvedArtifact.getExtension());
assertEquals(false, resolvedArtifact.isOptional());
assertFalse(resolvedArtifact.isOptional());
assertEquals(originalCoordinate, resolvedArtifact.getCoordinate());

final MavenArtifactInfo child1 = resolvedArtifact.getDependencies()[0];
assertEquals("jar", child1.getExtension());
assertEquals("1.0.0", child1.getResolvedVersion());
assertEquals(false, child1.isSnapshotVersion());
assertFalse(child1.isSnapshotVersion());
assertEquals("jar", child1.getExtension());
assertEquals(false, child1.isOptional());
assertFalse(child1.isOptional());
assertEquals(child1Coordinate, child1.getCoordinate());
assertEquals(ScopeType.COMPILE, child1.getScope());

final MavenArtifactInfo child2 = resolvedArtifact.getDependencies()[1];
assertEquals("jar", child2.getExtension());
assertEquals("1.0.0", child2.getResolvedVersion());
assertEquals(false, child2.isSnapshotVersion());
assertFalse(child2.isSnapshotVersion());
assertEquals("jar", child2.getExtension());
assertEquals(false, child2.isOptional());
assertFalse(child2.isOptional());
assertEquals(child2Coordinate, child2.getCoordinate());
assertEquals(ScopeType.RUNTIME, child2.getScope());
}
Expand Down Expand Up @@ -234,17 +236,17 @@ public MavenResolutionFilter[] getResolutionFilters() {

assertEquals("jar", resolvedArtifact.getExtension());
assertEquals("1.0.0", resolvedArtifact.getResolvedVersion());
assertEquals(false, resolvedArtifact.isSnapshotVersion());
assertFalse(resolvedArtifact.isSnapshotVersion());
assertEquals("jar", resolvedArtifact.getExtension());
assertEquals(false, resolvedArtifact.isOptional());
assertFalse(resolvedArtifact.isOptional());
assertEquals(originalCoordinate, resolvedArtifact.getCoordinate());

final MavenArtifactInfo child1 = resolvedArtifact.getDependencies()[0];
assertEquals("jar", child1.getExtension());
assertEquals("1.0.0", child1.getResolvedVersion());
assertEquals(false, child1.isSnapshotVersion());
assertFalse(child1.isSnapshotVersion());
assertEquals("jar", child1.getExtension());
assertEquals(true, child1.isOptional());
assertTrue(child1.isOptional());
assertEquals(child1Coordinate, child1.getCoordinate());
assertEquals(ScopeType.COMPILE, child1.getScope());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testClassifier() throws Exception {
}
jarFile.close();

Assert.assertTrue("Tests-jar artifact was resolved", containsFieldClass == true);
Assert.assertTrue("Tests-jar artifact was resolved", containsFieldClass);
}

/**
Expand Down Expand Up @@ -98,7 +98,7 @@ public void testClassifierAndTestJarType() throws Exception {
}
jarFile.close();

Assert.assertTrue("Tests-jar artifact was resolved", containsFieldClass == true);
Assert.assertTrue("Tests-jar artifact was resolved", containsFieldClass);
}

// SHRINKRES-162
Expand Down Expand Up @@ -148,6 +148,6 @@ public void testClassifierAndTestJarTypeVersionFromPom() throws Exception {
}
jarFile.close();

Assert.assertTrue("Tests-jar artifact was resolved", containsFieldClass == true);
Assert.assertTrue("Tests-jar artifact was resolved", containsFieldClass);
}
}
Loading

0 comments on commit 7c8217d

Please sign in to comment.